setup.rb in reap-4.3.3 vs setup.rb in reap-4.3.4
- old
+ new
@@ -1,32 +1,59 @@
-#!/usr/bin/env ruby
-
#
# setup.rb
#
# Copyright (c) 2000-2005 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the terms of
# the GNU LGPL, Lesser General Public License version 2.1.
#
-unless Enumerable.method_defined?(:map) # Ruby 1.4.6
- module Enumerable
- alias map collect
- end
-end
+#############################
+# Forked from version 3.2.1 #
+# #
+# -trans #
+#############################
-unless File.respond_to?(:read) # Ruby 1.6
- def File.read(fname)
- open(fname) {|f|
- return f.read
- }
+# CHANGE No longer need to support 1.4.6 or 1.6 versions of Ruby.
+
+# unless Enumerable.method_defined?(:map) # Ruby 1.4.6
+# module Enumerable
+# alias map collect
+# end
+# end
+
+# unless File.respond_to?(:read) # Ruby 1.6
+# def File.read(fname)
+# open(fname) {|f|
+# return f.read
+# }
+# end
+# end
+
+# This is hack!
+# This is needed to install within an abitrary root dir.
+# B/c setup.rb has become spegetti code, I was forced to do this hack.
+# Setup.rb shuld be re-writ. I would use package.rb instead but
+# it lacks hooks and extension compilation. But we'll keep
+# an eye on that one for the future. -trans.
+
+$setup_install_root = nil
+ARGV.each{ |a|
+ if md = /--root=(.*)/.match( a )
+ $setup_install_root = md[1]
end
+}
+if $setup_install_root
+ ARGV.delete("--root=#{$setup_install_root}")
+ $setup_install_root = File.expand_path($setup_install_root)
+ puts "(root=#{$setup_install_root})"
end
-unless Errno.const_defined?(:ENOTEMPTY) # Windows?
+# Windows?
+
+unless Errno.const_defined?(:ENOTEMPTY)
module Errno
class ENOTEMPTY
# We do not raise this exception, implementation is not needed.
end
end
@@ -55,30 +82,21 @@
# options
@install_prefix = nil
@config_opt = nil
@verbose = true
@no_harm = false
- @libsrc_pattern = '*.rb'
end
attr_accessor :install_prefix
attr_accessor :config_opt
- attr_writer :verbose
+ def verbose=(x) @verbose = x end
+ def verbose?() @verbose end
- def verbose?
- @verbose
- end
+ def no_harm=(x) @no_harm = x end
+ def no_harm?() @no_harm end
- attr_writer :no_harm
-
- def no_harm?
- @no_harm
- end
-
- attr_accessor :libsrc_pattern
-
def [](key)
lookup(key).resolve(self)
end
def []=(key, val)
@@ -117,13 +135,11 @@
if File.file?(path)
MetaConfigEnvironment.new(self, inst).instance_eval File.read(path), path
end
end
- def savefile
- '.config'
- end
+ def savefile() '.config' end
def load_savefile
begin
File.foreach(savefile()) do |line|
k, v = *line.split(/=/, 2)
@@ -142,140 +158,140 @@
end
}
end
def load_standard_entries
- standard_entries(@rbconfig).each do |ent|
+ #standard_entries(@rbconfig).each do |ent|
+ standard_entries.each do |ent|
add ent
end
end
- def standard_entries(rbconfig)
- c = rbconfig
+ def standard_entries #(rbconfig)
+ rbconfig = @rbconfig
- rubypath = c['bindir'] + '/' + c['ruby_install_name']
+ rubypath = File.join(rbconfig['bindir'], rbconfig['ruby_install_name'] + rbconfig['EXEEXT'])
- major = c['MAJOR'].to_i
- minor = c['MINOR'].to_i
- teeny = c['TEENY'].to_i
+ major = rbconfig['MAJOR'].to_i
+ minor = rbconfig['MINOR'].to_i
+ teeny = rbconfig['TEENY'].to_i
version = "#{major}.#{minor}"
- # ruby ver. >= 1.4.4?
- newpath_p = ((major >= 2) or
- ((major == 1) and
- ((minor >= 5) or
- ((minor == 4) and (teeny >= 4)))))
+# CHANGE Do not need to support these old versions any more.
- if c['rubylibdir']
+# # ruby ver. >= 1.4.4?
+# newpath_p = ((major >= 2) or
+# ((major == 1) and
+# ((minor >= 5) or
+# ((minor == 4) and (teeny >= 4)))))
+
+ #if c['rubylibdir']
# V > 1.6.3
- libruby = "#{c['prefix']}/lib/ruby"
- librubyver = c['rubylibdir']
- librubyverarch = c['archdir']
- siteruby = c['sitedir']
- siterubyver = c['sitelibdir']
- siterubyverarch = c['sitearchdir']
- elsif newpath_p
- # 1.4.4 <= V <= 1.6.3
- libruby = "#{c['prefix']}/lib/ruby"
- librubyver = "#{c['prefix']}/lib/ruby/#{version}"
- librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
- siteruby = c['sitedir']
- siterubyver = "$siteruby/#{version}"
- siterubyverarch = "$siterubyver/#{c['arch']}"
- else
- # V < 1.4.4
- libruby = "#{c['prefix']}/lib/ruby"
- librubyver = "#{c['prefix']}/lib/ruby/#{version}"
- librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
- siteruby = "#{c['prefix']}/lib/ruby/#{version}/site_ruby"
- siterubyver = siteruby
- siterubyverarch = "$siterubyver/#{c['arch']}"
- end
+
+ root = '/'
+ prefix = rbconfig['prefix']
+
+ libruby = "#{prefix}/lib/ruby"
+ librubyver = rbconfig['rubylibdir']
+ librubyverarch = rbconfig['archdir']
+ siteruby = rbconfig['sitedir']
+ siterubyver = rbconfig['sitelibdir']
+ siterubyverarch = rbconfig['sitearchdir']
+
+ bindir = paramize(rbconfig['bindir'])
+ libdir = paramize(rbconfig['libdir'])
+ datadir = paramize(rbconfig['datadir'])
+ mandir = paramize(rbconfig['mandir'])
+ sysconfdir = paramize(rbconfig['sysconfdir'])
+ localstatedir = paramize(rbconfig['localstatedir'])
+
+# elsif newpath_p
+# # 1.4.4 <= V <= 1.6.3
+# libruby = "#{c['prefix']}/lib/ruby"
+# librubyver = "#{c['prefix']}/lib/ruby/#{version}"
+# librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
+# siteruby = c['sitedir']
+# siterubyver = "$siteruby/#{version}"
+# siterubyverarch = "$siterubyver/#{c['arch']}"
+# else
+# # V < 1.4.4
+# libruby = "#{c['prefix']}/lib/ruby"
+# librubyver = "#{c['prefix']}/lib/ruby/#{version}"
+# librubyverarch = "#{c['prefix']}/lib/ruby/#{version}/#{c['arch']}"
+# siteruby = "#{c['prefix']}/lib/ruby/#{version}/site_ruby"
+# siterubyver = siteruby
+# siterubyverarch = "$siterubyver/#{c['arch']}"
+# end
+
parameterize = lambda {|path|
- path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')
+ path.sub(/\A#{Regexp.quote(rbconfig['prefix'])}/, '$prefix')
}
- if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
+ if arg = rbconfig['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
makeprog = arg.sub(/'/, '').split(/=/, 2)[1]
else
makeprog = 'make'
end
+ installdir_lambda = lambda {|val, table|
+ case val
+ when 'std'
+ table['rbdir'] = '$librubyver'
+ table['sodir'] = '$librubyverarch'
+ when 'site'
+ table['rbdir'] = '$siterubyver'
+ table['sodir'] = '$siterubyverarch'
+ when 'home'
+ setup_rb_error '$HOME was not set' unless ENV['HOME']
+ table['prefix'] = ENV['HOME']
+ table['rbdir'] = '$libdir/ruby'
+ table['sodir'] = '$libdir/ruby'
+ end
+ }
+
[
- ExecItem.new('installdirs', 'std/site/home',
- 'std: install under libruby; site: install under site_ruby; home: install under $HOME')\
- {|val, table|
- case val
- when 'std'
- table['rbdir'] = '$librubyver'
- table['sodir'] = '$librubyverarch'
- when 'site'
- table['rbdir'] = '$siterubyver'
- table['sodir'] = '$siterubyverarch'
- when 'home'
- setup_rb_error '$HOME was not set' unless ENV['HOME']
- table['prefix'] = ENV['HOME']
- table['rbdir'] = '$libdir/ruby'
- table['sodir'] = '$libdir/ruby'
- end
- },
- PathItem.new('prefix', 'path', c['prefix'],
- 'path prefix of target environment'),
- PathItem.new('bindir', 'path', parameterize.call(c['bindir']),
- 'the directory for commands'),
- PathItem.new('libdir', 'path', parameterize.call(c['libdir']),
- 'the directory for libraries'),
- PathItem.new('datadir', 'path', parameterize.call(c['datadir']),
- 'the directory for shared data'),
- PathItem.new('mandir', 'path', parameterize.call(c['mandir']),
- 'the directory for man pages'),
- PathItem.new('sysconfdir', 'path', parameterize.call(c['sysconfdir']),
- 'the directory for system configuration files'),
- PathItem.new('localstatedir', 'path', parameterize.call(c['localstatedir']),
- 'the directory for local state data'),
- PathItem.new('libruby', 'path', libruby,
- 'the directory for ruby libraries'),
- PathItem.new('librubyver', 'path', librubyver,
- 'the directory for standard ruby libraries'),
- PathItem.new('librubyverarch', 'path', librubyverarch,
- 'the directory for standard ruby extensions'),
- PathItem.new('siteruby', 'path', siteruby,
- 'the directory for version-independent aux ruby libraries'),
- PathItem.new('siterubyver', 'path', siterubyver,
- 'the directory for aux ruby libraries'),
- PathItem.new('siterubyverarch', 'path', siterubyverarch,
- 'the directory for aux ruby binaries'),
- PathItem.new('rbdir', 'path', '$siterubyver',
- 'the directory for ruby scripts'),
- PathItem.new('sodir', 'path', '$siterubyverarch',
- 'the directory for ruby extentions'),
- PathItem.new('rubypath', 'path', rubypath,
- 'the path to set to #! line'),
- ProgramItem.new('rubyprog', 'name', rubypath,
- 'the ruby program using for installation'),
- ProgramItem.new('makeprog', 'name', makeprog,
- 'the make program to compile ruby extentions'),
- SelectItem.new('shebang', 'all/ruby/never', 'ruby',
- 'shebang line (#!) editing mode'),
- BoolItem.new('without-ext', 'yes/no', 'no',
- 'does not compile/install ruby extentions')
+ ExecItem.new('installdirs', 'std/site/home', 'install under libruby, site_ruby or $HOME respectively', &installdir_lambda),
+ PathItem.new('root', 'path', root, 'root destination directory'),
+ PathItem.new('prefix', 'path', prefix, 'path prefix of target environment'),
+ PathItem.new('bindir', 'path', bindir, 'the directory for commands'),
+ PathItem.new('libdir', 'path', libdir, 'the directory for libraries'),
+ PathItem.new('datadir', 'path', datadir, 'the directory for shared data'),
+ PathItem.new('mandir', 'path', mandir, 'the directory for man pages'),
+ PathItem.new('sysconfdir', 'path', sysconfdir, 'the directory for system configuration files'),
+ PathItem.new('localstatedir', 'path', localstatedir, 'the directory for local state data'),
+ PathItem.new('libruby', 'path', libruby, 'the directory for ruby libraries'),
+ PathItem.new('librubyver', 'path', librubyver, 'the directory for standard ruby libraries'),
+ PathItem.new('librubyverarch', 'path', librubyverarch, 'the directory for standard ruby extensions'),
+ PathItem.new('siteruby', 'path', siteruby, 'the directory for version-independent aux ruby libraries'),
+ PathItem.new('siterubyver', 'path', siterubyver, 'the directory for aux ruby libraries'),
+ PathItem.new('siterubyverarch', 'path', siterubyverarch, 'the directory for aux ruby binaries'),
+ PathItem.new('rbdir', 'path', '$siterubyver', 'the directory for ruby scripts'),
+ PathItem.new('sodir', 'path', '$siterubyverarch', 'the directory for ruby extentions'),
+ PathItem.new('rubypath', 'path', rubypath, 'the path to set to #! line'),
+ ProgramItem.new('rubyprog', 'name', rubypath, 'the ruby program using for installation'),
+ ProgramItem.new('makeprog', 'name', makeprog, 'the make program to compile ruby extentions'),
+ SelectItem.new('shebang', 'all/ruby/never', 'ruby', 'shebang line (#!) editing mode'),
+ BoolItem.new('without-ext', 'yes/no', 'no', 'does not compile/install ruby extentions')
]
end
private :standard_entries
+ def paramize( path )
+ path.sub(/\A#{Regexp.quote(@rbconfig['prefix'])}/, '$prefix')
+ end
+ private :paramize
+
def load_multipackage_entries
multipackage_entries().each do |ent|
add ent
end
end
def multipackage_entries
[
- PackageSelectionItem.new('with', 'name,name...', '', 'ALL',
- 'package names that you want to install'),
- PackageSelectionItem.new('without', 'name,name...', '', 'NONE',
- 'package names that you do not want to install')
+ PackageSelectionItem.new('with', 'name,name...', '', 'ALL', 'package names that you want to install'),
+ PackageSelectionItem.new('without', 'name,name...', '', 'NONE', 'package names that you do not want to install')
]
end
private :multipackage_entries
ALIASES = {
@@ -336,18 +352,13 @@
def help_opt
"--#{@name}=#{@template}"
end
- def value?
- true
- end
+ def value? ; true ; end
+ def value ; @value ; end
- def value
- @value
- end
-
def resolve(table)
@value.gsub(%r<\$([^/]+)>) { table[$1] }
end
def set(val)
@@ -361,60 +372,52 @@
val
end
end
class BoolItem < Item
- def config_type
- 'bool'
- end
+ def config_type() 'bool' end
def help_opt
"--#{@name}"
end
private
def check(val)
return 'yes' unless val
- unless /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i =~ val
+ case val
+ when /\Ay(es)?\z/i, /\At(rue)?\z/i then 'yes'
+ when /\An(o)?\z/i, /\Af(alse)\z/i then 'no'
+ else
setup_rb_error "config: --#{@name} accepts only yes/no for argument"
end
- (/\Ay(es)?|\At(rue)/i =~ value) ? 'yes' : 'no'
end
end
class PathItem < Item
- def config_type
- 'path'
- end
+ def config_type() 'path' end
private
-
def check(path)
setup_rb_error "config: --#{@name} requires argument" unless path
path[0,1] == '$' ? path : File.expand_path(path)
end
end
class ProgramItem < Item
- def config_type
- 'program'
- end
+ def config_type() 'program' end
end
class SelectItem < Item
def initialize(name, selection, default, desc)
super
@ok = selection.split('/')
end
- def config_type
- 'select'
- end
+ def config_type() 'select' end
private
-
def check(val)
unless @ok.include?(val.strip)
setup_rb_error "config: use --#{@name}=#{@template} (#{val})"
end
val.strip
@@ -472,11 +475,11 @@
val
end
end
class MetaConfigEnvironment
- def intiailize(config, installer)
+ def initialize(config, installer)
@config = config
@installer = installer
end
def config_names
@@ -537,11 +540,13 @@
# This module requires: #verbose?, #no_harm?
module FileOperations
def mkdir_p(dirname, prefix = nil)
- dirname = prefix + File.expand_path(dirname) if prefix
+ dirname = File.join(prefix, File.expand_path(dirname)) if prefix
+ dirname = File.join( $setup_install_root, dirname ) if $setup_install_root
+
$stderr.puts "mkdir -p #{dirname}" if verbose?
return if no_harm?
# Does not check '/', it's too abnormal.
dirs = File.expand_path(dirname).split(%r<(?=/)>)
@@ -621,25 +626,33 @@
File.chmod 0777, path
File.unlink path
end
def install(from, dest, mode, prefix = nil)
+
+ realdest = prefix ? File.join(prefix, File.expand_path(dest)) : dest
+ realdest = File.join($setup_install_root, File.expand_path(realdest)) if $setup_install_root
+
$stderr.puts "install #{from} #{dest}" if verbose?
return if no_harm?
- realdest = prefix ? prefix + File.expand_path(dest) : dest
realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest)
+
str = File.binread(from)
if diff?(str, realdest)
verbose_off {
rm_f realdest if File.exist?(realdest)
}
File.open(realdest, 'wb') {|f|
f.write str
}
File.chmod mode, realdest
+ # Do not make InstalledFiles entry if to alternate root.
+ # This prevents problem with root permissions on this file.
+ return true unless $setup_install_root
+
File.open("#{objdir_root()}/InstalledFiles", 'a') {|f|
if prefix
f.puts realdest.sub(prefix, '')
else
f.puts realdest
@@ -660,11 +673,11 @@
end
def ruby(*args)
command config('rubyprog'), *args
end
-
+
def make(task = nil)
command(*[config('makeprog'), task].compact)
end
def extdir?(dir)
@@ -700,38 +713,19 @@
# obsolete: use metaconfig to change configuration
def set_config(key, val)
@config[key] = val
end
- #
# srcdir/objdir (works only in the package directory)
- #
- def curr_srcdir
- "#{srcdir_root()}/#{relpath()}"
- end
+ def curr_srcdir() "#{srcdir_root()}/#{relpath()}" end
+ def curr_objdir() "#{objdir_root()}/#{relpath()}" end
+ def srcfile(path) "#{curr_srcdir()}/#{path}" end
+ def srcexist?(path) File.exist?(srcfile(path)) end
+ def srcdirectory?(path) File.dir?(srcfile(path)) end
+ def srcfile?(path) File.file?(srcfile(path)) end
- def curr_objdir
- "#{objdir_root()}/#{relpath()}"
- end
-
- def srcfile(path)
- "#{curr_srcdir()}/#{path}"
- end
-
- def srcexist?(path)
- File.exist?(srcfile(path))
- end
-
- def srcdirectory?(path)
- File.dir?(srcfile(path))
- end
-
- def srcfile?(path)
- File.file?(srcfile(path))
- end
-
def srcentries(path = '.')
Dir.open("#{curr_srcdir()}/#{path}") {|d|
return d.to_a - %w(. ..)
}
end
@@ -751,11 +745,11 @@
end
class ToplevelInstaller
- Version = '3.4.0'
+ Version = '3.4.1'
Copyright = 'Copyright (c) 2000-2005 Minero Aoki'
TASKS = [
[ 'all', 'do config, setup, then install' ],
[ 'config', 'saves your configurations' ],
@@ -765,34 +759,35 @@
[ 'test', 'run all tests in test/' ],
[ 'clean', "does `make clean' for each extention" ],
[ 'distclean',"does `make distclean' for each extention" ]
]
- def ToplevelInstaller.invoke
- config = ConfigTable.new(load_rbconfig())
+ def self.invoke
+ config = ConfigTable.new(load_rbconfig)
config.load_standard_entries
config.load_multipackage_entries if multipackage?
config.fixup
klass = (multipackage?() ? ToplevelInstallerMulti : ToplevelInstaller)
klass.new(File.dirname($0), config).invoke
end
- def ToplevelInstaller.multipackage?
+ def self.multipackage?
File.dir?(File.dirname($0) + '/packages')
end
- def ToplevelInstaller.load_rbconfig
+ def self.load_rbconfig
if arg = ARGV.detect {|arg| /\A--rbconfig=/ =~ arg }
ARGV.delete(arg)
load File.expand_path(arg.split(/=/, 2)[1])
$".push 'rbconfig.rb'
else
require 'rbconfig'
end
::Config::CONFIG
end
+
def initialize(ardir_root, config)
@ardir = File.expand_path(ardir_root)
@config = config
# cache
@valid_task_re = nil
@@ -827,11 +822,11 @@
__send__ "parsearg_#{task}"
init_installers
__send__ "exec_#{task}"
end
end
-
+
def run_metaconfigs
@config.load_script "#{@ardir}/metaconfig"
end
def init_installers
@@ -840,22 +835,14 @@
#
# Hook Script API bases
#
- def srcdir_root
- @ardir
- end
+ def srcdir_root() @ardir end
+ def objdir_root() '.' end
+ def relpath() '.' end
- def objdir_root
- '.'
- end
-
- def relpath
- '.'
- end
-
#
# Option Parsing
#
def parsearg_global
@@ -892,10 +879,11 @@
@valid_task_re ||= /\A(?:#{TASKS.map {|task,desc| task }.join('|')})\z/
end
def parsearg_no_options
unless ARGV.empty?
+ task = caller(0).first.slice(%r<`parsearg_(\w+)'>, 1)
setup_rb_error "#{task}: unknown options: #{ARGV.join(' ')}"
end
end
alias parsearg_show parsearg_no_options
@@ -979,10 +967,11 @@
end
out.printf fmt, '--rbconfig=path', 'rbconfig.rb to load',"running ruby's"
out.puts
out.puts 'Options for INSTALL:'
out.printf fmt, '--no-harm', 'only display what to do if given', 'off'
+ out.printf fmt, '--root=path', 'install root directory (effects all paths)', '/'
out.printf fmt, '--prefix=path', 'install path prefix', ''
out.puts
end
#
@@ -1173,26 +1162,20 @@
def inspect
"#<#{self.class} #{File.basename(@srcdir)}>"
end
+ def noop(rel) ; end
+
#
# Hook Script API base methods
#
- def srcdir_root
- @srcdir
- end
+ def srcdir_root() @srcdir end
+ def objdir_root() @objdir end
+ def relpath() @currdir end
- def objdir_root
- @objdir
- end
-
- def relpath
- @currdir
- end
-
#
# Config Access
#
# module FileOperations requires this
@@ -1220,80 +1203,118 @@
def exec_config
exec_task_traverse 'config'
end
- def config_dir_bin(rel)
- end
+ alias config_dir_bin noop
+ alias config_dir_lib noop
- def config_dir_lib(rel)
- end
-
- def config_dir_man(rel)
- end
-
def config_dir_ext(rel)
extconf if extdir?(curr_srcdir())
end
+ alias config_dir_data noop
+ alias config_dir_conf noop
+ alias config_dir_man noop
+
def extconf
ruby "#{curr_srcdir()}/extconf.rb", *@config.config_opt
end
- def config_dir_data(rel)
- end
-
- def config_dir_conf(rel)
- end
-
#
# TASK setup
#
def exec_setup
exec_task_traverse 'setup'
end
def setup_dir_bin(rel)
files_of(curr_srcdir()).each do |fname|
- adjust_shebang "#{curr_srcdir()}/#{fname}"
+ update_shebang_line "#{curr_srcdir()}/#{fname}"
end
end
- def adjust_shebang(path)
+ alias setup_dir_lib noop
+
+ def setup_dir_ext(rel)
+ make if extdir?(curr_srcdir())
+ end
+
+ alias setup_dir_data noop
+ alias setup_dir_conf noop
+ alias setup_dir_man noop
+
+ def update_shebang_line(path)
return if no_harm?
+ return if config('shebang') == 'never'
+ old = Shebang.load(path)
+ if old
+ $stderr.puts "warning: #{path}: Shebang line includes too many args. It is not portable and your program may not work." if old.args.size > 1
+ new = new_shebang(old)
+ return if new.to_s == old.to_s
+ else
+ return unless config('shebang') == 'all'
+ new = Shebang.new(config('rubypath'))
+ end
+ $stderr.puts "updating shebang: #{File.basename(path)}" if verbose?
+ open_atomic_writer(path) {|output|
+ File.open(path, 'rb') {|f|
+ f.gets if old # discard
+ output.puts new.to_s
+ output.print f.read
+ }
+ }
+ end
+
+ def new_shebang(old)
+ if /\Aruby/ =~ File.basename(old.cmd)
+ Shebang.new(config('rubypath'), old.args)
+ elsif File.basename(old.cmd) == 'env' and old.args.first == 'ruby'
+ Shebang.new(config('rubypath'), old.args[1..-1])
+ else
+ return old unless config('shebang') == 'all'
+ Shebang.new(config('rubypath'))
+ end
+ end
+
+ def open_atomic_writer(path, &block)
tmpfile = File.basename(path) + '.tmp'
begin
- File.open(path, 'rb') {|r|
- first = r.gets
- return unless File.basename(first.sub(/\A\#!/, '').split[0].to_s) == 'ruby'
- $stderr.puts "adjusting shebang: #{File.basename(path)}" if verbose?
- File.open(tmpfile, 'wb') {|w|
- w.print first.sub(/\A\#!\s*\S+/, '#! ' + config('rubypath'))
- w.write r.read
- }
- }
- move_file tmpfile, File.basename(path)
+ File.open(tmpfile, 'wb', &block)
+ File.rename tmpfile, File.basename(path)
ensure
File.unlink tmpfile if File.exist?(tmpfile)
end
end
- def setup_dir_lib(rel)
- end
+ class Shebang
+ def Shebang.load(path)
+ line = nil
+ File.open(path) {|f|
+ line = f.gets
+ }
+ return nil unless /\A#!/ =~ line
+ parse(line)
+ end
- def setup_dir_man(rel)
- end
+ def Shebang.parse(line)
+ cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
+ new(cmd, args)
+ end
- def setup_dir_ext(rel)
- make if extdir?(curr_srcdir())
- end
+ def initialize(cmd, args = [])
+ @cmd = cmd
+ @args = args
+ end
- def setup_dir_data(rel)
- end
+ attr_reader :cmd
+ attr_reader :args
- def setup_dir_conf(rel)
+ def to_s
+ "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
+ end
end
#
# TASK install
#
@@ -1306,11 +1327,11 @@
def install_dir_bin(rel)
install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
end
def install_dir_lib(rel)
- install_files rubyscripts(), "#{config('rbdir')}/#{rel}", 0644
+ install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
end
def install_dir_ext(rel)
return unless extdir?(curr_srcdir())
install_files rubyextentions('.'),
@@ -1332,17 +1353,18 @@
install_files targetfiles(), "#{config('mandir')}/#{rel}", 0644
end
def install_files(list, dest, mode)
mkdir_p dest, @config.install_prefix
+ #mkdir_p dest, offset_dir
list.each do |fname|
install fname, dest, mode, @config.install_prefix
end
end
- def rubyscripts
- glob_select(@config.libsrc_pattern, targetfiles())
+ def libfiles
+ glob_reject(%w(*.y *.output), targetfiles())
end
def rubyextentions(dir)
ents = glob_select("*.#{@config.dllext}", targetfiles())
if ents.empty?
@@ -1416,11 +1438,15 @@
unless File.directory?('test')
$stderr.puts 'no test in this package' if verbose?
return
end
$stderr.puts 'Running tests...' if verbose?
- require 'test/unit'
+ begin
+ require 'test/unit'
+ rescue LoadError
+ setup_rb_error 'test/unit cannot loaded. You need Ruby 1.8 or later to invoke this task.'
+ end
runner = Test::Unit::AutoRunner.new(true)
runner.to_run << TESTDIR
runner.run
end
@@ -1432,61 +1458,50 @@
exec_task_traverse 'clean'
rm_f @config.savefile
rm_f 'InstalledFiles'
end
- def clean_dir_bin(rel)
- end
+ alias clean_dir_bin noop
+ alias clean_dir_lib noop
+ alias clean_dir_data noop
+ alias clean_dir_conf noop
+ alias clean_dir_man noop
- def clean_dir_lib(rel)
- end
-
def clean_dir_ext(rel)
return unless extdir?(curr_srcdir())
make 'clean' if File.file?('Makefile')
end
- def clean_dir_data(rel)
- end
-
- def clean_dir_conf(rel)
- end
-
#
# TASK distclean
#
def exec_distclean
exec_task_traverse 'distclean'
rm_f @config.savefile
rm_f 'InstalledFiles'
end
- def distclean_dir_bin(rel)
- end
+ alias distclean_dir_bin noop
+ alias distclean_dir_lib noop
- def distclean_dir_lib(rel)
- end
-
def distclean_dir_ext(rel)
return unless extdir?(curr_srcdir())
make 'distclean' if File.file?('Makefile')
end
- def distclean_dir_data(rel)
- end
+ alias distclean_dir_data noop
+ alias distclean_dir_conf noop
+ alias distclean_dir_man noop
- def distclean_dir_conf(rel)
- end
-
#
- # lib
+ # Traversing
#
def exec_task_traverse(task)
run_hook "pre-#{task}"
FILETYPES.each do |type|
- if config('without-ext') == 'yes' and type == 'ext'
+ if type == 'ext' and config('without-ext') == 'yes'
$stderr.puts 'skipping ext/* by user option' if verbose?
next
end
traverse task, type, "#{task}_dir_#{type}"
end