* 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
Родитель 20fa732495
Коммит 839ae05e0c
1 изменённых файлов: 55 добавлений и 36 удалений

Просмотреть файл

@ -15,15 +15,6 @@ else
include FileUtils include FileUtils
end 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 module Mswin
def ln_safe(src, dest, *opt) def ln_safe(src, dest, *opt)
cmd = ["mklink", dest.tr("/", "\\"), src.tr("/", "\\")] cmd = ["mklink", dest.tr("/", "\\"), src.tr("/", "\\")]
@ -49,16 +40,57 @@ if /mingw|mswin/ =~ CROSS_COMPILING
extend Mswin extend Mswin
end 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__) srcdir = config["srcdir"] ||= File.dirname(__FILE__)
top_srcdir = config["top_srcdir"] ||= File.dirname(srcdir) top_srcdir = config["top_srcdir"] ||= File.dirname(srcdir)
extout = ARGV[0] || config["EXTOUT"] extout = ARGV[0] || config["EXTOUT"]
version = config["ruby_version"] version = config["ruby_version"]
arch = config["arch"] arch = config["arch"]
bindir = File.basename(config["bindir"]) bindir = config["bindir"]
libdir = File.basename(config["libdir"]) libdirname = config["libdirname"]
archdir = File.join(extout, arch) libdir = config[libdirname || "libdir"]
[bindir, libdir, archdir].each do |dir| 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) File.directory?(dir) or mkdir_p(dir)
end 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_install_name, rubyw_install_name, goruby_install_name].map do |ruby|
ruby += exeext ruby += exeext
if ruby and !ruby.empty? if ruby and !ruby.empty?
ln_safe("../#{ruby}", "#{bindir}/#{ruby}") ln_relative(ruby, "#{bindir}/#{ruby}")
end end
end end
libruby = config.values_at("LIBRUBY_A", "LIBRUBY_SO") libruby = config.values_at("LIBRUBY_A", "LIBRUBY_SO")
libruby.concat(config["LIBRUBY_ALIASES"].split) libruby.concat(config["LIBRUBY_ALIASES"].split)
libruby.each {|lib|ln_safe("../#{lib}", "#{libdir}/#{lib}")} libruby.each {|lib|ln_relative(lib, "#{libdir}/#{lib}")}
if File.expand_path(extout) == extout ln_dir_relative("#{extout}/common", rubylibdir)
ln_dir_safe(extout, "#{libdir}/ruby") rubyarchdir.sub!(rubylibdir, "#{extout}/common")
else vendordir.sub!(rubylibdir, "#{extout}/common")
ln_dir_safe(File.join("..", extout), "#{libdir}/ruby") ln_dir_relative(archdir, rubyarchdir)
cur = "#{extout}/".gsub(/(\A|\/)(?:\.\/)+/, '\1').tr_s('/', '/') vendordir.sub!(rubyarchdir, archdir)
nil while cur.sub!(/[^\/]+\/\.\.\//, '') ln_dir_relative("#{top_srcdir}/lib", vendordir)
if /(\A|\/)\.\.\// =~ cur ln_relative("rbconfig.rb", "#{archdir}/rbconfig.rb")
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"))