Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 380 lines (356 sloc) 13.783 kb
6d571b4 @alloy Moved guts of the code in Rakefile into seperate files in rakelib.
alloy authored
1 require File.expand_path('../builder', __FILE__)
b8cf6a6 @alloy Added available build options to the output of: $ rake -T
alloy authored
2 require 'rake'
3
4 # We monkey-patch the method that Rake uses to display the tasks so we can add
5 # the build options.
6 module Rake
7 class Application
8 def formatted_macruby_options
9 $builder_options.sort_by { |name, _| name }.map do |name, default|
10 default = default.join(',') if default.is_a?(Array)
ac477e5 @alloy Oops, a bit too much indentation.
alloy authored
11 " #{name.ljust(30)} \"#{default}\""
b8cf6a6 @alloy Added available build options to the output of: $ rake -T
alloy authored
12 end.join("\n")
13 end
14
15 alias_method :display_tasks_and_comments_without_macruby_options, :display_tasks_and_comments
16
17 def display_tasks_and_comments
18 display_tasks_and_comments_without_macruby_options
19 puts %{
20 To change any of the default build options, use the rake build task
21 of choice with any of these following option-value pairs:
22
23 Usage: $ rake [task] [option=value, …]
24
25 #{'Option:'.ljust(30)} Default value:
26
27 #{formatted_macruby_options}
28
29 Example:
30
31 $ rake all archs="i386,ppc" framework_instdir="~/Library/Frameworks"
32
33 }
34 end
35 end
36 end
6d571b4 @alloy Moved guts of the code in Rakefile into seperate files in rakelib.
alloy authored
37
38 desc "Build known objects"
39 task :objects => [:config_h, :dtrace_h, :revision_h] do
40 sh "/usr/bin/ruby tool/compile_prelude.rb prelude.rb miniprelude.c.new"
41 if !File.exist?('miniprelude.c') or File.read('miniprelude.c') != File.read('miniprelude.c.new')
42 mv('miniprelude.c.new', 'miniprelude.c')
43 else
44 rm('miniprelude.c.new')
45 end
46 if !File.exist?('prelude.c')
47 touch('prelude.c') # create empty file nevertheless
48 end
49 if !File.exist?('parse.c') or File.mtime('parse.y') > File.mtime('parse.c')
50 sh("/usr/bin/bison -o y.tab.c parse.y")
51 sh("/usr/bin/sed -f ./tool/ytab.sed -e \"/^#/s!y\.tab\.c!parse.c!\" y.tab.c > parse.c.new")
52 if !File.exist?('parse.c') or File.read('parse.c.new') != File.read('parse.c')
53 mv('parse.c.new', 'parse.c')
54 rm_f('parse.o')
55 else
56 rm('parse.c.new')
57 end
58 end
59 if !File.exist?('lex.c') or File.read('lex.c') != File.read('lex.c.blt')
60 cp('lex.c.blt', 'lex.c')
61 end
62 if !File.exist?('node_name.inc') or File.mtime('include/ruby/node.h') > File.mtime('node_name.inc')
63 sh("/usr/bin/ruby -n tool/node_name.rb include/ruby/node.h > node_name.inc")
64 end
65 $builder.build
66 end
67
68 desc "Create miniruby"
69 task :miniruby => :objects do
70 $builder.link_executable('miniruby', OBJS - ['prelude'])
71 end
72
73 desc "Create config file"
74 task :rbconfig => :miniruby do
75 rbconfig = <<EOS
76 # This file was created when MacRuby was built. Any changes made to this file
77 # will be lost the next time MacRuby is built.
78
79 module RbConfig
80 RUBY_VERSION == "#{NEW_RUBY_VERSION}" or
81 raise "ruby lib version (#{NEW_RUBY_VERSION}) doesn't match executable version (\#{RUBY_VERSION})"
82
83 TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/#{NEW_RUBY_VERSION}/#{NEW_RUBY_PLATFORM}")
84 DESTDIR = '' unless defined? DESTDIR
85 CONFIG = {}
86 CONFIG["DESTDIR"] = DESTDIR
87 CONFIG["INSTALL"] = '/usr/bin/install -c'
88 CONFIG["prefix"] = (TOPDIR || DESTDIR + "#{FRAMEWORK_USR}")
89 CONFIG["EXEEXT"] = ""
90 CONFIG["ruby_install_name"] = "#{RUBY_INSTALL_NAME}"
91 CONFIG["RUBY_INSTALL_NAME"] = "#{RUBY_INSTALL_NAME}"
92 CONFIG["RUBY_SO_NAME"] = "#{RUBY_SO_NAME}"
93 CONFIG["SHELL"] = "/bin/sh"
94 CONFIG["PATH_SEPARATOR"] = ":"
95 CONFIG["PACKAGE_NAME"] = ""
96 CONFIG["PACKAGE_TARNAME"] = ""
97 CONFIG["PACKAGE_VERSION"] = ""
98 CONFIG["PACKAGE_STRING"] = ""
99 CONFIG["PACKAGE_BUGREPORT"] = ""
100 CONFIG["exec_prefix"] = "$(prefix)"
101 CONFIG["bindir"] = "$(exec_prefix)/bin"
102 CONFIG["sbindir"] = "$(exec_prefix)/sbin"
103 CONFIG["libexecdir"] = "$(exec_prefix)/libexec"
104 CONFIG["datarootdir"] = "$(prefix)/share"
105 CONFIG["datadir"] = "$(datarootdir)"
106 CONFIG["sysconfdir"] = "$(prefix)/etc"
107 CONFIG["sharedstatedir"] = "$(prefix)/com"
108 CONFIG["localstatedir"] = "$(prefix)/var"
109 CONFIG["includedir"] = "$(prefix)/include"
110 CONFIG["oldincludedir"] = "/usr/include"
111 CONFIG["docdir"] = "$(datarootdir)/doc/$(PACKAGE)"
112 CONFIG["infodir"] = "$(datarootdir)/info"
113 CONFIG["htmldir"] = "$(docdir)"
114 CONFIG["dvidir"] = "$(docdir)"
115 CONFIG["pdfdir"] = "$(docdir)"
116 CONFIG["psdir"] = "$(docdir)"
117 CONFIG["libdir"] = "$(exec_prefix)/lib"
118 CONFIG["localedir"] = "$(datarootdir)/locale"
119 CONFIG["mandir"] = "$(datarootdir)/man"
120 CONFIG["DEFS"] = ""
121 CONFIG["ECHO_C"] = "\\\\\\\\c"
122 CONFIG["ECHO_N"] = ""
123 CONFIG["ECHO_T"] = ""
124 CONFIG["LIBS"] = ""
125 CONFIG["build_alias"] = ""
126 CONFIG["host_alias"] = ""
127 CONFIG["target_alias"] = ""
128 CONFIG["BASERUBY"] = "ruby"
129 CONFIG["MAJOR"], CONFIG["MINOR"], CONFIG["TEENY"] = [#{NEW_RUBY_VERSION.scan(/\d+/).map { |x| "\"" + x + "\"" }.join(', ')}]
130 CONFIG["build"] = "i686-apple-darwin9.0.0"
131 CONFIG["build_cpu"] = "i686"
132 CONFIG["build_vendor"] = "apple"
133 CONFIG["build_os"] = "darwin9.0.0"
134 CONFIG["host"] = "i686-apple-darwin9.0.0"
135 CONFIG["host_cpu"] = "i686"
136 CONFIG["host_vendor"] = "apple"
137 CONFIG["host_os"] = "darwin9.0.0"
138 CONFIG["target"] = "i686-apple-darwin9.0.0"
139 CONFIG["target_cpu"] = "i686"
140 CONFIG["target_vendor"] = "apple"
141 CONFIG["target_os"] = "darwin9.0"
142 CONFIG["CC"] = "gcc"
143 CONFIG["CFLAGS"] = "-fno-common -pipe $(cflags)"
144 CONFIG["LDFLAGS"] = ""
145 CONFIG["CPPFLAGS"] = "$(cppflags)"
146 CONFIG["OBJEXT"] = "o"
147 CONFIG["CXX"] = "g++"
148 CONFIG["CXXFLAGS"] = ""
149 CONFIG["CPP"] = "gcc -E"
150 CONFIG["GREP"] = "/usr/bin/grep"
151 CONFIG["EGREP"] = "/usr/bin/grep -E"
152 CONFIG["GNU_LD"] = "no"
153 CONFIG["CPPOUTFILE"] = "-o conftest.i"
154 CONFIG["OUTFLAG"] = "-o "
155 CONFIG["COUTFLAG"] = "-o "
156 CONFIG["RANLIB"] = "ranlib"
157 CONFIG["AR"] = "ar"
158 CONFIG["AS"] = "as"
159 CONFIG["ASFLAGS"] = ""
160 CONFIG["NM"] = ""
161 CONFIG["WINDRES"] = ""
162 CONFIG["DLLWRAP"] = ""
163 CONFIG["OBJDUMP"] = ""
164 CONFIG["LN_S"] = "ln -s"
165 CONFIG["SET_MAKE"] = ""
166 CONFIG["INSTALL_PROGRAM"] = "$(INSTALL)"
167 CONFIG["INSTALL_SCRIPT"] = "$(INSTALL)"
168 CONFIG["INSTALL_DATA"] = "$(INSTALL) -m 644"
169 CONFIG["RM"] = "rm -f"
170 CONFIG["CP"] = "cp"
171 CONFIG["MAKEDIRS"] = "mkdir -p"
172 CONFIG["ALLOCA"] = ""
173 CONFIG["DLDFLAGS"] = ""
174 CONFIG["ARCH_FLAG"] = "#{ARCHFLAGS}"
175 CONFIG["STATIC"] = ""
176 CONFIG["CCDLFLAGS"] = "-fno-common"
177 CONFIG["LDSHARED"] = "$(CC) -dynamic -bundle -undefined suppress -flat_namespace #{ARCHFLAGS}"
178 CONFIG["LDSHAREDXX"] = "$(CXX) -dynamic -bundle -undefined suppress -flat_namespace"
179 CONFIG["DLEXT"] = "bundle"
180 CONFIG["DLEXT2"] = ""
181 CONFIG["LIBEXT"] = "a"
182 CONFIG["LINK_SO"] = ""
183 CONFIG["LIBPATHFLAG"] = " -L%s"
184 CONFIG["RPATHFLAG"] = ""
185 CONFIG["LIBPATHENV"] = "DYLD_LIBRARY_PATH"
186 CONFIG["TRY_LINK"] = ""
187 CONFIG["STRIP"] = "strip -A -n"
188 CONFIG["EXTSTATIC"] = ""
189 CONFIG["setup"] = "Setup"
190 CONFIG["PREP"] = "miniruby$(EXEEXT)"
191 CONFIG["EXTOUT"] = ".ext"
192 CONFIG["ARCHFILE"] = ""
193 CONFIG["RDOCTARGET"] = "install-doc"
194 CONFIG["cppflags"] = ""
195 CONFIG["cflags"] = "$(optflags) $(debugflags) $(warnflags)"
196 CONFIG["optflags"] = "-O2"
197 CONFIG["debugflags"] = "-g"
198 CONFIG["warnflags"] = "-Wall -Wno-parentheses"
199 CONFIG["LIBRUBY_LDSHARED"] = "gcc -dynamiclib -undefined suppress -flat_namespace"
200 CONFIG["LIBRUBY_DLDFLAGS"] = "-install_name $(libdir)/lib$(RUBY_SO_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)"
201 CONFIG["rubyw_install_name"] = ""
202 CONFIG["RUBYW_INSTALL_NAME"] = ""
203 CONFIG["LIBRUBY_A"] = "lib$(RUBY_SO_NAME)-static.a"
204 CONFIG["LIBRUBY_SO"] = "lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib"
205 CONFIG["LIBRUBY_ALIASES"] = "lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib"
206 CONFIG["LIBRUBY"] = "$(LIBRUBY_SO)"
207 CONFIG["LIBRUBYARG"] = "$(LIBRUBYARG_SHARED)"
208 CONFIG["LIBRUBYARG_STATIC"] = "-l$(RUBY_SO_NAME)-static #{LDFLAGS}"
209 CONFIG["LIBRUBYARG_SHARED"] = "-l$(RUBY_SO_NAME)"
210 CONFIG["SOLIBS"] = ""
211 CONFIG["DLDLIBS"] = ""
212 CONFIG["ENABLE_SHARED"] = "yes"
213 CONFIG["ENABLE_STATIC"] = "#{ENABLE_STATIC_LIBRARY}"
214 CONFIG["MAINLIBS"] = ""
215 CONFIG["COMMON_LIBS"] = ""
216 CONFIG["COMMON_MACROS"] = ""
217 CONFIG["COMMON_HEADERS"] = ""
218 CONFIG["EXPORT_PREFIX"] = ""
219 CONFIG["THREAD_MODEL"] = "pthread"
220 CONFIG["MAKEFILES"] = "Makefile"
221 CONFIG["arch"] = "#{NEW_RUBY_PLATFORM}"
222 CONFIG["sitearch"] = "#{NEW_RUBY_PLATFORM}"
223 CONFIG["sitedir"] = "$(libdir)/ruby/site_ruby"
224 CONFIG["vendordir"] = "$(prefix)/lib/ruby/vendor_ruby"
225 CONFIG["configure_args"] = ""
226 CONFIG["rubyhdrdir"] = "$(includedir)/ruby-$(MAJOR).$(MINOR).$(TEENY)"
227 CONFIG["sitehdrdir"] = "$(rubyhdrdir)/site_ruby"
228 CONFIG["vendorhdrdir"] = "$(rubyhdrdir)/vendor_ruby"
229 CONFIG["NROFF"] = "/usr/bin/nroff"
230 CONFIG["MANTYPE"] = "doc"
231 CONFIG["ruby_version"] = "$(MAJOR).$(MINOR).$(TEENY)"
232 CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
233 CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
234 CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
235 CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
236 CONFIG["vendorlibdir"] = "$(vendordir)/$(ruby_version)"
237 CONFIG["vendorarchdir"] = "$(vendorlibdir)/$(sitearch)"
238 CONFIG["topdir"] = File.dirname(__FILE__)
239 MAKEFILE_CONFIG = {}
240 CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
241 def RbConfig::expand(val, config = CONFIG)
242 val.gsub!(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do
243 var = $&
244 if !(v = $1 || $2)
245 '$'
246 elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]]
247 pat, sub = $1, $2
248 config[v] = false
249 RbConfig::expand(key, config)
250 config[v] = key
251 key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat
252 key
253 else
254 var
255 end
256 end
257 val
258 end
259 CONFIG.each_value do |val|
260 RbConfig::expand(val)
261 end
262 end
263 Config = RbConfig # compatibility for ruby-1.8.4 and older.
264 CROSS_COMPILING = nil
265 RUBY_FRAMEWORK = true
266 RUBY_FRAMEWORK_VERSION = RbConfig::CONFIG['ruby_version']
267 EOS
268 if !File.exist?('rbconfig.rb') or File.read('rbconfig.rb') != rbconfig
269 File.open('rbconfig.rb', 'w') { |io| io.print rbconfig }
270 end
271 end
272
273 namespace :macruby do
274 desc "Build dynamic libraries for MacRuby"
275 task :dylib => [:rbconfig, :miniruby] do
b0f57d9 blocked the rake all/install tasks for now
Laurent Sansonetti authored
276 $stderr.puts "Warning: this version of MacRuby is still under development and can only build the \"miniruby\" target."
277 system("ls -l ./miniruby")
278 exit 0
6d571b4 @alloy Moved guts of the code in Rakefile into seperate files in rakelib.
alloy authored
279 sh("./miniruby -I. -I./lib -rrbconfig tool/compile_prelude.rb prelude.rb gem_prelude.rb prelude.c.new")
280 if !File.exist?('prelude.c') or File.read('prelude.c') != File.read('prelude.c.new')
281 mv('prelude.c.new', 'prelude.c')
282 $builder.build(['prelude'])
283 else
284 rm('prelude.c.new')
285 end
286 dylib = "lib#{RUBY_SO_NAME}.#{NEW_RUBY_VERSION}.dylib"
287 $builder.link_dylib(dylib, $builder.objs - ['main', 'gc-stub', 'miniprelude'])
288 major, minor, teeny = NEW_RUBY_VERSION.scan(/\d+/)
289 ["lib#{RUBY_SO_NAME}.#{major}.#{minor}.dylib", "lib#{RUBY_SO_NAME}.dylib"].each do |dylib_alias|
290 if !File.exist?(dylib_alias) or File.readlink(dylib_alias) != dylib
291 rm_f(dylib_alias)
292 ln_s(dylib, dylib_alias)
293 end
294 end
295 end
296
297 desc "Build static libraries for MacRuby"
298 task :static => :dylib do
299 $builder.link_archive("lib#{RUBY_SO_NAME}-static.a", $builder.objs - ['main', 'gc-stub', 'miniprelude'])
300 end
301
302 desc "Build MacRuby"
303 task :build => :dylib do
304 $builder.link_executable(RUBY_INSTALL_NAME, ['main', 'gc-stub'], "-L. -l#{RUBY_SO_NAME} -lobjc")
305 end
306 end
307
308 DESTDIR = (ENV['DESTDIR'] or "")
309 EXTOUT = (ENV['EXTOUT'] or ".ext")
310 INSTALLED_LIST = '.installed.list'
311 SCRIPT_ARGS = "--make=\"/usr/bin/make\" --dest-dir=\"#{DESTDIR}\" --extout=\"#{EXTOUT}\" --mflags=\"\" --make-flags=\"\""
312 EXTMK_ARGS = "#{SCRIPT_ARGS} --extension --extstatic"
313 INSTRUBY_ARGS = "#{SCRIPT_ARGS} --data-mode=0644 --prog-mode=0755 --installed-list #{INSTALLED_LIST} --mantype=\"doc\" --sym-dest-dir=\"#{SYM_INSTDIR}\""
314
315 desc "Build extensions"
316 task :extensions => [:miniruby, "macruby:static"] do
317 sh "./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ext/extmk.rb #{EXTMK_ARGS}"
318 end
319
320 namespace :framework do
321 desc "Create the plist file for the framework"
322 task :info_plist do
323 plist = <<EOS
324 <?xml version="1.0" encoding="UTF-8"?>
325 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
326 <plist version="1.0">
327 <dict>
328 <key>CFBundleDevelopmentRegion</key>
329 <string>English</string>
330 <key>CFBundleExecutable</key>
331 <string>Ruby</string>
332 <key>CFBundleName</key>
333 <string>Ruby</string>
334 <key>CFBundleGetInfoString</key>
335 <string>MacRuby Runtime and Library</string>
336 <key>CFBundleIconFile</key>
337 <string></string>
338 <key>CFBundleIdentifier</key>
339 <string>com.apple.macruby</string>
340 <key>CFBundleInfoDictionaryVersion</key>
341 <string>#{MACRUBY_VERSION}</string>
342 <key>CFBundlePackageType</key>
343 <string>FMWK</string>
344 <key>CFBundleShortVersionString</key>
345 <string>#{MACRUBY_VERSION}</string>
346 <key>CFBundleSignature</key>
347 <string>????</string>
348 <key>CFBundleVersion</key>
349 <string>MacRuby-#{MACRUBY_VERSION}</string>
350 <key>NSPrincipalClass</key>
351 <string></string>
352 </dict>
353 </plist>
354 EOS
355 File.open('framework/Info.plist', 'w') { |io| io.print plist }
356 end
357
358 desc "Install the framework"
359 task :install => :info_plist do
b0f57d9 blocked the rake all/install tasks for now
Laurent Sansonetti authored
360 $stderr.puts "This version of MacRuby is under development and cannot be installed yet. Please retry later."
361 exit 1
6d571b4 @alloy Moved guts of the code in Rakefile into seperate files in rakelib.
alloy authored
362 sh "./miniruby instruby.rb #{INSTRUBY_ARGS}"
363 end
364 end
365
366 namespace :clean do
367 desc "Clean local build files"
368 task :local do
369 $builder.clean
370 ['parse.c', 'lex.c', INSTALLED_LIST, 'Makefile', *Dir['*.inc']].each { |x| rm_f(x) }
371 end
372
373 desc "Clean extension build files"
374 task :ext do
375 if File.exist?('./miniruby')
376 sh "./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb ext/extmk.rb #{EXTMK_ARGS} -- clean"
377 end
378 end
b0f57d9 blocked the rake all/install tasks for now
Laurent Sansonetti authored
379 end
Something went wrong with that request. Please try again.