summaryrefslogtreecommitdiff
path: root/instruby.rb
diff options
context:
space:
mode:
Diffstat (limited to 'instruby.rb')
-rw-r--r--instruby.rb64
1 files changed, 49 insertions, 15 deletions
diff --git a/instruby.rb b/instruby.rb
index f56bb2e..98d2714 100644
--- a/instruby.rb
+++ b/instruby.rb
@@ -7,27 +7,32 @@ srcdir = File.dirname(__FILE__)
$:.unshift File.join(srcdir, "lib")
require 'fileutils'
require 'shellwords'
-require 'getopts'
+require 'optparse'
+require 'optparse/shellwords'
require 'tempfile'
+STDOUT.sync = true
File.umask(0)
def parse_args()
- getopts('n', 'dest-dir:',
- 'make:', 'make-flags:', 'mflags:',
- 'mantype:doc')
-
- $dryrun = $OPT['n']
- $destdir = $OPT['dest-dir'] || ''
- $make = $OPT['make'] || $make || 'make'
- $mantype = $OPT['mantype']
- mflags = ($OPT['make-flags'] || '').strip
- mflags = ($OPT['mflags'] || '').strip if mflags.empty?
-
- $mflags = Shellwords.shellwords(mflags)
- if arg = $mflags.first
- arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
+ $mantype = 'doc'
+ $destdir = nil
+ $make = 'make'
+ $mflags = []
+ $install = []
+ 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)
end
+ opt.on('--install=TYPE', [:bin, :lib, :man]) {|ins| $install << ins}
+ opt.parse! rescue abort [$!.message, opt].join("\n")
$make, *rest = Shellwords.shellwords($make)
$mflags.unshift(*rest) unless rest.empty?
@@ -55,6 +60,10 @@ include FileUtils::NoWrite if $dryrun
@fileutils_output = STDOUT
@fileutils_label = ''
+def install?(type)
+ yield if $install.empty? or $install.include?(type)
+end
+
def install(src, dest, options = {})
options[:preserve] = true
super
@@ -99,11 +108,29 @@ arc = CONFIG["LIBRUBY_A"]
makedirs [bindir, libdir, rubylibdir, archlibdir, sitelibdir, sitearchlibdir]
+install?(:bin) do
ruby_bin = File.join(bindir, ruby_install_name)
+major = CONFIG["MAJOR"]
+minor = CONFIG["MINOR"]
+teeny = CONFIG["TEENY"]
+os = CONFIG["target_os"]
+suffixes = %W[#{major}#{minor} #{major}#{minor}#{teeny}
+#{major}#{minor}-#{os} #{major}#{minor}#{teeny}-#{os}
+-#{major}.#{minor} -#{major}.#{minor}.#{teeny}
+]
+def suffixes.link(bin)
+ each do |suf|
+ ln(bin+exeext, bin+suf+exeext, force: true)
+ end
+rescue NotImplementedError
+end
+
install ruby_install_name+exeext, ruby_bin+exeext, :mode => 0755
+suffixes.link(ruby_bin)
if rubyw_install_name and !rubyw_install_name.empty?
install rubyw_install_name+exeext, bindir, :mode => 0755
+ suffixes.link(File.join(bindir, rubyw_install_name))
end
install dll, bindir, :mode => 0755 if enable_shared and dll != lib
install lib, libdir, :mode => 0755 unless lib == arc
@@ -121,9 +148,11 @@ if dll == lib and dll != arc
ln_sf(dll, File.join(libdir, link))
end
end
+end
Dir.chdir srcdir
+install?(:lib) do
ruby_shebang = File.join(CONFIG["bindir"], ruby_install_name)
if File::ALT_SEPARATOR
ruby_bin_dosish = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR)
@@ -176,7 +205,9 @@ for f in Dir["lib/**/*{.rb,help-message}"]
makedirs dir
install f, dir, :mode => 0644
end
+end
+install?(:bin) do
for f in Dir["*.h"]
install f, archlibdir, :mode => 0644
end
@@ -185,7 +216,9 @@ if RUBY_PLATFORM =~ /mswin32|mingw|bccwin32/
makedirs File.join(archlibdir, "win32")
install "win32/win32.h", File.join(archlibdir, "win32"), :mode => 0644
end
+end
+install?(:man) do
for mdoc in Dir["*.[1-9]"]
next unless File.file?(mdoc) and open(mdoc){|fh| fh.read(1) == '.'}
@@ -212,5 +245,6 @@ for mdoc in Dir["*.[1-9]"]
install w.path, destfile, :mode => 0644
end
end
+end
# vi:set sw=2: