2000-09-01 07:31:05 +04:00
|
|
|
#!./miniruby
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2000-09-01 07:31:05 +04:00
|
|
|
load "./rbconfig.rb"
|
1998-01-16 15:19:09 +03:00
|
|
|
include Config
|
|
|
|
|
2004-03-18 13:49:20 +03:00
|
|
|
srcdir = File.dirname(__FILE__)
|
|
|
|
$:.unshift File.join(srcdir, "lib")
|
2002-12-26 21:01:34 +03:00
|
|
|
require 'fileutils'
|
|
|
|
require 'shellwords'
|
2004-02-23 03:09:48 +03:00
|
|
|
require 'optparse'
|
|
|
|
require 'optparse/shellwords'
|
2003-01-20 15:51:50 +03:00
|
|
|
require 'tempfile'
|
2002-12-26 21:01:34 +03:00
|
|
|
|
2003-05-02 10:07:54 +04:00
|
|
|
File.umask(0)
|
2002-10-22 08:19:26 +04:00
|
|
|
|
2003-01-25 21:59:34 +03:00
|
|
|
def parse_args()
|
2004-02-23 03:09:48 +03:00
|
|
|
$mantype = 'doc'
|
|
|
|
$destdir = nil
|
|
|
|
$make = 'make'
|
|
|
|
$mflags = []
|
|
|
|
opt = OptionParser.new
|
|
|
|
opt.on('-n') {$dryrun = true}
|
|
|
|
opt.on('--dest-dir=DIR') {|dir| $destdir = dir}
|
|
|
|
opt.on('--make=COMMAND') {|make| $make = make}
|
|
|
|
opt.on('--mantype=MAN') {|man| $mantype = man}
|
|
|
|
opt.on('--make-flags=FLAGS', '--mflags', Shellwords) do |v|
|
|
|
|
if arg = v.first
|
|
|
|
arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
|
|
|
|
end
|
|
|
|
$mflags.concat(v)
|
2003-01-27 22:48:02 +03:00
|
|
|
end
|
2004-02-23 03:09:48 +03:00
|
|
|
opt.parse! rescue abort [$!.message, opt].join("\n")
|
2003-01-27 22:48:02 +03:00
|
|
|
|
2003-01-25 21:59:34 +03:00
|
|
|
$make, *rest = Shellwords.shellwords($make)
|
|
|
|
$mflags.unshift(*rest) unless rest.empty?
|
|
|
|
|
2003-01-26 11:56:01 +03:00
|
|
|
def $mflags.set?(flag)
|
2003-01-27 22:48:02 +03:00
|
|
|
grep(/\A-(?!-).*#{'%c' % flag}/i) { return true }
|
|
|
|
false
|
2003-01-26 11:56:01 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
if $mflags.set?(?n)
|
|
|
|
$dryrun = true
|
|
|
|
else
|
|
|
|
$mflags << '-n' if $dryrun
|
|
|
|
end
|
2003-01-25 21:59:34 +03:00
|
|
|
|
|
|
|
$mflags << "DESTDIR=#{$destdir}"
|
|
|
|
|
2003-01-26 11:56:01 +03:00
|
|
|
$continue = $mflags.set?(?k)
|
2003-01-25 21:59:34 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
parse_args()
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2003-07-29 11:08:04 +04:00
|
|
|
include FileUtils::Verbose
|
2002-12-26 21:01:34 +03:00
|
|
|
include FileUtils::NoWrite if $dryrun
|
|
|
|
@fileutils_output = STDOUT
|
|
|
|
@fileutils_label = ''
|
2003-07-29 11:08:04 +04:00
|
|
|
|
|
|
|
def install(src, dest, options = {})
|
2003-07-29 14:24:28 +04:00
|
|
|
options[:preserve] = true
|
2004-11-30 09:01:58 +03:00
|
|
|
super src, dest, options
|
2003-01-26 00:42:42 +03:00
|
|
|
end
|
2003-07-29 11:08:04 +04:00
|
|
|
|
2003-01-26 01:23:17 +03:00
|
|
|
$made_dirs = {}
|
|
|
|
def makedirs(dirs)
|
|
|
|
dirs = fu_list(dirs)
|
|
|
|
dirs.reject! do |dir|
|
|
|
|
$made_dirs.fetch(dir) do
|
|
|
|
$made_dirs[dir] = true
|
|
|
|
File.directory?(dir)
|
|
|
|
end
|
|
|
|
end
|
2003-05-02 10:07:54 +04:00
|
|
|
super(dirs, :mode => 0755, :verbose => true) unless dirs.empty?
|
2003-01-26 01:23:17 +03:00
|
|
|
end
|
2000-02-17 10:11:22 +03:00
|
|
|
|
2004-02-23 03:09:48 +03:00
|
|
|
def with_destdir(dir)
|
2004-02-25 15:16:30 +03:00
|
|
|
return dir if $destdir.empty?
|
2004-02-23 03:09:48 +03:00
|
|
|
dir = dir.sub(/\A\w:/, '') if File::PATH_SEPARATOR == ';'
|
|
|
|
$destdir + dir
|
2003-12-28 20:25:31 +03:00
|
|
|
end
|
|
|
|
|
2002-10-22 08:19:26 +04:00
|
|
|
exeext = CONFIG["EXEEXT"]
|
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
ruby_install_name = CONFIG["ruby_install_name"]
|
2002-10-22 08:19:26 +04:00
|
|
|
rubyw_install_name = CONFIG["rubyw_install_name"]
|
2000-02-17 10:11:22 +03:00
|
|
|
|
2002-10-22 08:19:26 +04:00
|
|
|
version = CONFIG["ruby_version"]
|
2004-02-23 03:09:48 +03:00
|
|
|
bindir = with_destdir(CONFIG["bindir"])
|
|
|
|
libdir = with_destdir(CONFIG["libdir"])
|
|
|
|
rubylibdir = with_destdir(CONFIG["rubylibdir"])
|
|
|
|
archlibdir = with_destdir(CONFIG["archdir"])
|
|
|
|
sitelibdir = with_destdir(CONFIG["sitelibdir"])
|
|
|
|
sitearchlibdir = with_destdir(CONFIG["sitearchdir"])
|
|
|
|
mandir = with_destdir(File.join(CONFIG["mandir"], "man"))
|
2002-10-23 21:40:36 +04:00
|
|
|
configure_args = Shellwords.shellwords(CONFIG["configure_args"])
|
2002-11-04 14:06:03 +03:00
|
|
|
enable_shared = CONFIG["ENABLE_SHARED"] == 'yes'
|
2002-10-22 08:19:26 +04:00
|
|
|
dll = CONFIG["LIBRUBY_SO"]
|
|
|
|
lib = CONFIG["LIBRUBY"]
|
|
|
|
arc = CONFIG["LIBRUBY_A"]
|
|
|
|
|
2003-01-20 15:51:50 +03:00
|
|
|
makedirs [bindir, libdir, rubylibdir, archlibdir, sitelibdir, sitearchlibdir]
|
2002-10-22 08:19:26 +04:00
|
|
|
|
2003-01-23 00:42:25 +03:00
|
|
|
ruby_bin = File.join(bindir, ruby_install_name)
|
2003-01-21 11:03:05 +03:00
|
|
|
|
2003-05-02 10:07:54 +04:00
|
|
|
install ruby_install_name+exeext, ruby_bin+exeext, :mode => 0755
|
2002-10-22 08:19:26 +04:00
|
|
|
if rubyw_install_name and !rubyw_install_name.empty?
|
2003-05-02 10:07:54 +04:00
|
|
|
install rubyw_install_name+exeext, bindir, :mode => 0755
|
1999-01-20 07:59:39 +03:00
|
|
|
end
|
2003-05-02 10:07:54 +04:00
|
|
|
install dll, bindir, :mode => 0755 if enable_shared and dll != lib
|
2003-07-09 10:45:45 +04:00
|
|
|
install lib, libdir, :mode => 0755 unless lib == arc
|
2003-05-02 10:07:54 +04:00
|
|
|
install arc, libdir, :mode => 0644
|
|
|
|
install "config.h", archlibdir, :mode => 0644
|
|
|
|
install "rbconfig.rb", archlibdir, :mode => 0644
|
2002-10-22 08:19:26 +04:00
|
|
|
if CONFIG["ARCHFILE"]
|
|
|
|
for file in CONFIG["ARCHFILE"].split
|
2003-05-02 10:07:54 +04:00
|
|
|
install file, archlibdir, :mode => 0644
|
1999-01-20 07:59:39 +03:00
|
|
|
end
|
|
|
|
end
|
2002-10-22 08:19:26 +04:00
|
|
|
|
|
|
|
if dll == lib and dll != arc
|
1999-08-13 09:45:20 +04:00
|
|
|
for link in CONFIG["LIBRUBY_ALIASES"].split
|
2003-07-29 11:08:04 +04:00
|
|
|
ln_sf(dll, File.join(libdir, link))
|
1999-08-13 09:45:20 +04:00
|
|
|
end
|
|
|
|
end
|
2002-09-08 13:08:15 +04:00
|
|
|
|
2004-03-18 13:49:20 +03:00
|
|
|
Dir.chdir srcdir
|
1999-08-13 09:45:20 +04:00
|
|
|
|
2003-01-23 00:42:25 +03:00
|
|
|
ruby_shebang = File.join(CONFIG["bindir"], ruby_install_name)
|
2004-02-23 03:09:48 +03:00
|
|
|
if File::ALT_SEPARATOR
|
|
|
|
ruby_bin_dosish = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
|
|
|
|
end
|
2002-11-18 20:26:03 +03:00
|
|
|
for src in Dir["bin/*"]
|
|
|
|
next unless File.file?(src)
|
2002-11-18 23:16:54 +03:00
|
|
|
next if /\/[.#]|(\.(old|bak|orig|rej|diff|patch|core)|~|\/core)$/i =~ src
|
2002-11-18 19:57:36 +03:00
|
|
|
|
2002-11-18 20:26:03 +03:00
|
|
|
name = ruby_install_name.sub(/ruby/, File.basename(src))
|
|
|
|
dest = File.join(bindir, name)
|
2002-11-18 19:57:36 +03:00
|
|
|
|
2003-05-02 10:07:54 +04:00
|
|
|
install src, dest, :mode => 0755
|
2002-11-18 20:26:03 +03:00
|
|
|
|
2003-01-21 11:03:05 +03:00
|
|
|
next if $dryrun
|
|
|
|
|
|
|
|
shebang = ''
|
|
|
|
body = ''
|
2002-11-18 20:26:03 +03:00
|
|
|
open(dest, "r+") { |f|
|
2003-01-21 11:03:05 +03:00
|
|
|
shebang = f.gets
|
2002-11-22 13:22:29 +03:00
|
|
|
body = f.read
|
2002-11-18 20:26:03 +03:00
|
|
|
|
2003-01-23 00:42:25 +03:00
|
|
|
if shebang.sub!(/^\#!.*?ruby\b/) {"#!" + ruby_shebang}
|
2003-01-21 11:03:05 +03:00
|
|
|
f.rewind
|
|
|
|
f.print shebang, body
|
|
|
|
f.truncate(f.pos)
|
|
|
|
end
|
|
|
|
}
|
2002-11-22 13:22:29 +03:00
|
|
|
|
2004-02-23 03:09:48 +03:00
|
|
|
if ruby_bin_dosish
|
|
|
|
batfile = File.join(CONFIG["bindir"], name + ".bat")
|
|
|
|
open(with_destdir(batfile), "w") { |b|
|
2003-01-21 11:03:05 +03:00
|
|
|
b.print <<EOH, shebang, body, <<EOF
|
2002-11-22 13:22:29 +03:00
|
|
|
@echo off
|
2004-02-25 15:16:30 +03:00
|
|
|
if not "%~d0" == "~d0" goto WinNT
|
2003-01-21 11:03:05 +03:00
|
|
|
#{ruby_bin_dosish} -x "#{batfile}" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
2002-11-22 13:22:29 +03:00
|
|
|
goto endofruby
|
|
|
|
:WinNT
|
2004-02-25 15:16:30 +03:00
|
|
|
"%~dp0#{ruby_install_name}" -x "%~f0" %*
|
2002-11-22 13:22:29 +03:00
|
|
|
goto endofruby
|
|
|
|
EOH
|
|
|
|
__END__
|
|
|
|
:endofruby
|
|
|
|
EOF
|
2003-01-21 11:03:05 +03:00
|
|
|
}
|
|
|
|
end
|
2002-11-18 19:57:36 +03:00
|
|
|
end
|
2000-07-14 08:34:43 +04:00
|
|
|
|
2003-08-18 20:24:42 +04:00
|
|
|
for f in Dir["lib/**/*{.rb,help-message}"]
|
2002-10-22 08:19:26 +04:00
|
|
|
dir = File.dirname(f).sub!(/\Alib/, rubylibdir) || rubylibdir
|
2003-01-26 01:23:17 +03:00
|
|
|
makedirs dir
|
2003-05-02 10:07:54 +04:00
|
|
|
install f, dir, :mode => 0644
|
1999-01-20 07:59:39 +03:00
|
|
|
end
|
|
|
|
|
2003-08-18 20:24:42 +04:00
|
|
|
for f in Dir["*.h"]
|
2003-05-02 10:07:54 +04:00
|
|
|
install f, archlibdir, :mode => 0644
|
1999-08-13 09:45:20 +04:00
|
|
|
end
|
2003-01-20 15:51:50 +03:00
|
|
|
|
2002-06-11 05:27:48 +04:00
|
|
|
if RUBY_PLATFORM =~ /mswin32|mingw|bccwin32/
|
2002-12-26 21:01:34 +03:00
|
|
|
makedirs File.join(archlibdir, "win32")
|
2003-05-02 10:07:54 +04:00
|
|
|
install "win32/win32.h", File.join(archlibdir, "win32"), :mode => 0644
|
1998-01-16 15:19:09 +03:00
|
|
|
end
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2003-08-18 20:24:42 +04:00
|
|
|
for mdoc in Dir["*.[1-9]"]
|
2003-07-11 13:39:09 +04:00
|
|
|
next unless File.file?(mdoc) and open(mdoc){|fh| fh.read(1) == '.'}
|
2003-07-09 10:45:45 +04:00
|
|
|
|
2003-01-20 15:51:50 +03:00
|
|
|
section = mdoc[-1,1]
|
|
|
|
|
2003-02-20 17:15:57 +03:00
|
|
|
destdir = mandir + section
|
|
|
|
destfile = File.join(destdir, mdoc.sub(/ruby/, ruby_install_name))
|
2003-01-20 15:51:50 +03:00
|
|
|
|
2003-02-20 17:15:57 +03:00
|
|
|
makedirs destdir
|
2003-01-20 15:51:50 +03:00
|
|
|
|
2003-01-25 21:59:34 +03:00
|
|
|
if $mantype == "doc"
|
2003-05-02 10:07:54 +04:00
|
|
|
install mdoc, destfile, :mode => 0644
|
2003-01-20 15:51:50 +03:00
|
|
|
else
|
|
|
|
require 'mdoc2man.rb'
|
|
|
|
|
|
|
|
w = Tempfile.open(mdoc)
|
|
|
|
|
|
|
|
open(mdoc) { |r|
|
|
|
|
Mdoc2Man.mdoc2man(r, w)
|
|
|
|
}
|
|
|
|
|
|
|
|
w.close
|
|
|
|
|
2003-05-02 10:07:54 +04:00
|
|
|
install w.path, destfile, :mode => 0644
|
2003-01-20 15:51:50 +03:00
|
|
|
end
|
|
|
|
end
|
2002-10-22 08:19:26 +04:00
|
|
|
|
1998-01-16 15:19:09 +03:00
|
|
|
# vi:set sw=2:
|