2012-07-03 06:16:08 +04:00
|
|
|
#!./miniruby
|
2012-11-23 17:49:14 +04:00
|
|
|
# -*- coding: us-ascii -*-
|
2012-07-03 06:16:08 +04:00
|
|
|
|
2013-02-19 07:49:35 +04:00
|
|
|
require './rbconfig'
|
2013-01-11 11:59:07 +04:00
|
|
|
require 'fileutils'
|
2012-07-03 06:16:08 +04:00
|
|
|
|
|
|
|
case ARGV[0]
|
|
|
|
when "-n"
|
|
|
|
ARGV.shift
|
|
|
|
include FileUtils::DryRun
|
|
|
|
when "-v"
|
|
|
|
ARGV.shift
|
|
|
|
include FileUtils::Verbose
|
|
|
|
else
|
|
|
|
include FileUtils
|
|
|
|
end
|
|
|
|
|
2013-01-11 11:59:07 +04:00
|
|
|
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
|
|
|
|
|
2012-07-25 12:17:46 +04:00
|
|
|
module Mswin
|
|
|
|
def ln_safe(src, dest, *opt)
|
|
|
|
cmd = ["mklink", dest.tr("/", "\\"), src.tr("/", "\\")]
|
|
|
|
cmd[1, 0] = opt
|
|
|
|
# TODO: use RUNAS or something
|
|
|
|
puts cmd.join(" ")
|
|
|
|
end
|
|
|
|
|
|
|
|
def ln_dir_safe(src, dest)
|
|
|
|
ln_safe(src, dest, "/d")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-03 06:16:08 +04:00
|
|
|
def ln_safe(src, dest)
|
|
|
|
link = File.readlink(dest) rescue nil
|
|
|
|
return if link == src
|
|
|
|
ln_sf(src, dest)
|
|
|
|
end
|
|
|
|
|
2012-07-25 12:17:46 +04:00
|
|
|
alias ln_dir_safe ln_safe
|
|
|
|
|
2013-01-11 11:59:07 +04:00
|
|
|
if /mingw|mswin/ =~ CROSS_COMPILING
|
2012-07-25 12:17:46 +04:00
|
|
|
extend Mswin
|
|
|
|
end
|
|
|
|
|
2012-07-03 06:16:08 +04:00
|
|
|
config = RbConfig::CONFIG
|
2013-01-11 11:59:07 +04:00
|
|
|
srcdir = config["srcdir"] ||= File.dirname(__FILE__)
|
|
|
|
top_srcdir = config["top_srcdir"] ||= File.dirname(srcdir)
|
2012-07-03 06:16:08 +04:00
|
|
|
extout = ARGV[0] || config["EXTOUT"]
|
|
|
|
version = config["ruby_version"]
|
|
|
|
arch = config["arch"]
|
2012-08-29 09:59:07 +04:00
|
|
|
bindir = File.basename(config["bindir"])
|
|
|
|
libdir = File.basename(config["libdir"])
|
2012-11-23 17:49:14 +04:00
|
|
|
archdir = File.join(extout, arch)
|
|
|
|
[bindir, libdir, archdir].each do |dir|
|
2012-07-03 06:16:08 +04:00
|
|
|
File.directory?(dir) or mkdir_p(dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
exeext = config["EXEEXT"]
|
|
|
|
ruby_install_name = config["ruby_install_name"]
|
|
|
|
rubyw_install_name = config["rubyw_install_name"]
|
|
|
|
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?
|
2012-08-29 09:59:07 +04:00
|
|
|
ln_safe("../#{ruby}", "#{bindir}/#{ruby}")
|
2012-07-03 06:16:08 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
libruby = config.values_at("LIBRUBY_A", "LIBRUBY_SO")
|
|
|
|
libruby.concat(config["LIBRUBY_ALIASES"].split)
|
2012-08-29 09:59:07 +04:00
|
|
|
libruby.each {|lib|ln_safe("../#{lib}", "#{libdir}/#{lib}")}
|
2012-07-03 06:16:08 +04:00
|
|
|
if File.expand_path(extout) == extout
|
2012-08-29 09:59:07 +04:00
|
|
|
ln_dir_safe(extout, "#{libdir}/ruby")
|
2012-07-03 06:16:08 +04:00
|
|
|
else
|
2012-08-29 09:59:07 +04:00
|
|
|
ln_dir_safe(File.join("..", extout), "#{libdir}/ruby")
|
2012-07-03 06:16:08 +04:00
|
|
|
cur = "#{extout}/".gsub(/(\A|\/)(?:\.\/)+/, '\1').tr_s('/', '/')
|
|
|
|
nil while cur.sub!(/[^\/]+\/\.\.\//, '')
|
|
|
|
if /(\A|\/)\.\.\// =~ cur
|
|
|
|
cur = nil
|
|
|
|
else
|
|
|
|
cur.gsub!(/[^\/]+/, '..')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if cur
|
2012-11-23 17:49:14 +04:00
|
|
|
ln_safe(File.join("..", cur, "rbconfig.rb"), File.join(archdir, "rbconfig.rb"))
|
2012-07-03 06:16:08 +04:00
|
|
|
else
|
2012-11-23 17:49:14 +04:00
|
|
|
ln_safe(File.expand_path("rbconfig.rb"), File.join(archdir, "rbconfig.rb"))
|
2012-07-03 06:16:08 +04:00
|
|
|
end
|
2012-07-25 12:17:46 +04:00
|
|
|
ln_dir_safe("common", File.join(extout, version))
|
|
|
|
ln_dir_safe(File.join("..", arch), File.join(extout, "common", arch))
|
2013-01-11 11:59:07 +04:00
|
|
|
ln_dir_safe(relative_from(File.join(top_srcdir, "lib"), ".."), File.join(extout, "vendor_ruby"))
|