Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 240 lines (187 sloc) 6.819 kb
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
1 task :vm => 'vm/vm'
2
3 ############################################################
4 # Files, Flags, & Constants
5
6 ENV.delete 'CDPATH' # confuses llvm_config
7 LLVM_CONFIG = "vm/external_libs/llvm/Release/bin/llvm-config"
8 tests = FileList["vm/test/test_*.hpp"]
9 srcs = FileList["vm/*.{cpp,c}"]
10 hdrs = FileList["vm/*.{hpp,h}"]
11 objs = srcs.map { |f| f.sub(/c(pp)?$/, 'o') }
12 dep_file = "vm/.depends.mf"
13 vm_objs = %w[ vm/drivers/cli.o ]
14 vm_srcs = %w[ vm/drivers/cli.cpp ]
15 EX_INC = %w[ libtommath onig libffi/include
16 libltdl libev llvm/include
17 ].map { |f| "vm/external_libs/#{f}" }
18 INSN_GEN = %w[ vm/gen/iseq_instruction_names.cpp
19 vm/gen/iseq_instruction_names.hpp
20 vm/test/test_instructions.hpp ]
21 TYPE_GEN = %w[ vm/gen/simple_field.rb
22 vm/gen/typechecks.gen.cpp
23 vm/gen/primitives_declare.hpp
24 vm/gen/primitives_glue.gen.cpp ]
25
26 LLVM_A = "vm/external_libs/llvm/Release/lib/libLLVMSystem.a"
27 EXTERNALS = %W[ #{LLVM_A}
28 vm/external_libs/libtommath/libtommath.a
29 vm/external_libs/onig/.libs/libonig.a
30 vm/external_libs/libffi/.libs/libffi.a
31 vm/external_libs/libltdl/.libs/libltdl.a
32 vm/external_libs/libev/.libs/libev.a ]
33 OPTIONS = {
34 LLVM_A => "--enable-targets=host-only --enable-optimized"
35 }
36
37 INCLUDES = (EX_INC + %w[vm/test/cxxtest vm .]).map { |f| "-I#{f}" }
38 FLAGS = %w(-Wall -ggdb -gdwarf-2)
39
40 FLAGS << "-O2" if ENV['FAST']
41
3197850 Fix using strlcpy and strlcat, respect CC
Evan Phoenix authored
42 CC = ENV['CC'] || "gcc"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
43
3197850 Fix using strlcpy and strlcat, respect CC
Evan Phoenix authored
44 def compile(obj, src)
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
45 unless defined? $llvm_c then
46 $llvm_c = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
47 $llvm_c.delete_if { |e| e.index("-O") == 0 }
48 end
49
50 flags = (INCLUDES + FLAGS + $llvm_c).join(' ')
51
3197850 Fix using strlcpy and strlcat, respect CC
Evan Phoenix authored
52 sh "#{CC} #{flags} -c -o #{obj} #{src} 2>&1"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
53 end
54
55 ############################################################
56 # Other Tasks
57
58 rule '.o' do |t|
59 obj = t.name
60 src = t.prerequisites.find { |f| f =~ /#{File.basename obj, '.o'}\.c(pp)?$/}
61
62 compile obj, src
63 end
64
65 def files targets, dependencies = nil, &block
66 targets.each do |target|
67 if dependencies then
68 file target => dependencies, &block
69 else
70 file target, &block
71 end
72 end
73 end
74
75 directory "vm/gen"
76 file "vm/type_info.o" => "vm/gen/typechecks.gen.cpp"
77 file "vm/primitives.hpp" => "vm/gen/primitives_declare.hpp"
78 files Dir["vm/builtin_*.hpp"], INSN_GEN
79 files objs, EXTERNALS
80 files vm_objs, vm_srcs
81
82 objs.zip(srcs).each do |obj, src|
83 file obj => src
84 end
85
86 objs += ["vm/instructions.o"]
87
88 files EXTERNALS do |t|
89 path = File.join(*split_all(t.name)[0..2])
90 configure_path = File.join(path, 'configure')
91
92 if File.exist? configure_path then
93 sh "cd #{path}; ./configure #{OPTIONS[t.name]} && make"
94 else
95 sh "cd #{path}; make"
96 end
97 end
98
99 file 'vm/instructions.rb' => 'vm/instructions_gen.rb'
100
101 files INSN_GEN, %w[vm/gen vm/instructions.rb] do
102 ruby 'vm/instructions.rb', :verbose => $verbose
103 end
104
105 files TYPE_GEN, %w[vm/gen vm/instructions.rb vm/field_extract.rb] do
106 field_extract
107 end
108
109 file 'vm/vm' => EXTERNALS + objs + vm_objs do |t|
110 link t
111 end
112
113 file 'vm/gen/primitives_glue.gen.cpp' => hdrs
114
115 file 'vm/test/runner.cpp' => tests do
116 tests += [{ :verbose => true }]
117 sh("vm/test/cxxtest/cxxtestgen.pl", "--error-printer", "--have-eh",
118 "--abort-on-fail", "-o", "vm/test/runner.cpp", *tests)
119 end
120
121 file 'vm/test/runner.o' => 'vm/test/runner.cpp' # no rule .o => .cpp
122
123 file 'vm/test/runner' => EXTERNALS + objs + %w[vm/test/runner.o] do |t|
124 link t
125 end
126
127 file "vm/instructions.o" => %w[vm/llvm/instructions.cpp vm/instructions.rb] do
128 ruby "vm/rubypp.rb vm/llvm/instructions.cpp vm/llvm/.instructions.cpp"
129 compile "vm/instructions.o", "vm/llvm/.instructions.cpp"
130 rm_f "vm/llvm/.instructions.cpp", :verbose => $verbose
131 end
132
133 file "vm/instructions.bc" => "vm/llvm/instructions.cpp" do
134 ruby "vm/rubypp.rb vm/llvm/instructions.cpp vm/llvm/.instructions.cpp"
135 sh "llvm-g++ -emit-llvm -Ivm -Ivm/external_libs/libffi/include -c -o vm/instructions.bc vm/llvm/.instructions.cpp", :verbose => true
136 rm_f "llvm/.instructions.cpp", :verbose => $verbose
137 end
138
139 ############################################################$
140 # Importers & Methods:
141
142 require 'rake/loaders/makefile'
143
144 file dep_file => srcs + hdrs + vm_srcs do |t|
145 flags = (INCLUDES + FLAGS).join(' ')
146 flags << " -D__STDC_LIMIT_MACROS"
147
148 dep = nil
149 Dir.chdir 'vm' do
150 dep = `makedepend -f- -- #{flags} -- #{t.prerequisites} 2>/dev/null`
151 end
152 dep.gsub!(%r% /usr/include\S+%, '') # speeds up rake a lot
153 dep.gsub!(%r%^\S+:[^ ]%, '')
154
155 File.open t.name, 'w' do |f|
156 f.puts dep
157 end
158 end
159
160 import dep_file
161
162 def ex_libs # needs to be method to delay running of llvm_config
163 unless defined? $ex_libs then
164 $ex_libs = EXTERNALS + [ "-ldl" ]
165 $ex_libs << "-lrt" if RUBY_PLATFORM =~ /linux/
166
167 llvm_libfiles = `#{LLVM_CONFIG} --libfiles all`.split(/\s+/)
168 llvm_libfiles = llvm_libfiles.select { |f| File.file? f }
169
170 pwd = File.join Dir.pwd, '' # add /
171 llvm_libfiles = llvm_libfiles.map { |f| f.sub pwd, '' }
172 $ex_libs += llvm_libfiles
173 end
174 $ex_libs
175 end
176
177 def field_extract
178 order = %w[vm/builtin_object.hpp vm/objects.hpp]
a38df9f Use correct list to field_extract
Evan Phoenix authored
179 order += File.read("vm/objects.hpp").scan(/builtin_[^"]+/).map { |f| "vm/#{f}" }
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
180 order << { :verbose => $verbose}
181 ruby('vm/field_extract.rb', *order)
182 end
183
184 def link t
185 $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
186
187 ld = ENV['LD'] || 'g++'
188 o = t.prerequisites.find_all { |f| f =~ /o$/ }.join(' ')
189 l = ex_libs.join(' ')
190
191 sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}"
192 end
193
194 namespace :vm do
195 desc 'Run all VM tests'
196 task :test => 'vm/test/runner' do
197 ENV['VERBOSE'] = '1' if $verbose
198 sh 'vm/test/runner', :verbose => $verbose
199 end
200
201 desc "Clean up vm build files"
202 task :clean do
203 # TODO evan? "*.gcda *.gcno *.gcov *.dSYM ../*.o coverage"
204 files = [
205 objs, dep_file,
206 'vm/test/runner', 'vm/test/runner.cpp',
207 'vm/gen',
208 'vm/vm'
209 ]
210
211 files.each do |filename|
212 rm_f filename, :verbose => $verbose
213 end
214 end
215
216 desc "Clean up, including all external libs"
217 task :distclean => :clean do
218 EXTERNALS.each do |lib|
219 path = File.join(*lib.split(File::SEPARATOR)[0..2])
220 system "cd #{path}; make clean"
221 end
222 end
223
224 desc "Show which primitives are missing"
225 task :missing_primitives do
226 cpp_primitives = `grep 'Ruby.primitive' vm/*.hpp | awk '{ print $4 }'`
227
228 cpp_primitives = cpp_primitives.gsub(':', '').split("\n").sort.uniq
229
230 shotgun_primitives = File.read('vm/shotgun_primitives.txt')
231 shotgun_primitives = shotgun_primitives.split("\n").sort.uniq
232
233 missing = shotgun_primitives - cpp_primitives
234
235 puts missing.join("\n")
236 end
237
238 end
239
Something went wrong with that request. Please try again.