[macruby-changes] [4268] MacRuby/trunk/rakelib
source_changes at macosforge.org
source_changes at macosforge.org
Tue Jun 22 23:04:04 PDT 2010
Revision: 4268
http://trac.macosforge.org/projects/ruby/changeset/4268
Author: lsansonetti at apple.com
Date: 2010-06-22 23:04:01 -0700 (Tue, 22 Jun 2010)
Log Message:
-----------
rewrote the builder script to be more flexible/configurable
Modified Paths:
--------------
MacRuby/trunk/rakelib/builder/builder.rb
MacRuby/trunk/rakelib/builder/options.rb
MacRuby/trunk/rakelib/builder/templates.rb
MacRuby/trunk/rakelib/builder.rake
Modified: MacRuby/trunk/rakelib/builder/builder.rb
===================================================================
--- MacRuby/trunk/rakelib/builder/builder.rb 2010-06-23 06:00:22 UTC (rev 4267)
+++ MacRuby/trunk/rakelib/builder/builder.rb 2010-06-23 06:04:01 UTC (rev 4268)
@@ -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 @@
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)
+ FileUtils.mkdir_p(@config.objsdir)
end
end
- def objsdir=(d)
- if @objsdir != d
- @objsdir = d.dup
- FileUtils.mkdir_p(@objsdir)
- @obj_sources.clear
- 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 @@
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 @@
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 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 @@
end
end
-$builder = Builder.new(OBJS)
+$builder = Builder.new(FULL_CONFIG)
Modified: MacRuby/trunk/rakelib/builder/options.rb
===================================================================
--- MacRuby/trunk/rakelib/builder/options.rb 2010-06-23 06:00:22 UTC (rev 4267)
+++ MacRuby/trunk/rakelib/builder/options.rb 2010-06-23 06:04:01 UTC (rev 4268)
@@ -33,7 +33,6 @@
$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 @@
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 @@
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}"
+# 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
+}
-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
+# 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'
Modified: MacRuby/trunk/rakelib/builder/templates.rb
===================================================================
--- MacRuby/trunk/rakelib/builder/templates.rb 2010-06-23 06:00:22 UTC (rev 4267)
+++ MacRuby/trunk/rakelib/builder/templates.rb 2010-06-23 06:04:01 UTC (rev 4268)
@@ -36,6 +36,7 @@
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 @@
elsif e = ENV['RC_ARCHS']
e.split.map { |a| "-arch \#{a}" }.join(' ')
else
- "#{ARCHFLAGS}"
+ "#{archflags}"
end
CONFIG = {}
CONFIG["DESTDIR"] = DESTDIR
Modified: MacRuby/trunk/rakelib/builder.rake
===================================================================
--- MacRuby/trunk/rakelib/builder.rake 2010-06-23 06:00:22 UTC (rev 4267)
+++ MacRuby/trunk/rakelib/builder.rake 2010-06-23 06:04:01 UTC (rev 4268)
@@ -71,7 +71,7 @@
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 @@
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 @@
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 @@
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 @@
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}'])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100622/de613496/attachment-0001.html>
More information about the macruby-changes
mailing list