2004-02-09 03:48:55 -05:00
|
|
|
#!./miniruby
|
|
|
|
|
2009-02-06 21:57:15 -05:00
|
|
|
show = false
|
|
|
|
precommand = []
|
2004-02-09 03:48:55 -05: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-06 22:31:04 -05:00
|
|
|
when re =~ "cpu"
|
|
|
|
precommand << "arch" << "-arch" << value
|
2004-02-09 03:48:55 -05:00
|
|
|
when re =~ "extout"
|
|
|
|
extout = value
|
2007-03-05 20:21:48 -05:00
|
|
|
when re =~ "pure"
|
2010-08-02 23:05:39 -04:00
|
|
|
# obsolete switch do nothing
|
2007-03-05 20:21:48 -05:00
|
|
|
when re =~ "debugger"
|
2009-02-06 21:57:15 -05: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 03:48:55 -05:00
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ARGV.shift
|
|
|
|
end
|
|
|
|
|
2012-06-08 03:19:38 -04:00
|
|
|
unless defined?(File.realpath)
|
|
|
|
def File.realpath(*args)
|
2012-06-15 18:12:58 -04:00
|
|
|
Dir.chdir(expand_path(*args)) do
|
2012-06-08 03:19:38 -04:00
|
|
|
Dir.pwd
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
srcdir ||= File.realpath('..', File.dirname(__FILE__))
|
2004-02-09 03:48:55 -05:00
|
|
|
archdir ||= '.'
|
|
|
|
|
2005-06-23 10:56:40 -04:00
|
|
|
abs_archdir = File.expand_path(archdir)
|
|
|
|
$:.unshift(abs_archdir)
|
|
|
|
|
2009-02-06 22:31:04 -05:00
|
|
|
config = File.read(conffile = File.join(abs_archdir, 'rbconfig.rb'))
|
2015-06-13 21:46:22 -04:00
|
|
|
config.sub!(/^(\s*)RUBY_VERSION\b.*(\sor\s*)\n.*\n/, '')
|
2009-04-30 08:25:23 -04:00
|
|
|
config = Module.new {module_eval(config, conffile)}::RbConfig::CONFIG
|
2005-06-23 10:56:40 -04:00
|
|
|
|
2004-02-09 03:48:55 -05: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-05 20:21:48 -05:00
|
|
|
libs = [abs_archdir]
|
2009-02-07 19:41:49 -05:00
|
|
|
extout ||= config["EXTOUT"]
|
2004-02-09 03:48:55 -05:00
|
|
|
if extout
|
2012-06-08 03:19:38 -04:00
|
|
|
abs_extout = File.expand_path(extout, abs_archdir)
|
2009-02-07 19:41:49 -05:00
|
|
|
libs << File.expand_path("common", abs_extout) << File.expand_path(config['arch'], abs_extout)
|
2004-02-09 03:48:55 -05:00
|
|
|
end
|
2007-03-05 20:21:48 -05:00
|
|
|
libs << File.expand_path("lib", srcdir)
|
2004-02-09 03:48:55 -05:00
|
|
|
config["bindir"] = abs_archdir
|
2008-12-27 10:44:51 -05:00
|
|
|
|
|
|
|
env = {}
|
|
|
|
|
|
|
|
env["RUBY"] = File.expand_path(ruby)
|
|
|
|
env["PATH"] = [abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
|
2004-02-09 03:48:55 -05:00
|
|
|
|
2010-08-02 23:05:39 -04:00
|
|
|
if e = ENV["RUBYLIB"]
|
2004-02-09 03:48:55 -05:00
|
|
|
libs |= e.split(File::PATH_SEPARATOR)
|
|
|
|
end
|
2008-12-27 10:44:51 -05:00
|
|
|
env["RUBYLIB"] = $:.replace(libs).join(File::PATH_SEPARATOR)
|
2004-02-09 03:48:55 -05:00
|
|
|
|
2004-12-07 13:26:46 -05: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 10:44:51 -05:00
|
|
|
env[e] = [abs_archdir, ENV[e]].compact.join(File::PATH_SEPARATOR)
|
2004-12-07 13:26:46 -05:00
|
|
|
end
|
2015-02-26 03:01:54 -05:00
|
|
|
if e = config['PRELOADENV']
|
|
|
|
e = nil if e.empty?
|
|
|
|
e ||= "LD_PRELOAD" if /linux/ =~ RUBY_PLATFORM
|
|
|
|
end
|
|
|
|
if e
|
2015-02-26 09:42:11 -05:00
|
|
|
env[e] = [libruby_so, ENV[e]].compact.join(File::PATH_SEPARATOR)
|
2004-12-07 13:26:46 -05:00
|
|
|
end
|
2004-02-09 03:48:55 -05:00
|
|
|
end
|
|
|
|
|
2008-12-27 10:44:51 -05:00
|
|
|
ENV.update env
|
|
|
|
|
2007-03-05 20:21:48 -05:00
|
|
|
cmd = [ruby]
|
|
|
|
cmd.concat(ARGV)
|
2009-02-06 21:57:15 -05:00
|
|
|
cmd.unshift(*precommand) unless precommand.empty?
|
2015-06-21 06:52:41 -04:00
|
|
|
cmd.push(:close_others => false)
|
2008-12-27 10:44:51 -05:00
|
|
|
|
2009-02-06 21:57:15 -05:00
|
|
|
if show
|
|
|
|
require 'shellwords'
|
|
|
|
env.each {|k,v| puts "#{k}=#{v}"}
|
|
|
|
puts Shellwords.join(cmd)
|
|
|
|
end
|
2008-12-27 10:44:51 -05:00
|
|
|
|
2007-03-05 20:21:48 -05:00
|
|
|
exec(*cmd)
|