setup.rb in reap-5.0.0 vs setup.rb in reap-5.10.10
- old
+ new
@@ -1,59 +1,32 @@
+#!/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.
#
-#############################
-# Forked from version 3.2.1 #
-# #
-# -trans #
-#############################
+unless Enumerable.method_defined?(:map) # Ruby 1.4.6
+ module Enumerable
+ alias map collect
+ end
+end
-# 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]
+unless File.respond_to?(:read) # Ruby 1.6
+ def File.read(fname)
+ open(fname) {|f|
+ return f.read
+ }
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
-# Windows?
-
-unless Errno.const_defined?(:ENOTEMPTY)
+unless Errno.const_defined?(:ENOTEMPTY) # Windows?
module Errno
class ENOTEMPTY
# We do not raise this exception, implementation is not needed.
end
end
@@ -82,21 +55,30 @@
# options
@install_prefix = nil
@config_opt = nil
@verbose = true
@no_harm = false
+ @libsrc_pattern = '*.rb'
end
attr_accessor :install_prefix
attr_accessor :config_opt
- def verbose=(x) @verbose = x end
- def verbose?() @verbose end
+ attr_writer :verbose
- def no_harm=(x) @no_harm = x end
- def no_harm?() @no_harm end
+ def verbose?
+ @verbose
+ 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)
@@ -135,11 +117,13 @@
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)
@@ -158,140 +142,140 @@
end
}
end
def load_standard_entries
- #standard_entries(@rbconfig).each do |ent|
- standard_entries.each do |ent|
+ standard_entries(@rbconfig).each do |ent|
add ent
end
end
- def standard_entries #(rbconfig)
- rbconfig = @rbconfig
+ def standard_entries(rbconfig)
+ c = rbconfig
- rubypath = File.join(rbconfig['bindir'], rbconfig['ruby_install_name'] + rbconfig['EXEEXT'])
+ rubypath = c['bindir'] + '/' + c['ruby_install_name']
- major = rbconfig['MAJOR'].to_i
- minor = rbconfig['MINOR'].to_i
- teeny = rbconfig['TEENY'].to_i
+ major = c['MAJOR'].to_i
+ minor = c['MINOR'].to_i
+ teeny = c['TEENY'].to_i
version = "#{major}.#{minor}"
-# CHANGE Do not need to support these old versions any more.
+ # ruby ver. >= 1.4.4?
+ newpath_p = ((major >= 2) or
+ ((major == 1) and
+ ((minor >= 5) or
+ ((minor == 4) and (teeny >= 4)))))
-# # ruby ver. >= 1.4.4?
-# newpath_p = ((major >= 2) or
-# ((major == 1) and
-# ((minor >= 5) or
-# ((minor == 4) and (teeny >= 4)))))
-
- #if c['rubylibdir']
+ if c['rubylibdir']
# V > 1.6.3
-
- 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
-
+ 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
parameterize = lambda {|path|
- path.sub(/\A#{Regexp.quote(rbconfig['prefix'])}/, '$prefix')
+ path.sub(/\A#{Regexp.quote(c['prefix'])}/, '$prefix')
}
- if arg = rbconfig['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg }
+ if arg = c['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', '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')
+ 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')
]
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 = {
@@ -352,13 +336,18 @@
def help_opt
"--#{@name}=#{@template}"
end
- def value? ; true ; end
- def value ; @value ; end
+ def value?
+ true
+ end
+ def value
+ @value
+ end
+
def resolve(table)
@value.gsub(%r<\$([^/]+)>) { table[$1] }
end
def set(val)
@@ -372,52 +361,60 @@
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
- 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
+ unless /\A(y(es)?|n(o)?|t(rue)?|f(alse))\z/i =~ val
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
@@ -475,11 +472,11 @@
val
end
end
class MetaConfigEnvironment
- def initialize(config, installer)
+ def intiailize(config, installer)
@config = config
@installer = installer
end
def config_names
@@ -540,13 +537,11 @@
# This module requires: #verbose?, #no_harm?
module FileOperations
def mkdir_p(dirname, prefix = nil)
- dirname = File.join(prefix, File.expand_path(dirname)) if prefix
- dirname = File.join( $setup_install_root, dirname ) if $setup_install_root
-
+ dirname = prefix + File.expand_path(dirname) if prefix
$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<(?=/)>)
@@ -626,33 +621,25 @@
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
@@ -673,11 +660,11 @@
end
def ruby(*args)
command config('rubyprog'), *args
end
-
+
def make(task = nil)
command(*[config('makeprog'), task].compact)
end
def extdir?(dir)
@@ -713,19 +700,38 @@
# 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_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_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 srcentries(path = '.')
Dir.open("#{curr_srcdir()}/#{path}") {|d|
return d.to_a - %w(. ..)
}
end
@@ -745,11 +751,11 @@
end
class ToplevelInstaller
- Version = '3.4.1'
+ Version = '3.4.0'
Copyright = 'Copyright (c) 2000-2005 Minero Aoki'
TASKS = [
[ 'all', 'do config, setup, then install' ],
[ 'config', 'saves your configurations' ],
@@ -759,35 +765,34 @@
[ 'test', 'run all tests in test/' ],
[ 'clean', "does `make clean' for each extention" ],
[ 'distclean',"does `make distclean' for each extention" ]
]
- def self.invoke
- config = ConfigTable.new(load_rbconfig)
+ def ToplevelInstaller.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 self.multipackage?
+ def ToplevelInstaller.multipackage?
File.dir?(File.dirname($0) + '/packages')
end
- def self.load_rbconfig
+ def ToplevelInstaller.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
@@ -822,11 +827,11 @@
__send__ "parsearg_#{task}"
init_installers
__send__ "exec_#{task}"
end
end
-
+
def run_metaconfigs
@config.load_script "#{@ardir}/metaconfig"
end
def init_installers
@@ -835,14 +840,22 @@
#
# Hook Script API bases
#
- def srcdir_root() @ardir end
- def objdir_root() '.' end
- def relpath() '.' end
+ def srcdir_root
+ @ardir
+ end
+ def objdir_root
+ '.'
+ end
+
+ def relpath
+ '.'
+ end
+
#
# Option Parsing
#
def parsearg_global
@@ -879,11 +892,10 @@
@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
@@ -967,11 +979,10 @@
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
#
@@ -1162,20 +1173,26 @@
def inspect
"#<#{self.class} #{File.basename(@srcdir)}>"
end
- def noop(rel) ; end
-
#
# Hook Script API base methods
#
- def srcdir_root() @srcdir end
- def objdir_root() @objdir end
- def relpath() @currdir end
+ def srcdir_root
+ @srcdir
+ end
+ def objdir_root
+ @objdir
+ end
+
+ def relpath
+ @currdir
+ end
+
#
# Config Access
#
# module FileOperations requires this
@@ -1203,118 +1220,80 @@
def exec_config
exec_task_traverse 'config'
end
- alias config_dir_bin noop
- alias config_dir_lib noop
+ def config_dir_bin(rel)
+ end
+ 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|
- update_shebang_line "#{curr_srcdir()}/#{fname}"
+ adjust_shebang "#{curr_srcdir()}/#{fname}"
end
end
- 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)
+ def adjust_shebang(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(tmpfile, 'wb', &block)
- File.rename tmpfile, File.basename(path)
+ 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)
ensure
File.unlink tmpfile if File.exist?(tmpfile)
end
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_lib(rel)
+ end
- def Shebang.parse(line)
- cmd, *args = *line.strip.sub(/\A\#!/, '').split(' ')
- new(cmd, args)
- end
+ def setup_dir_man(rel)
+ end
- def initialize(cmd, args = [])
- @cmd = cmd
- @args = args
- end
+ def setup_dir_ext(rel)
+ make if extdir?(curr_srcdir())
+ end
- attr_reader :cmd
- attr_reader :args
+ def setup_dir_data(rel)
+ end
- def to_s
- "#! #{@cmd}" + (@args.empty? ? '' : " #{@args.join(' ')}")
- end
+ def setup_dir_conf(rel)
end
#
# TASK install
#
@@ -1327,11 +1306,11 @@
def install_dir_bin(rel)
install_files targetfiles(), "#{config('bindir')}/#{rel}", 0755
end
def install_dir_lib(rel)
- install_files libfiles(), "#{config('rbdir')}/#{rel}", 0644
+ install_files rubyscripts(), "#{config('rbdir')}/#{rel}", 0644
end
def install_dir_ext(rel)
return unless extdir?(curr_srcdir())
install_files rubyextentions('.'),
@@ -1353,18 +1332,17 @@
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 libfiles
- glob_reject(%w(*.y *.output), targetfiles())
+ def rubyscripts
+ glob_select(@config.libsrc_pattern, targetfiles())
end
def rubyextentions(dir)
ents = glob_select("*.#{@config.dllext}", targetfiles())
if ents.empty?
@@ -1438,15 +1416,11 @@
unless File.directory?('test')
$stderr.puts 'no test in this package' if verbose?
return
end
$stderr.puts 'Running tests...' if verbose?
- 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
+ require 'test/unit'
runner = Test::Unit::AutoRunner.new(true)
runner.to_run << TESTDIR
runner.run
end
@@ -1458,50 +1432,61 @@
exec_task_traverse 'clean'
rm_f @config.savefile
rm_f 'InstalledFiles'
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_bin(rel)
+ end
+ 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
- alias distclean_dir_bin noop
- alias distclean_dir_lib noop
+ def distclean_dir_bin(rel)
+ end
+ def distclean_dir_lib(rel)
+ end
+
def distclean_dir_ext(rel)
return unless extdir?(curr_srcdir())
make 'distclean' if File.file?('Makefile')
end
- alias distclean_dir_data noop
- alias distclean_dir_conf noop
- alias distclean_dir_man noop
+ def distclean_dir_data(rel)
+ end
+ def distclean_dir_conf(rel)
+ end
+
#
- # Traversing
+ # lib
#
def exec_task_traverse(task)
run_hook "pre-#{task}"
FILETYPES.each do |type|
- if type == 'ext' and config('without-ext') == 'yes'
+ if config('without-ext') == 'yes' and type == 'ext'
$stderr.puts 'skipping ext/* by user option' if verbose?
next
end
traverse task, type, "#{task}_dir_#{type}"
end