-
Notifications
You must be signed in to change notification settings - Fork 1
/
mrbgem.rake
66 lines (53 loc) · 1.77 KB
/
mrbgem.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
MRuby::Gem::Specification.new('mruby-compiler2') do |spec|
spec.license = 'MIT'
spec.author = 'HASUMI Hitoshi'
spec.summary = 'mruby compiler using a universal parser'
lib_dir = "#{dir}/lib"
cc.include_paths << "#{dir}/include"
prism_dir = "#{lib_dir}/prism"
ruby_dir = "#{lib_dir}/ruby"
cc.defines.flatten!
if cc.defines.any? { _1.match? /\A(PICORUBY|MRB)_NO_FLOAT(=|\z)/ }
cc.defines << "MRC_NO_FLOAT"
end
if cc.defines.any? { _1.match? /\A(PICORUBY|MRB)_INT64(=|\z)/ }
cc.defines << "MRC_INT64"
end
if cc.defines.any? { _1.match? /\A(PICORUBY|MRB)_DEBUG(=|\z)/ }
cc.defines << "MRC_DEBUG"
cc.defines << "MRC_DUMP_PRETTY"
else
cc.defines << "PRISM_BUILD_MINIMAL"
end
if cc.defines.include? "MRC_CUSTOM_ALLOC"
cc.defines << "PRISM_XALLOCATOR"
end
prism_templates_dir = "#{lib_dir}/prism/templates"
cc.include_paths << "#{prism_dir}/include"
next if %w(clean deep_clean).include?(Rake.application.top_level_tasks.first)
directory prism_dir do
FileUtils.cd dir do
sh "git submodule update --init"
end
end
task :prism_templates => prism_dir do
FileUtils.cd prism_dir do
sh "templates/template.rb"
end
end
%w(node prettyprint serialize token_type).each do |name|
dst = "#{prism_dir}/src/#{name}.c"
# file task does not work when dst does not exist. why?
Rake::Task[:prism_templates].invoke unless File.exist?(dst)
file dst => ["#{prism_templates_dir}/src/#{name}.c.erb", "#{prism_templates_dir}/template.rb"] do |t|
Rake::Task[:prism_templates].invoke
end
end
Dir.glob("#{prism_dir}/src/**/*.c").map do |src|
obj = objfile(src.pathmap("#{build_dir}/lib/%n"))
objs << obj
file obj => [src] do |f|
cc.run f.name, f.prerequisites.first
end
end
end