2004-02-09 11:48:55 +03:00
|
|
|
#!./miniruby
|
|
|
|
|
2007-03-06 04:21:48 +03:00
|
|
|
pure = true
|
2009-02-07 05:57:15 +03:00
|
|
|
show = false
|
|
|
|
precommand = []
|
2004-02-09 11:48:55 +03:00
|
|
|
while arg = ARGV[0]
|
|
|
|
break ARGV.shift if arg == '--'
|
|
|
|
/\A--([-\w]+)(?:=(.*))?\z/ =~ arg or break
|
|
|
|
arg, value = $1, $2
|
|
|
|
re = Regexp.new('\A'+arg.gsub(/\w+\b/, '\&\\w*')+'\z', "i")
|
|
|
|
case
|
|
|
|
when re =~ "srcdir"
|
|
|
|
srcdir = value
|
|
|
|
when re =~ "archdir"
|
|
|
|
archdir = value
|
2009-02-07 06:31:04 +03:00
|
|
|
when re =~ "cpu"
|
|
|
|
precommand << "arch" << "-arch" << value
|
2004-02-09 11:48:55 +03:00
|
|
|
when re =~ "extout"
|
|
|
|
extout = value
|
2007-03-06 04:21:48 +03:00
|
|
|
when re =~ "pure"
|
|
|
|
pure = (value != "no")
|
|
|
|
when re =~ "debugger"
|
2009-02-07 05:57:15 +03:00
|
|
|
require 'shellwords'
|
|
|
|
precommand.concat(value ? (Shellwords.shellwords(value) unless value == "no") : %w"gdb --args")
|
|
|
|
when re =~ "precommand"
|
|
|
|
require 'shellwords'
|
|
|
|
precommand.concat(Shellwords.shellwords(value))
|
|
|
|
when re =~ "show"
|
|
|
|
show = true
|
2004-02-09 11:48:55 +03:00
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
|
2009-05-22 15:48:42 +04:00
|
|
|
srcdir ||= File.expand_path('..', File.dirname(__FILE__))
|
2004-02-09 11:48:55 +03:00
|
|
|
archdir ||= '.'
|
|
|
|
|
2005-06-23 18:56:40 +04:00
|
|
|
abs_archdir = File.expand_path(archdir)
|
|
|
|
$:.unshift(abs_archdir)
|
|
|
|
|
2009-02-07 06:31:04 +03:00
|
|
|
config = File.read(conffile = File.join(abs_archdir, 'rbconfig.rb'))
|
|
|
|
config.sub!(/^(\s*)RUBY_VERSION\s*==.*(\sor\s*)$/, '\1true\2')
|
2009-04-30 16:25:23 +04:00
|
|
|
config = Module.new {module_eval(config, conffile)}::RbConfig::CONFIG
|
2005-06-23 18:56:40 +04:00
|
|
|
|
2004-02-09 11:48:55 +03:00
|
|
|
ruby = File.join(archdir, config["RUBY_INSTALL_NAME"]+config['EXEEXT'])
|
|
|
|
unless File.exist?(ruby)
|
|
|
|
abort "#{ruby} is not found.\nTry `make' first, then `make test', please.\n"
|
|
|
|
end
|
|
|
|
|
2007-03-06 04:21:48 +03:00
|
|
|
libs = [abs_archdir]
|
2009-02-08 03:41:49 +03:00
|
|
|
extout ||= config["EXTOUT"]
|
2004-02-09 11:48:55 +03:00
|
|
|
if extout
|
|
|
|
abs_extout = File.expand_path(extout)
|
2009-02-08 03:41:49 +03:00
|
|
|
libs << File.expand_path("common", abs_extout) << File.expand_path(config['arch'], abs_extout)
|
2004-02-09 11:48:55 +03:00
|
|
|
end
|
2007-03-06 04:21:48 +03:00
|
|
|
libs << File.expand_path("lib", srcdir)
|
2004-02-09 11:48:55 +03:00
|
|
|
config["bindir"] = abs_archdir
|
2008-12-27 18:44:51 +03:00
|
|
|
|
|
|
|
env = {}
|
|
|
|
|
|
|
|
env["RUBY"] = File.expand_path(ruby)
|
|
|
|
env["PATH"] = [abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
|
2004-02-09 11:48:55 +03:00
|
|
|
|
2007-05-23 00:48:34 +04:00
|
|
|
if pure
|
|
|
|
libs << File.expand_path("ext", srcdir) << "-"
|
|
|
|
elsif e = ENV["RUBYLIB"]
|
2004-02-09 11:48:55 +03:00
|
|
|
libs |= e.split(File::PATH_SEPARATOR)
|
|
|
|
end
|
2008-12-27 18:44:51 +03:00
|
|
|
env["RUBYLIB"] = $:.replace(libs).join(File::PATH_SEPARATOR)
|
2004-02-09 11:48:55 +03:00
|
|
|
|
2004-12-07 21:26:46 +03:00
|
|
|
libruby_so = File.join(abs_archdir, config['LIBRUBY_SO'])
|
|
|
|
if File.file?(libruby_so)
|
|
|
|
if e = config['LIBPATHENV'] and !e.empty?
|
2008-12-27 18:44:51 +03:00
|
|
|
env[e] = [abs_archdir, ENV[e]].compact.join(File::PATH_SEPARATOR)
|
2004-12-07 21:26:46 +03:00
|
|
|
end
|
|
|
|
if /linux/ =~ RUBY_PLATFORM
|
2008-12-27 18:44:51 +03:00
|
|
|
env["LD_PRELOAD"] = [libruby_so, ENV["LD_PRELOAD"]].compact.join(' ')
|
2004-12-07 21:26:46 +03:00
|
|
|
end
|
2004-02-09 11:48:55 +03:00
|
|
|
end
|
|
|
|
|
2008-12-27 18:44:51 +03:00
|
|
|
ENV.update env
|
|
|
|
|
2007-03-06 04:21:48 +03:00
|
|
|
cmd = [ruby]
|
2007-05-23 00:48:34 +04:00
|
|
|
cmd << "-rpurelib.rb" if pure
|
2007-03-06 04:21:48 +03:00
|
|
|
cmd.concat(ARGV)
|
2009-02-07 05:57:15 +03:00
|
|
|
cmd.unshift(*precommand) unless precommand.empty?
|
2008-12-27 18:44:51 +03:00
|
|
|
|
2009-02-07 05:57:15 +03:00
|
|
|
if show
|
|
|
|
require 'shellwords'
|
|
|
|
env.each {|k,v| puts "#{k}=#{v}"}
|
|
|
|
puts Shellwords.join(cmd)
|
|
|
|
end
|
2008-12-27 18:44:51 +03:00
|
|
|
|
2007-03-06 04:21:48 +03:00
|
|
|
exec(*cmd)
|