/
builder.rake
441 lines (413 loc) · 15.4 KB
/
builder.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
require File.expand_path('../builder', __FILE__)
require 'rake'
# We monkey-patch the method that Rake uses to display the tasks so we can add
# the build options.
module Rake
class Application
def formatted_macruby_options
$builder_options.sort_by { |name, _| name }.map do |name, default|
default = default.join(',') if default.is_a?(Array)
" #{name.ljust(30)} \"#{default}\""
end.join("\n")
end
alias_method :display_tasks_and_comments_without_macruby_options, :display_tasks_and_comments
def display_tasks_and_comments
display_tasks_and_comments_without_macruby_options
puts %{
To change any of the default build options, use the rake build task
of choice with any of these following option-value pairs:
Usage: $ rake [task] [option=value, ...]
#{'Option:'.ljust(30)} Default value:
#{formatted_macruby_options}
Example:
$ rake all archs="i386,ppc" framework_instdir="~/Library/Frameworks"
}
end
end
end
desc "Build known objects"
task :objects => [:config_h, :dtrace_h, :revision_h] do
sh "/usr/bin/ruby tool/compile_prelude.rb prelude.rb miniprelude.c.new"
if !File.exist?('miniprelude.c') or File.read('miniprelude.c') != File.read('miniprelude.c.new')
mv('miniprelude.c.new', 'miniprelude.c')
else
rm('miniprelude.c.new')
end
if !File.exist?('prelude.c')
touch('prelude.c') # create empty file nevertheless
end
if !File.exist?('parse.c') or File.mtime('parse.y') > File.mtime('parse.c')
sh("/usr/bin/bison -o y.tab.c parse.y")
sh("/usr/bin/sed -f ./tool/ytab.sed -e \"/^#/s!y\.tab\.c!parse.c!\" y.tab.c > parse.c.new")
if !File.exist?('parse.c') or File.read('parse.c.new') != File.read('parse.c')
mv('parse.c.new', 'parse.c')
rm_f('parse.o')
else
rm('parse.c.new')
end
end
if !File.exist?('lex.c') or File.read('lex.c') != File.read('lex.c.blt')
cp('lex.c.blt', 'lex.c')
end
if !File.exist?('node_name.inc') or File.mtime('include/ruby/node.h') > File.mtime('node_name.inc')
sh("/usr/bin/ruby -n tool/node_name.rb include/ruby/node.h > node_name.inc")
end
$builder.build
end
desc "Create miniruby"
task :miniruby => :objects do
$builder.link_executable('miniruby', OBJS - ['prelude'])
end
desc "Create config file"
task :rbconfig => :miniruby do
rbconfig = <<EOS
# This file was created when MacRuby was built. Any changes made to this file
# will be lost the next time MacRuby is built.
module RbConfig
RUBY_VERSION == "#{NEW_RUBY_VERSION}" or
raise "ruby lib version (#{NEW_RUBY_VERSION}) doesn't match executable version (\#{RUBY_VERSION})"
TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/#{NEW_RUBY_VERSION}/#{NEW_RUBY_PLATFORM}")
DESTDIR = '' unless defined? DESTDIR
CONFIG = {}
CONFIG["DESTDIR"] = DESTDIR
CONFIG["INSTALL"] = '/usr/bin/install -c'
CONFIG["prefix"] = (TOPDIR || DESTDIR + "#{FRAMEWORK_USR}")
CONFIG["EXEEXT"] = ""
CONFIG["ruby_install_name"] = "#{RUBY_INSTALL_NAME}"
CONFIG["RUBY_INSTALL_NAME"] = "#{RUBY_INSTALL_NAME}"
CONFIG["RUBY_SO_NAME"] = "#{RUBY_SO_NAME}"
CONFIG["SHELL"] = "/bin/sh"
CONFIG["PATH_SEPARATOR"] = ":"
CONFIG["PACKAGE_NAME"] = ""
CONFIG["PACKAGE_TARNAME"] = ""
CONFIG["PACKAGE_VERSION"] = ""
CONFIG["PACKAGE_STRING"] = ""
CONFIG["PACKAGE_BUGREPORT"] = ""
CONFIG["exec_prefix"] = "$(prefix)"
CONFIG["bindir"] = "$(exec_prefix)/bin"
CONFIG["sbindir"] = "$(exec_prefix)/sbin"
CONFIG["libexecdir"] = "$(exec_prefix)/libexec"
CONFIG["datarootdir"] = "$(prefix)/share"
CONFIG["datadir"] = "$(datarootdir)"
CONFIG["sysconfdir"] = "$(prefix)/etc"
CONFIG["sharedstatedir"] = "$(prefix)/com"
CONFIG["localstatedir"] = "$(prefix)/var"
CONFIG["includedir"] = "$(prefix)/include"
CONFIG["oldincludedir"] = "/usr/include"
CONFIG["docdir"] = "$(datarootdir)/doc/$(PACKAGE)"
CONFIG["infodir"] = "$(datarootdir)/info"
CONFIG["htmldir"] = "$(docdir)"
CONFIG["dvidir"] = "$(docdir)"
CONFIG["pdfdir"] = "$(docdir)"
CONFIG["psdir"] = "$(docdir)"
CONFIG["libdir"] = "$(exec_prefix)/lib"
CONFIG["localedir"] = "$(datarootdir)/locale"
CONFIG["mandir"] = "$(datarootdir)/man"
CONFIG["DEFS"] = ""
CONFIG["ECHO_C"] = "\\\\\\\\c"
CONFIG["ECHO_N"] = ""
CONFIG["ECHO_T"] = ""
CONFIG["LIBS"] = ""
CONFIG["build_alias"] = ""
CONFIG["host_alias"] = ""
CONFIG["target_alias"] = ""
CONFIG["BASERUBY"] = "ruby"
CONFIG["MAJOR"], CONFIG["MINOR"], CONFIG["TEENY"] = [#{NEW_RUBY_VERSION.scan(/\d+/).map { |x| "\"" + x + "\"" }.join(', ')}]
CONFIG["build"] = "i686-apple-darwin9.0.0"
CONFIG["build_cpu"] = "i686"
CONFIG["build_vendor"] = "apple"
CONFIG["build_os"] = "darwin9.0.0"
CONFIG["host"] = "i686-apple-darwin9.0.0"
CONFIG["host_cpu"] = "i686"
CONFIG["host_vendor"] = "apple"
CONFIG["host_os"] = "darwin9.0.0"
CONFIG["target"] = "i686-apple-darwin9.0.0"
CONFIG["target_cpu"] = "i686"
CONFIG["target_vendor"] = "apple"
CONFIG["target_os"] = "darwin9.0"
CONFIG["CC"] = "/usr/bin/gcc"
CONFIG["CFLAGS"] = "-fno-common -pipe $(cflags)"
CONFIG["LDFLAGS"] = ""
CONFIG["CPPFLAGS"] = "$(cppflags)"
CONFIG["OBJEXT"] = "o"
CONFIG["CXX"] = "/usr/bin/g++"
CONFIG["CXXFLAGS"] = ""
CONFIG["CPP"] = "/usr/bin/gcc -E"
CONFIG["GREP"] = "/usr/bin/grep"
CONFIG["EGREP"] = "/usr/bin/grep -E"
CONFIG["GNU_LD"] = "no"
CONFIG["CPPOUTFILE"] = "-o conftest.i"
CONFIG["OUTFLAG"] = "-o "
CONFIG["COUTFLAG"] = "-o "
CONFIG["RANLIB"] = "ranlib"
CONFIG["AR"] = "ar"
CONFIG["AS"] = "as"
CONFIG["ASFLAGS"] = ""
CONFIG["NM"] = ""
CONFIG["WINDRES"] = ""
CONFIG["DLLWRAP"] = ""
CONFIG["OBJDUMP"] = ""
CONFIG["LN_S"] = "ln -s"
CONFIG["SET_MAKE"] = ""
CONFIG["INSTALL_PROGRAM"] = "$(INSTALL)"
CONFIG["INSTALL_SCRIPT"] = "$(INSTALL)"
CONFIG["INSTALL_DATA"] = "$(INSTALL) -m 644"
CONFIG["RM"] = "rm -f"
CONFIG["CP"] = "cp"
CONFIG["MAKEDIRS"] = "mkdir -p"
CONFIG["ALLOCA"] = ""
CONFIG["DLDFLAGS"] = ""
CONFIG["ARCH_FLAG"] = "#{ARCHFLAGS}"
CONFIG["STATIC"] = ""
CONFIG["CCDLFLAGS"] = "-fno-common"
CONFIG["LDSHARED"] = "$(CC) -dynamic -bundle -undefined suppress -flat_namespace #{ARCHFLAGS}"
CONFIG["LDSHAREDXX"] = "$(CXX) -dynamic -bundle -undefined suppress -flat_namespace"
CONFIG["DLEXT"] = "bundle"
CONFIG["DLEXT2"] = ""
CONFIG["LIBEXT"] = "a"
CONFIG["LINK_SO"] = ""
CONFIG["LIBPATHFLAG"] = " -L%s"
CONFIG["RPATHFLAG"] = ""
CONFIG["LIBPATHENV"] = "DYLD_LIBRARY_PATH"
CONFIG["TRY_LINK"] = ""
CONFIG["STRIP"] = "strip -A -n"
CONFIG["EXTSTATIC"] = ""
CONFIG["setup"] = "Setup"
CONFIG["PREP"] = "miniruby$(EXEEXT)"
CONFIG["EXTOUT"] = ".ext"
CONFIG["ARCHFILE"] = ""
CONFIG["RDOCTARGET"] = "install-doc"
CONFIG["cppflags"] = ""
CONFIG["cflags"] = "$(optflags) $(debugflags) $(warnflags)"
CONFIG["optflags"] = "-O3"
CONFIG["debugflags"] = "-g"
CONFIG["warnflags"] = "-Wall -Wno-parentheses"
CONFIG["LIBRUBY_LDSHARED"] = "/usr/bin/gcc -dynamiclib -undefined suppress -flat_namespace"
CONFIG["LIBRUBY_DLDFLAGS"] = "-install_name $(libdir)/lib$(RUBY_SO_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)"
CONFIG["rubyw_install_name"] = ""
CONFIG["RUBYW_INSTALL_NAME"] = ""
CONFIG["LIBRUBY_A"] = "lib$(RUBY_SO_NAME)-static.a"
CONFIG["LIBRUBY_SO"] = "lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib"
CONFIG["LIBRUBY_ALIASES"] = "lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib"
CONFIG["LIBRUBY"] = "$(LIBRUBY_SO)"
CONFIG["LIBRUBYARG"] = "$(LIBRUBYARG_SHARED)"
#CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)-static #{LDFLAGS}"
CONFIG["LIBRUBYARG_SHARED"] = CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)"
CONFIG["SOLIBS"] = ""
CONFIG["DLDLIBS"] = ""
CONFIG["ENABLE_SHARED"] = "yes"
CONFIG["ENABLE_STATIC"] = "#{ENABLE_STATIC_LIBRARY}"
CONFIG["MAINLIBS"] = ""
CONFIG["COMMON_LIBS"] = ""
CONFIG["COMMON_MACROS"] = ""
CONFIG["COMMON_HEADERS"] = ""
CONFIG["EXPORT_PREFIX"] = ""
CONFIG["THREAD_MODEL"] = "pthread"
CONFIG["MAKEFILES"] = "Makefile"
CONFIG["arch"] = "#{NEW_RUBY_PLATFORM}"
CONFIG["sitearch"] = "#{NEW_RUBY_PLATFORM}"
CONFIG["sitedir"] = "$(libdir)/ruby/site_ruby"
CONFIG["vendordir"] = "$(prefix)/lib/ruby/vendor_ruby"
CONFIG["configure_args"] = ""
CONFIG["rubyhdrdir"] = "$(includedir)/ruby-$(MAJOR).$(MINOR).$(TEENY)"
CONFIG["sitehdrdir"] = "$(rubyhdrdir)/site_ruby"
CONFIG["vendorhdrdir"] = "$(rubyhdrdir)/vendor_ruby"
CONFIG["NROFF"] = "/usr/bin/nroff"
CONFIG["MANTYPE"] = "doc"
CONFIG["ruby_version"] = "$(MAJOR).$(MINOR).$(TEENY)"
CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
CONFIG["vendorlibdir"] = "$(vendordir)/$(ruby_version)"
CONFIG["vendorarchdir"] = "$(vendorlibdir)/$(sitearch)"
CONFIG["topdir"] = File.dirname(__FILE__)
MAKEFILE_CONFIG = {}
CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
def RbConfig::expand(val, config = CONFIG)
val.gsub!(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do
var = $&
if !(v = $1 || $2)
'$'
elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]]
pat, sub = $1, $2
config[v] = false
RbConfig::expand(key, config)
config[v] = key
key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat
key
else
var
end
end
val
end
CONFIG.each_value do |val|
RbConfig::expand(val)
end
end
Config = RbConfig # compatibility for ruby-1.8.4 and older.
CROSS_COMPILING = nil
RUBY_FRAMEWORK = true
RUBY_FRAMEWORK_VERSION = RbConfig::CONFIG['ruby_version']
EOS
if !File.exist?('rbconfig.rb') or File.read('rbconfig.rb') != rbconfig
File.open('rbconfig.rb', 'w') { |io| io.print rbconfig }
end
end
namespace :macruby do
desc "Build dynamic libraries for MacRuby"
task :dylib => [:rbconfig, :miniruby] do
=begin
sh("./miniruby -I. -I./lib -rrbconfig tool/compile_prelude.rb prelude.rb gem_prelude.rb prelude.c.new")
if !File.exist?('prelude.c') or File.read('prelude.c') != File.read('prelude.c.new')
mv('prelude.c.new', 'prelude.c')
$builder.build(['prelude'])
else
rm('prelude.c.new')
end
=end
cp('miniprelude.c', 'prelude.c')
dylib = "lib#{RUBY_SO_NAME}.#{NEW_RUBY_VERSION}.dylib"
$builder.link_dylib(dylib, $builder.objs - ['main', 'gc-stub', 'miniprelude'])
major, minor, teeny = NEW_RUBY_VERSION.scan(/\d+/)
["lib#{RUBY_SO_NAME}.#{major}.#{minor}.dylib", "lib#{RUBY_SO_NAME}.dylib"].each do |dylib_alias|
if !File.exist?(dylib_alias) or File.readlink(dylib_alias) != dylib
rm_f(dylib_alias)
ln_s(dylib, dylib_alias)
end
end
end
desc "Build static libraries for MacRuby"
task :static => :dylib do
$builder.link_archive("lib#{RUBY_SO_NAME}-static.a", $builder.objs - ['main', 'gc-stub', 'miniprelude'])
end
desc "Build MacRuby"
task :build => :dylib do
$builder.link_executable(RUBY_INSTALL_NAME, ['main', 'gc-stub'], "-L. -l#{RUBY_SO_NAME} -lobjc")
end
end
DESTDIR = (ENV['DESTDIR'] or "")
EXTOUT = (ENV['EXTOUT'] or ".ext")
INSTALLED_LIST = '.installed.list'
SCRIPT_ARGS = "--make=\"/usr/bin/make\" --dest-dir=\"#{DESTDIR}\" --extout=\"#{EXTOUT}\" --mflags=\"\" --make-flags=\"\""
EXTMK_ARGS = "#{SCRIPT_ARGS} --extension --extstatic"
INSTRUBY_ARGS = "#{SCRIPT_ARGS} --data-mode=0644 --prog-mode=0755 --installed-list #{INSTALLED_LIST} --mantype=\"doc\" --sym-dest-dir=\"#{SYM_INSTDIR}\""
EXTENSIONS = ['ripper', 'digest', 'etc', 'readline', 'libyaml', 'fcntl', 'socket', 'zlib']
def perform_extensions_target(target)
EXTENSIONS.map { |x| File.join('ext', x) }.each do |ext_dir|
Dir.glob(File.join(ext_dir, '**/extconf.rb')) do |p|
dir = File.dirname(p)
Dir.chdir(dir) do
$stderr.puts "cd #{dir}"
srcdir = File.join(*dir.split(File::SEPARATOR).map { |x| '..' })
next if target == :clean and !File.exist?('Makefile')
if !File.exist?('Makefile') or File.mtime('extconf.rb') > File.mtime('Makefile')
sh "#{srcdir}/miniruby -I#{srcdir} -I#{srcdir}/lib -r rbconfig -e \"RbConfig::CONFIG['libdir'] = '#{srcdir}'; require './extconf.rb'\""
end
line = "/usr/bin/make top_srcdir=#{srcdir} ruby=\"#{srcdir}/miniruby -I#{srcdir} -I#{srcdir}/lib\" extout=#{srcdir}/.ext hdrdir=#{srcdir}/include arch_hdrdir=#{srcdir}/include"
case target
when :all
line << " libdir=#{srcdir}"
else
line << " #{target}"
end
sh line
rm_f 'Makefile' if target == :clean
end
end
end
end
desc "Build extensions"
task :extensions => [:miniruby, "macruby:static"] do
=begin
sh "./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ext/extmk.rb #{EXTMK_ARGS}"
=end
perform_extensions_target(:all)
end
AOT_STDLIB = ['rbconfig.rb', 'lib/irb.rb', 'lib/irb/**/*.rb', 'lib/fileutils.rb']
desc "AOT compile parts of the stdlib"
task :aot_compile_stdlib => [:miniruby] do
AOT_STDLIB.each do |pat|
Dir.glob(pat).each do |path|
out = File.join(File.dirname(path), File.basename(path, '.rb') + '.rbo')
if !File.exist?(out) or File.mtime(path) > File.mtime(out) or File.mtime('./miniruby') > File.mtime(out)
sh "./miniruby -I. -I./lib bin/rubyc --internal -C \"#{path}\" -o \"#{out}\""
end
end
end
end
desc "Same as extensions"
task :ext => 'extensions'
namespace :framework do
desc "Create the plist file for the framework"
task :info_plist do
plist = <<EOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>Ruby</string>
<key>CFBundleName</key>
<string>Ruby</string>
<key>CFBundleGetInfoString</key>
<string>MacRuby Runtime and Library</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.apple.macruby</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>#{MACRUBY_VERSION}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>#{MACRUBY_VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>MacRuby-#{MACRUBY_VERSION}</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
EOS
File.open('framework/Info.plist', 'w') { |io| io.print plist }
end
desc "Install the extensions"
task :install_ext do
perform_extensions_target(:install)
end
desc "Install the framework"
task :install => [:info_plist, :install_ext] do
sh "./miniruby instruby.rb #{INSTRUBY_ARGS}"
end
end
namespace :clean do
desc "Clean local build files"
task :local do
$builder.clean
list = ['parse.c', 'lex.c', INSTALLED_LIST, 'Makefile', RUBY_INSTALL_NAME, 'miniruby']
list.concat(Dir['*.inc'])
list.concat(Dir['lib*.{dylib,a}'])
list.each { |x| rm_f(x) }
end
desc "Clean .rbo build files"
task :rbo do
list = []
list.concat(Dir['*.rbo'])
list.concat(Dir['lib/**/*.rbo'])
list.each { |x| rm_f(x) }
end
desc "Clean extension build files"
task :ext do
=begin
if File.exist?('./miniruby')
sh "./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ext/extmk.rb #{EXTMK_ARGS} -- clean"
end
=end
perform_extensions_target(:clean)
end
end