1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* tool/mkrunnable.rb: refactor and multiarch support.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-02-22 02:37:51 +00:00
parent 20fa732495
commit 839ae05e0c

View file

@ -15,15 +15,6 @@ else
include FileUtils
end
def relative_from(path, base)
dir = File.join(path, "")
if File.expand_path(dir) == File.expand_path(dir, base)
path
else
File.join(base, path)
end
end
module Mswin
def ln_safe(src, dest, *opt)
cmd = ["mklink", dest.tr("/", "\\"), src.tr("/", "\\")]
@ -49,16 +40,57 @@ if /mingw|mswin/ =~ CROSS_COMPILING
extend Mswin
end
config = RbConfig::CONFIG
def clean_path(path)
path = "#{path}/".gsub(/(\A|\/)(?:\.\/)+/, '\1').tr_s('/', '/')
nil while path.sub!(/[^\/]+\/\.\.\//, '')
path
end
def relative_path_from(path, base)
path = clean_path(path)
base = clean_path(base)
path, base = [path, base].map{|s|s.split("/")}
until path.empty? or base.empty? or path[0] != base[0]
path.shift
base.shift
end
path, base = [path, base].map{|s|s.join("/")}
if /(\A|\/)\.\.\// =~ base
File.expand_path(path)
else
base.gsub!(/[^\/]+/, '..')
File.join(base, path)
end
end
def ln_relative(src, dest)
parent = File.dirname(dest)
File.directory?(parent) or mkdir_p(parent)
ln_safe(relative_path_from(src, parent), dest)
end
def ln_dir_relative(src, dest)
parent = File.dirname(dest)
File.directory?(parent) or mkdir_p(parent)
ln_dir_safe(relative_path_from(src, parent), dest)
end
config = RbConfig::MAKEFILE_CONFIG.merge("prefix" => ".", "exec_prefix" => ".")
config.each_value {|s| RbConfig.expand(s, config)}
srcdir = config["srcdir"] ||= File.dirname(__FILE__)
top_srcdir = config["top_srcdir"] ||= File.dirname(srcdir)
extout = ARGV[0] || config["EXTOUT"]
version = config["ruby_version"]
arch = config["arch"]
bindir = File.basename(config["bindir"])
libdir = File.basename(config["libdir"])
archdir = File.join(extout, arch)
[bindir, libdir, archdir].each do |dir|
bindir = config["bindir"]
libdirname = config["libdirname"]
libdir = config[libdirname || "libdir"]
vendordir = config["vendordir"]
rubylibdir = config["rubylibdir"]
rubyarchdir = config["rubyarchdir"]
archdir = "#{extout}/#{arch}"
rubylibs = [vendordir, rubylibdir, rubyarchdir]
[bindir, libdir, archdir].uniq.each do |dir|
File.directory?(dir) or mkdir_p(dir)
end
@ -69,29 +101,16 @@ goruby_install_name = "go" + ruby_install_name
[ruby_install_name, rubyw_install_name, goruby_install_name].map do |ruby|
ruby += exeext
if ruby and !ruby.empty?
ln_safe("../#{ruby}", "#{bindir}/#{ruby}")
ln_relative(ruby, "#{bindir}/#{ruby}")
end
end
libruby = config.values_at("LIBRUBY_A", "LIBRUBY_SO")
libruby.concat(config["LIBRUBY_ALIASES"].split)
libruby.each {|lib|ln_safe("../#{lib}", "#{libdir}/#{lib}")}
if File.expand_path(extout) == extout
ln_dir_safe(extout, "#{libdir}/ruby")
else
ln_dir_safe(File.join("..", extout), "#{libdir}/ruby")
cur = "#{extout}/".gsub(/(\A|\/)(?:\.\/)+/, '\1').tr_s('/', '/')
nil while cur.sub!(/[^\/]+\/\.\.\//, '')
if /(\A|\/)\.\.\// =~ cur
cur = nil
else
cur.gsub!(/[^\/]+/, '..')
end
end
if cur
ln_safe(File.join("..", cur, "rbconfig.rb"), File.join(archdir, "rbconfig.rb"))
else
ln_safe(File.expand_path("rbconfig.rb"), File.join(archdir, "rbconfig.rb"))
end
ln_dir_safe("common", File.join(extout, version))
ln_dir_safe(File.join("..", arch), File.join(extout, "common", arch))
ln_dir_safe(relative_from(File.join(top_srcdir, "lib"), ".."), File.join(extout, "vendor_ruby"))
libruby.each {|lib|ln_relative(lib, "#{libdir}/#{lib}")}
ln_dir_relative("#{extout}/common", rubylibdir)
rubyarchdir.sub!(rubylibdir, "#{extout}/common")
vendordir.sub!(rubylibdir, "#{extout}/common")
ln_dir_relative(archdir, rubyarchdir)
vendordir.sub!(rubyarchdir, archdir)
ln_dir_relative("#{top_srcdir}/lib", vendordir)
ln_relative("rbconfig.rb", "#{archdir}/rbconfig.rb")