2004-02-09 11:48:55 +03:00
|
|
|
#!./miniruby
|
|
|
|
|
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"
|
2010-08-03 07:05:39 +04:00
|
|
|
# obsolete switch do nothing
|
2007-03-06 04:21:48 +03:00
|
|
|
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
|
|
|
|
|
2012-06-08 11:19:38 +04:00
|
|
|
unless defined?(File.realpath)
|
|
|
|
def File.realpath(*args)
|
2012-06-16 02:12:58 +04:00
|
|
|
Dir.chdir(expand_path(*args)) do
|
2012-06-08 11:19:38 +04:00
|
|
|
Dir.pwd
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
srcdir ||= File.realpath('..', 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'))
|
2015-06-14 04:46:22 +03:00
|
|
|
config.sub!(/^(\s*)RUBY_VERSION\b.*(\sor\s*)\n.*\n/, '')
|
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
|
2012-06-08 11:19:38 +04:00
|
|
|
abs_extout = File.expand_path(extout, abs_archdir)
|
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 = {}
|
|
|
|
|
2015-10-04 04:25:42 +03:00
|
|
|
runner = File.join(abs_archdir, "ruby-runner#{config['EXEEXT']}")
|
|
|
|
runner = File.expand_path(ruby) unless File.exist?(runner)
|
|
|
|
env["RUBY"] = runner
|
2008-12-27 18:44:51 +03:00
|
|
|
env["PATH"] = [abs_archdir, ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
|
2004-02-09 11:48:55 +03:00
|
|
|
|
2010-08-03 07:05:39 +04:00
|
|
|
if 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
|
2015-02-26 11:01:54 +03:00
|
|
|
if e = config['PRELOADENV']
|
|
|
|
e = nil if e.empty?
|
|
|
|
e ||= "LD_PRELOAD" if /linux/ =~ RUBY_PLATFORM
|
|
|
|
end
|
|
|
|
if e
|
2015-02-26 17:42:11 +03:00
|
|
|
env[e] = [libruby_so, ENV[e]].compact.join(File::PATH_SEPARATOR)
|
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]
|
|
|
|
cmd.concat(ARGV)
|
2009-02-07 05:57:15 +03:00
|
|
|
cmd.unshift(*precommand) unless precommand.empty?
|
2015-06-21 13:52:41 +03:00
|
|
|
cmd.push(:close_others => false)
|
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)
|