Permalink
Browse files

rewrote the builder script to be more flexible/configurable

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4268 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 5943bc5 commit 922141d89abfc8cec1e82d25f1bc8d17c6630134 @lrz lrz committed Jun 23, 2010
Showing with 86 additions and 112 deletions.
  1. +5 −7 rakelib/builder.rake
  2. +25 −67 rakelib/builder/builder.rb
  3. +54 −37 rakelib/builder/options.rb
  4. +2 −1 rakelib/builder/templates.rb
View
12 rakelib/builder.rake
@@ -71,7 +71,7 @@ end
desc "Create miniruby"
task :miniruby => :files do
- $builder.mode = :full
+ $builder.config = FULL_CONFIG
build_objects
$builder.link_executable('miniruby', OBJS)
end
@@ -85,7 +85,7 @@ end
namespace :macruby do
desc "Build dynamic library"
task :dylib => [:rbconfig, :files] do
- $builder.mode = :full
+ $builder.config = FULL_CONFIG
build_objects
dylib = "lib#{RUBY_SO_NAME}.#{NEW_RUBY_VERSION}.dylib"
$builder.link_dylib(dylib, $builder.objs - ['main', 'gc-stub'])
@@ -100,14 +100,14 @@ namespace :macruby do
desc "Build static library"
task :static => :files do
- $builder.mode = :static
+ $builder.config = STATIC_CONFIG
build_objects
$builder.link_archive("lib#{RUBY_SO_NAME}-static.a", $builder.objs - ['main', 'gc-stub'])
end
desc "Build MacRuby"
task :build => [:dylib, :static] do
- $builder.mode = :full
+ $builder.config = FULL_CONFIG
$builder.link_executable(RUBY_INSTALL_NAME, ['main', 'gc-stub'], "-L. -l#{RUBY_SO_NAME} -lobjc")
end
end
@@ -192,7 +192,6 @@ namespace :framework do
next unless EXTENSIONS.include?(ext_name)
sub_dir = File.dirname(sub_path)
sh "/usr/bin/install -c -m 0755 #{path} #{File.join(dest_site, sub_dir)}"
- sh "/usr/bin/strip -x #{File.join(dest_site, sub_path)}"
end
end
@@ -205,8 +204,7 @@ end
namespace :clean do
desc "Clean local build files"
task :local do
- rm_rf(FULL_OBJS_DIR)
- rm_rf(STATIC_OBJS_DIR)
+ CONFIGS.each { |x| rm_rf(x.objsdir) }
list = ['parse.c', 'lex.c', INSTALLED_LIST, 'Makefile', RUBY_INSTALL_NAME, 'miniruby', 'kernel_data.c']
list.concat(Dir['*.inc'])
list.concat(Dir['lib*.{dylib,a}'])
View
92 rakelib/builder/builder.rb
@@ -1,23 +1,10 @@
require File.expand_path('../options', __FILE__)
-OBJS = %w{
- array bignum class compar complex enum enumerator error eval file load proc
- gc hash env inits io math numeric object pack parse prec dir process
- random range rational re ruby signal sprintf st string struct time
- util variable version thread id objc bs ucnv encoding main dln dmyext marshal
- gcd vm_eval gc-stub bridgesupport compiler dispatcher vm symbol debugger
- interpreter MacRuby MacRubyDebuggerConnector NSArray NSDictionary NSString
- transcode
-}
-
EXTENSIONS = %w{
ripper digest etc readline libyaml fcntl socket zlib bigdecimal openssl json
nkf
}.sort
-FULL_OBJS_DIR = '.objs'
-STATIC_OBJS_DIR = '.static-objs'
-
class Builder
# Runs the given array of +commands+ in parallel. The amount of spawned
# simultaneous jobs is determined by the `jobs' env variable. The default
@@ -37,67 +24,38 @@ def self.parallel_execute(commands)
end.each { |t| t.join }
end
- attr_reader :objs, :archs, :objsdir, :cflags, :cxxflags
- attr_accessor :cflags, :cxxflags, :objc_cflags, :ldflags, :dldflags
+ [:objs, :archs, :cflags, :cxxflags, :objc_cflags, :ldflags, :objsdir,
+ :objs_cflags, :dldflags].each do |sym|
+ define_method(sym) { @config.send(sym) }
+ end
- def initialize(objs)
- @all_objs = objs.dup
- self.mode = :full
+ def initialize(config)
+ self.config = config
end
- def mode=(m)
- if @mode != m
- @mode = m
- case @mode
- when :full
- @objs = @all_objs
- @archs = ARCHS
- @cflags = CFLAGS
- @cxxflags = CXXFLAGS
- @objc_cflags = OBJC_CFLAGS
- @ldflags = LDFLAGS
- @objsdir = FULL_OBJS_DIR
- when :static
- @objs = @all_objs - %w{bs compiler debugger interpreter MacRubyDebuggerConnector parse}
- @archs = ARCHS_STATIC
- @cflags = CFLAGS_STATIC
- @cxxflags = CXXFLAGS_STATIC
- @objc_cflags = OBJC_CFLAGS_STATIC
- @ldflags = LDFLAGS_STATIC
- @objsdir = STATIC_OBJS_DIR
- else
- raise
- end
- @objs_cflags = OBJS_CFLAGS
- @dldflags = DLDFLAGS
+ def config=(c)
+ if @config != c
+ @config = c
@obj_sources = {}
@header_paths = {}
- FileUtils.mkdir_p(@objsdir)
- end
- end
-
- def objsdir=(d)
- if @objsdir != d
- @objsdir = d.dup
- FileUtils.mkdir_p(@objsdir)
- @obj_sources.clear
+ FileUtils.mkdir_p(@config.objsdir)
end
end
def build(objs=nil)
- objs ||= @objs
+ objs ||= @config.objs
commands = []
objs.each do |obj|
if should_build?(obj)
s = obj_source(obj)
cc, flags =
case File.extname(s)
- when '.c' then [CC, @cflags]
- when '.cpp' then [CXX, @cxxflags]
- when '.m' then [CC, @objc_cflags]
- when '.mm' then [CXX, @cxxflags + ' ' + @objc_cflags]
+ when '.c' then [CC, @config.cflags]
+ when '.cpp' then [CXX, @config.cxxflags]
+ when '.m' then [CC, @config.objc_cflags]
+ when '.mm' then [CXX, @config.cxxflags + ' ' + @config.objc_cflags]
end
- if f = @objs_cflags[obj]
+ if f = @config.objs_cflags[obj]
flags += " #{f}"
end
commands << "#{cc} #{flags} -c #{s} -o #{obj_path(obj)}"
@@ -111,11 +69,11 @@ def link_executable(name, objs=nil, ldflags=nil)
end
def link_dylib(name, objs=nil, ldflags=nil)
- link(objs, ldflags, "#{@dldflags} -o #{name}", name)
+ link(objs, ldflags, "#{@config.dldflags} -o #{name}", name)
end
def link_archive(name, objs=nil)
- objs ||= @objs
+ objs ||= @config.objs
if should_link?(name, objs)
rm_f(name)
sh("/usr/bin/ar rcu #{name} #{objs.map { |x| obj_path(x) }.join(' ') }")
@@ -126,15 +84,15 @@ def link_archive(name, objs=nil)
private
def obj_path(o)
- raise unless @objsdir
- File.join(@objsdir, o + '.o')
+ raise unless @config.objsdir
+ File.join(@config.objsdir, o + '.o')
end
def link(objs, ldflags, args, name)
- objs ||= @objs
- ldflags ||= @ldflags
+ objs ||= @config.objs
+ ldflags ||= @config.ldflags
if should_link?(name, objs)
- sh("#{CXX} #{@cflags} #{objs.map { |x| obj_path(x) }.join(' ') } #{ldflags} #{args}")
+ sh("#{CXX} #{@config.cflags} #{objs.map { |x| obj_path(x) }.join(' ') } #{ldflags} #{args}")
end
end
@@ -197,7 +155,7 @@ def locate_headers(cont, src)
def dependencies
unless @obj_dependencies
@obj_dependencies = {}
- @objs.each do |obj|
+ @config.objs.each do |obj|
ary = []
locate_headers(ary, obj_source(obj))
@obj_dependencies[obj] = ary.uniq
@@ -281,4 +239,4 @@ def make_command(target)
end
end
-$builder = Builder.new(OBJS)
+$builder = Builder.new(FULL_CONFIG)
View
91 rakelib/builder/options.rb
@@ -33,7 +33,6 @@ def self.option(name, default)
$stderr.puts "Welcome bleeding-edge adventurer!"
llvm_default_path = '/Developer/usr/local'
ENV['LLVM_TOT'] = '1'
- #ENV['LLVM_PRE_TOT'] = '1'
end
RUBY_INSTALL_NAME = b.option('ruby_install_name', 'macruby')
@@ -42,12 +41,12 @@ def self.option(name, default)
FRAMEWORK_NAME = b.option('framework_name', 'MacRuby')
FRAMEWORK_INSTDIR = b.option('framework_instdir', '/Library/Frameworks')
SYM_INSTDIR = b.option('sym_instdir', '/usr/local')
-NO_WARN_BUILD = !b.option('allow_build_warnings', false)
ENABLE_STATIC_LIBRARY = b.option('enable_static_library', 'no') { 'yes' }
ENABLE_DEBUG_LOGGING = b.option('enable_debug_logging', true) { |x| x == 'true' }
SIMULTANEOUS_JOBS = b.option('jobs', 1) { |x| x.to_i }
COMPILE_STDLIB = b.option('compile_stdlib', true) { |x| x == 'true' }
OPTZ_LEVEL = b.option('optz_level', 3) { |x| x.to_i }
+IPHONEOS_SDK = b.option('iphoneos_sdk', nil)
default_CC = '/usr/bin/gcc-4.2'
unless File.exist?(default_CC)
@@ -116,49 +115,67 @@ def self.option(name, default)
RUBY_VENDOR_ARCHLIB = File.join(RUBY_VENDOR_LIB2, NEW_RUBY_PLATFORM)
INSTALL_NAME = File.join(FRAMEWORK_USR_LIB, 'lib' + RUBY_SO_NAME + '.dylib')
-ARCHFLAGS = ARCHS.map { |a| '-arch ' + a }.join(' ')
LLVM_MODULES = "core jit nativecodegen bitwriter bitreader ipo"
EXPORTED_SYMBOLS_LIST = "./exported_symbols_list"
-ARCHS_STATIC = ARCHS
-
-OPTZFLAG = "-O#{OPTZ_LEVEL}"
-STATIC_FLAGS = "-DMACRUBY_STATIC"
-CFLAGS = "-std=c99 -I. -I./include #{ARCHFLAGS} -fno-common -pipe -g -Wall -fexceptions #{OPTZFLAG}"
-CFLAGS << " -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
-OBJC_CFLAGS = CFLAGS + " -fobjc-gc-only"
-CFLAGS_STATIC = "#{CFLAGS} #{STATIC_FLAGS}"
-CXXFLAGS_STATIC = "-I. -I./include -g -Wall #{ARCHFLAGS}"
-CXXFLAGS_STATIC << " -Wno-deprecated-declarations -Werror" if NO_WARN_BUILD
-CXXFLAGS = CXXFLAGS_STATIC + ' ' + `#{LLVM_CONFIG} --cxxflags #{LLVM_MODULES}`.sub(/-DNDEBUG/, '').sub(/-fno-exceptions/, '').sub(/-Wcast-qual/, '').strip
-CXXFLAGS.sub!(/-O\d/, OPTZFLAG)
-CXXFLAGS << " -fno-rtti" unless CXXFLAGS.index("-fno-rtti")
-CXXFLAGS << " -DLLVM_TOT" if ENV['LLVM_TOT']
-CXXFLAGS << " -DLLVM_PRE_TOT" if ENV['LLVM_PRE_TOT']
-CXXFLAGS_STATIC << " #{OPTZFLAG} -fno-rtti #{STATIC_FLAGS}"
-LDFLAGS_STATIC = "-lpthread -ldl -lxml2 -lobjc -lauto -licucore -framework Foundation"
-LDFLAGS = LDFLAGS_STATIC + ' ' + `#{LLVM_CONFIG} --ldflags --libs #{LLVM_MODULES}`.strip.gsub(/\n/, '')
-DLDFLAGS = "-dynamiclib -undefined suppress -flat_namespace -install_name #{INSTALL_NAME} -current_version #{MACRUBY_VERSION} -compatibility_version #{MACRUBY_VERSION} -exported_symbols_list #{EXPORTED_SYMBOLS_LIST}"
-OBJC_CFLAGS_STATIC = "#{OBJC_CFLAGS} #{STATIC_FLAGS}"
-
-if `sw_vers -productVersion`.to_f <= 10.6
- CFLAGS << " -I./icu-1060"
- CFLAGS_STATIC << " -I./icu-1060"
- CXXFLAGS << " -I./icu-1060"
- CXXFLAGS_STATIC << " -I./icu-1060"
- OBJC_CFLAGS << " -I./icu-1060"
- OBJC_CFLAGS_STATIC << " -I./icu-1060"
-else
- if !File.exist?('/usr/local/include/unicode')
- $stderr.puts "Cannot locate ICU headers for this version of Mac OS X."
- exit 1
- end
-end
+# Full list of objects to build.
+OBJS = %w{
+ array bignum class compar complex enum enumerator error eval file load proc
+ gc hash env inits io math numeric object pack parse prec dir process
+ random range rational re ruby signal sprintf st string struct time
+ util variable version thread id objc bs ucnv encoding main dln dmyext marshal
+ gcd vm_eval gc-stub bridgesupport compiler dispatcher vm symbol debugger
+ interpreter MacRuby MacRubyDebuggerConnector NSArray NSDictionary NSString
+ transcode
+}
+
+# Static MacRuby builds less objects.
+STATIC_OBJS = OBJS - %w{
+ bs compiler debugger interpreter MacRubyDebuggerConnector parse
+}
+
+# Additional compilation flags for certain objects.
OBJS_CFLAGS = {
'dispatcher' => '-x objective-c++', # compile as Objective-C++.
'bs' => '-I/usr/include/libxml2' # need to access libxml2
}
+class BuilderConfig
+ attr_reader :objs, :archs, :cflags, :cxxflags, :objc_cflags, :ldflags,
+ :objsdir, :objs_cflags, :dldflags
+
+ def initialize(opt)
+ @objs = (opt.delete(:objs) || OBJS)
+ @archs = (opt.delete(:archs) || ARCHS)
+ archflags = archs.map { |x| "-arch #{x}" }.join(' ')
+ @cflags = "-std=c99 -I. -I./include -fno-common -pipe -g -Wall -fexceptions -O#{OPTZ_LEVEL} -Wno-deprecated-declarations -Werror #{archflags}"
+ @cxxflags = "-I. -I./include -g -Wall -Wno-deprecated-declarations -Werror #{archflags}"
+ @ldflags = '-lpthread -ldl -lxml2 -lobjc -lauto -licucore -framework Foundation'
+ if opt.delete(:static)
+ @cflags << ' -DMACRUBY_STATIC'
+ @cxxflags << ' -DMACRUBY_STATIC'
+ @cxxflags << " -O#{OPTZ_LEVEL} "
+ else
+ @cxxflags << ' ' << `#{LLVM_CONFIG} --cxxflags #{LLVM_MODULES}`.sub(/-DNDEBUG/, '').sub(/-fno-exceptions/, '').sub(/-Wcast-qual/, '').sub!(/-O\d/, "-O#{OPTZ_LEVEL}").strip.gsub(/\n/, '')
+ @cxxflags << ' -DLLVM_TOT' if ENV['LLVM_TOT']
+ @ldflags << ' ' << `#{LLVM_CONFIG} --ldflags --libs #{LLVM_MODULES}`.strip.gsub(/\n/, '')
+ end
+ @cxxflags << " -fno-rtti" unless @cxxflags.index("-fno-rtti")
+ @dldflags = "-dynamiclib -undefined suppress -flat_namespace -install_name #{INSTALL_NAME} -current_version #{MACRUBY_VERSION} -compatibility_version #{MACRUBY_VERSION} -exported_symbols_list #{EXPORTED_SYMBOLS_LIST}"
+ if `sw_vers -productVersion`.to_f <= 10.6
+ @cflags << ' -I./icu-1060'
+ @cxxflags << ' -I./icu-1060'
+ end
+ @objc_cflags = cflags + ' -fobjc-gc-only'
+ @objs_cflags = OBJS_CFLAGS
+ @objsdir = opt.delete(:objsdir)
+ end
+end
+
+FULL_CONFIG = BuilderConfig.new(:objsdir => '.objs')
+STATIC_CONFIG = BuilderConfig.new(:objsdir => '.static-objs', :static => true, :objs => STATIC_OBJS)
+CONFIGS = [FULL_CONFIG, STATIC_CONFIG]
+
# We monkey-patch the method that Rake uses to display the tasks so we can add
# the build options.
require 'rake'
View
3 rakelib/builder/templates.rb
@@ -36,6 +36,7 @@ def self.create_framework_info_plist
end
def self.create_rbconfig
+ archflags = ARCHS.map { |x| "-arch #{x}" }.join(' ')
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.
@@ -52,7 +53,7 @@ module RbConfig
elsif e = ENV['RC_ARCHS']
e.split.map { |a| "-arch \#{a}" }.join(' ')
else
- "#{ARCHFLAGS}"
+ "#{archflags}"
end
CONFIG = {}
CONFIG["DESTDIR"] = DESTDIR

0 comments on commit 922141d

Please sign in to comment.