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
|
|
|
|
2016-07-03 00:01:04 +03:00
|
|
|
# Used by "make runnable" target, to make symbolic links from a build
|
|
|
|
# directory.
|
|
|
|
|
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
|
|
|
|
|
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
|
2015-02-24 07:59:03 +03:00
|
|
|
return if system("cmd", "/c", *cmd)
|
2012-07-25 12:17:46 +04:00
|
|
|
# TODO: use RUNAS or something
|
|
|
|
puts cmd.join(" ")
|
|
|
|
end
|
|
|
|
|
|
|
|
def ln_dir_safe(src, dest)
|
|
|
|
ln_safe(src, dest, "/d")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-09 09:50:53 +03:00
|
|
|
def clean_link(src, dest)
|
|
|
|
begin
|
|
|
|
link = File.readlink(dest)
|
|
|
|
rescue
|
|
|
|
else
|
|
|
|
return if link == src
|
|
|
|
File.unlink(dest)
|
|
|
|
end
|
|
|
|
yield src, dest
|
|
|
|
end
|
|
|
|
|
2012-07-03 06:16:08 +04:00
|
|
|
def ln_safe(src, dest)
|
|
|
|
ln_sf(src, dest)
|
2020-05-29 19:15:23 +03:00
|
|
|
rescue Errno::ENOENT
|
|
|
|
# Windows disallows to create broken symboic links, probably because
|
|
|
|
# it is a kind of reparse points.
|
|
|
|
raise if File.exist?(src)
|
2012-07-03 06:16:08 +04:00
|
|
|
end
|
|
|
|
|
2012-07-25 12:17:46 +04:00
|
|
|
alias ln_dir_safe ln_safe
|
|
|
|
|
2021-08-19 10:10:14 +03:00
|
|
|
case RUBY_PLATFORM
|
2021-12-14 06:19:44 +03:00
|
|
|
when /linux|darwin|solaris/
|
2021-08-19 10:10:14 +03:00
|
|
|
def ln_exe(src, dest)
|
|
|
|
ln(src, dest, force: true)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
alias ln_exe ln_safe
|
|
|
|
end
|
|
|
|
|
2016-02-09 09:57:09 +03:00
|
|
|
if !File.respond_to?(:symlink) && /mingw|mswin/ =~ (CROSS_COMPILING || RUBY_PLATFORM)
|
2012-07-25 12:17:46 +04:00
|
|
|
extend Mswin
|
|
|
|
end
|
|
|
|
|
2013-02-22 06:37:51 +04:00
|
|
|
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]
|
2020-05-29 19:15:23 +03:00
|
|
|
path.shift
|
|
|
|
base.shift
|
2013-02-22 06:37:51 +04:00
|
|
|
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
|
|
|
|
|
2021-08-19 10:10:14 +03:00
|
|
|
def ln_relative(src, dest, executable = false)
|
2015-02-24 07:59:03 +03:00
|
|
|
return if File.identical?(src, dest)
|
2013-02-22 06:37:51 +04:00
|
|
|
parent = File.dirname(dest)
|
|
|
|
File.directory?(parent) or mkdir_p(parent)
|
2021-08-19 10:10:14 +03:00
|
|
|
return ln_exe(src, dest) if executable
|
2016-02-09 09:50:53 +03:00
|
|
|
clean_link(relative_path_from(src, parent), dest) {|s, d| ln_safe(s, d)}
|
2013-02-22 06:37:51 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def ln_dir_relative(src, dest)
|
2015-02-24 07:59:03 +03:00
|
|
|
return if File.identical?(src, dest)
|
2013-02-22 06:37:51 +04:00
|
|
|
parent = File.dirname(dest)
|
|
|
|
File.directory?(parent) or mkdir_p(parent)
|
2016-02-09 09:50:53 +03:00
|
|
|
clean_link(relative_path_from(src, parent), dest) {|s, d| ln_dir_safe(s, d)}
|
2013-02-22 06:37:51 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
config = RbConfig::MAKEFILE_CONFIG.merge("prefix" => ".", "exec_prefix" => ".")
|
|
|
|
config.each_value {|s| RbConfig.expand(s, 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"]
|
|
|
|
arch = config["arch"]
|
2013-02-22 06:37:51 +04:00
|
|
|
bindir = config["bindir"]
|
|
|
|
libdirname = config["libdirname"]
|
|
|
|
libdir = config[libdirname || "libdir"]
|
|
|
|
vendordir = config["vendordir"]
|
|
|
|
rubylibdir = config["rubylibdir"]
|
|
|
|
rubyarchdir = config["rubyarchdir"]
|
|
|
|
archdir = "#{extout}/#{arch}"
|
|
|
|
[bindir, libdir, archdir].uniq.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|
|
2021-08-19 10:10:14 +03:00
|
|
|
if ruby and !ruby.empty?
|
|
|
|
ruby += exeext
|
|
|
|
ln_relative(ruby, "#{bindir}/#{ruby}", true)
|
2012-07-03 06:16:08 +04:00
|
|
|
end
|
|
|
|
end
|
2014-01-02 06:41:06 +04:00
|
|
|
so = config["LIBRUBY_SO"]
|
|
|
|
libruby = [config["LIBRUBY_A"]]
|
|
|
|
if /\.dll\z/i =~ so
|
|
|
|
ln_relative(so, "#{bindir}/#{so}")
|
|
|
|
else
|
|
|
|
libruby << so
|
|
|
|
end
|
2012-07-03 06:16:08 +04:00
|
|
|
libruby.concat(config["LIBRUBY_ALIASES"].split)
|
2013-02-22 06:37:51 +04:00
|
|
|
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")
|