| 1 |
# |
# |
|
# This file is automatically generated. DO NOT MODIFY! |
|
|
# |
|
| 2 |
# setup.rb |
# setup.rb |
| 3 |
# |
# |
| 4 |
# Copyright (c) 2000-2003 Minero Aoki <aamine@loveruby.net> |
# Copyright (c) 2000-2004 Minero Aoki |
| 5 |
# |
# |
| 6 |
# This program is free software. |
# This program is free software. |
| 7 |
# You can distribute/modify this program under the terms of |
# You can distribute/modify this program under the terms of |
| 8 |
# the GNU Lesser General Public License version 2. |
# the GNU Lesser General Public License version 2.1. |
| 9 |
# |
# |
| 10 |
|
|
|
def multipackage_install? |
|
|
FileTest.directory?(File.dirname($0) + '/packages') |
|
|
end |
|
|
|
|
| 11 |
# |
# |
| 12 |
# compat.rb |
# For backward compatibility |
| 13 |
# |
# |
| 14 |
|
|
| 15 |
unless Enumerable.method_defined?(:map) |
unless Enumerable.method_defined?(:map) |
| 18 |
end |
end |
| 19 |
end |
end |
| 20 |
|
|
| 21 |
|
unless Enumerable.method_defined?(:detect) |
| 22 |
|
module Enumerable |
| 23 |
|
alias detect find |
| 24 |
|
end |
| 25 |
|
end |
| 26 |
|
|
| 27 |
unless Enumerable.method_defined?(:select) |
unless Enumerable.method_defined?(:select) |
| 28 |
module Enumerable |
module Enumerable |
| 29 |
alias select find_all |
alias select find_all |
| 66 |
|
|
| 67 |
unless File.respond_to?(:read) |
unless File.respond_to?(:read) |
| 68 |
def File.read(fname) |
def File.read(fname) |
| 69 |
File.open(fname, 'rb') {|f| |
open(fname) {|f| |
| 70 |
return f.read |
return f.read |
| 71 |
} |
} |
| 72 |
end |
end |
| 73 |
end |
end |
| 74 |
|
|
| 75 |
# |
# |
| 76 |
# fileop.rb |
# Application independent utilities |
| 77 |
# |
# |
| 78 |
|
|
| 79 |
module FileOperations |
def File.binread(fname) |
| 80 |
|
open(fname, 'rb') {|f| |
| 81 |
def mkdir_p(dirname, prefix = nil) |
return f.read |
| 82 |
dirname = prefix + dirname if prefix |
} |
|
$stderr.puts "mkdir -p #{dirname}" if verbose? |
|
|
return if no_harm? |
|
|
|
|
|
# does not check '/'... it's too abnormal case |
|
|
dirs = dirname.split(%r<(?=/)>) |
|
|
if /\A[a-z]:\z/i =~ dirs[0] |
|
|
disk = dirs.shift |
|
|
dirs[0] = disk + dirs[0] |
|
|
end |
|
|
dirs.each_index do |idx| |
|
|
path = dirs[0..idx].join('') |
|
|
Dir.mkdir path unless File.dir?(path) |
|
|
end |
|
|
end |
|
|
|
|
|
def rm_f(fname) |
|
|
$stderr.puts "rm -f #{fname}" if verbose? |
|
|
return if no_harm? |
|
|
|
|
|
if File.exist?(fname) or File.symlink?(fname) |
|
|
File.chmod 0777, fname |
|
|
File.unlink fname |
|
|
end |
|
|
end |
|
|
|
|
|
def rm_rf(dn) |
|
|
$stderr.puts "rm -rf #{dn}" if verbose? |
|
|
return if no_harm? |
|
|
|
|
|
Dir.chdir dn |
|
|
Dir.foreach('.') do |fn| |
|
|
next if fn == '.' |
|
|
next if fn == '..' |
|
|
if File.dir?(fn) |
|
|
verbose_off { |
|
|
rm_rf fn |
|
|
} |
|
|
else |
|
|
verbose_off { |
|
|
rm_f fn |
|
|
} |
|
|
end |
|
|
end |
|
|
Dir.chdir '..' |
|
|
Dir.rmdir dn |
|
|
end |
|
|
|
|
|
def move_file(src, dest) |
|
|
File.unlink dest if File.exist?(dest) |
|
|
begin |
|
|
File.rename src, dest |
|
|
rescue |
|
|
File.open(dest, 'wb') {|f| f.write File.read(src) } |
|
|
File.chmod File.stat(src).mode, dest |
|
|
File.unlink src |
|
|
end |
|
|
end |
|
|
|
|
|
def install(from, dest, mode, prefix = nil) |
|
|
$stderr.puts "install #{from} #{dest}" if verbose? |
|
|
return if no_harm? |
|
|
|
|
|
realdest = prefix + dest if prefix |
|
|
realdest += '/' + File.basename(from) if File.dir?(realdest) |
|
|
str = File.read(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 |
|
|
|
|
|
File.open("#{objdir_root()}/InstalledFiles", 'a') {|f| f.puts dest } |
|
|
end |
|
|
end |
|
|
|
|
|
def diff?(orig, targ) |
|
|
return true unless File.exist?(targ) |
|
|
orig != File.read(targ) |
|
|
end |
|
|
|
|
|
def command(str) |
|
|
$stderr.puts str if verbose? |
|
|
system str or raise RuntimeError, "'system #{str}' failed" |
|
|
end |
|
|
|
|
|
def ruby(str) |
|
|
command config('ruby-prog') + ' ' + str |
|
|
end |
|
|
|
|
|
def make(task = '') |
|
|
command config('make-prog') + ' ' + task |
|
|
end |
|
|
|
|
|
def extdir?(dir) |
|
|
File.exist?(dir + '/MANIFEST') |
|
|
end |
|
|
|
|
|
def all_files_in(dirname) |
|
|
Dir.open(dirname) {|d| |
|
|
return d.select {|ent| File.file?("#{dirname}/#{ent}") } |
|
|
} |
|
|
end |
|
|
|
|
|
REJECT_DIRS = %w( |
|
|
CVS SCCS RCS CVS.adm |
|
|
) |
|
|
|
|
|
def all_dirs_in(dirname) |
|
|
Dir.open(dirname) {|d| |
|
|
return d.select {|n| File.dir?("#{dirname}/#{n}") } - %w(. ..) - REJECT_DIRS |
|
|
} |
|
|
end |
|
|
|
|
| 83 |
end |
end |
| 84 |
|
|
| 85 |
|
# for corrupted windows stat(2) |
| 86 |
class File |
def File.dir?(path) |
| 87 |
|
File.directory?((path[-1,1] == '/') ? path : path + '/') |
|
def File.dir?(path) |
|
|
# for corrupted windows stat() |
|
|
File.directory?((path[-1,1] == '/') ? path : path + '/') |
|
|
end |
|
|
|
|
| 88 |
end |
end |
| 89 |
|
|
| 90 |
# |
# |
| 91 |
# config.rb |
# Config |
| 92 |
# |
# |
| 93 |
|
|
| 94 |
if idx = ARGV.index(/\A--rbconfig=/) |
if arg = ARGV.detect{|arg| /\A--rbconfig=/ =~ arg } |
| 95 |
require ARGV.delete_at(idx).split(/=/, 2)[1] |
ARGV.delete(arg) |
| 96 |
|
require arg.split(/=/, 2)[1] |
| 97 |
|
$".push 'rbconfig.rb' |
| 98 |
else |
else |
| 99 |
require 'rbconfig' |
require 'rbconfig' |
| 100 |
end |
end |
| 101 |
|
|
| 102 |
|
def multipackage_install? |
| 103 |
|
FileTest.directory?(File.dirname($0) + '/packages') |
| 104 |
|
end |
| 105 |
|
|
| 106 |
|
|
| 107 |
class ConfigTable |
class ConfigTable |
| 108 |
|
|
| 109 |
c = ::Config::CONFIG |
c = ::Config::CONFIG |
| 145 |
sodir = "$site-ruby/#{c['arch']}" |
sodir = "$site-ruby/#{c['arch']}" |
| 146 |
end |
end |
| 147 |
|
|
| 148 |
|
if arg = c['configure_args'].split.detect {|arg| /--with-make-prog=/ =~ arg } |
| 149 |
|
makeprog = arg.sub(/'/, '').split(/=/, 2)[1] |
| 150 |
|
else |
| 151 |
|
makeprog = 'make' |
| 152 |
|
end |
| 153 |
|
|
| 154 |
common_descripters = [ |
common_descripters = [ |
| 155 |
[ 'prefix', [ c['prefix'], |
[ 'prefix', [ c['prefix'], |
| 156 |
'path', |
'path', |
| 182 |
[ 'ruby-prog', [ rubypath, |
[ 'ruby-prog', [ rubypath, |
| 183 |
'name', |
'name', |
| 184 |
'the ruby program using for installation' ] ], |
'the ruby program using for installation' ] ], |
| 185 |
[ 'make-prog', [ 'make', |
[ 'make-prog', [ makeprog, |
| 186 |
'name', |
'name', |
| 187 |
'the make program to compile ruby extentions' ] ], |
'the make program to compile ruby extentions' ] ], |
| 188 |
[ 'without-ext', [ 'no', |
[ 'without-ext', [ 'no', |
| 373 |
end |
end |
| 374 |
|
|
| 375 |
end |
end |
| 376 |
|
|
| 377 |
# |
# |
| 378 |
# base.rb |
# File Operations |
| 379 |
# |
# |
| 380 |
|
|
| 381 |
require 'rbconfig' |
module FileOperations |
| 382 |
|
|
| 383 |
|
def mkdir_p(dirname, prefix = nil) |
| 384 |
|
dirname = prefix + dirname if prefix |
| 385 |
|
$stderr.puts "mkdir -p #{dirname}" if verbose? |
| 386 |
|
return if no_harm? |
| 387 |
|
|
| 388 |
|
# does not check '/'... it's too abnormal case |
| 389 |
|
dirs = dirname.split(%r<(?=/)>) |
| 390 |
|
if /\A[a-z]:\z/i =~ dirs[0] |
| 391 |
|
disk = dirs.shift |
| 392 |
|
dirs[0] = disk + dirs[0] |
| 393 |
|
end |
| 394 |
|
dirs.each_index do |idx| |
| 395 |
|
path = dirs[0..idx].join('') |
| 396 |
|
Dir.mkdir path unless File.dir?(path) |
| 397 |
|
end |
| 398 |
|
end |
| 399 |
|
|
| 400 |
|
def rm_f(fname) |
| 401 |
|
$stderr.puts "rm -f #{fname}" if verbose? |
| 402 |
|
return if no_harm? |
| 403 |
|
|
| 404 |
|
if File.exist?(fname) or File.symlink?(fname) |
| 405 |
|
File.chmod 0777, fname |
| 406 |
|
File.unlink fname |
| 407 |
|
end |
| 408 |
|
end |
| 409 |
|
|
| 410 |
|
def rm_rf(dn) |
| 411 |
|
$stderr.puts "rm -rf #{dn}" if verbose? |
| 412 |
|
return if no_harm? |
| 413 |
|
|
| 414 |
|
Dir.chdir dn |
| 415 |
|
Dir.foreach('.') do |fn| |
| 416 |
|
next if fn == '.' |
| 417 |
|
next if fn == '..' |
| 418 |
|
if File.dir?(fn) |
| 419 |
|
verbose_off { |
| 420 |
|
rm_rf fn |
| 421 |
|
} |
| 422 |
|
else |
| 423 |
|
verbose_off { |
| 424 |
|
rm_f fn |
| 425 |
|
} |
| 426 |
|
end |
| 427 |
|
end |
| 428 |
|
Dir.chdir '..' |
| 429 |
|
Dir.rmdir dn |
| 430 |
|
end |
| 431 |
|
|
| 432 |
|
def move_file(src, dest) |
| 433 |
|
File.unlink dest if File.exist?(dest) |
| 434 |
|
begin |
| 435 |
|
File.rename src, dest |
| 436 |
|
rescue |
| 437 |
|
File.open(dest, 'wb') {|f| f.write File.binread(src) } |
| 438 |
|
File.chmod File.stat(src).mode, dest |
| 439 |
|
File.unlink src |
| 440 |
|
end |
| 441 |
|
end |
| 442 |
|
|
| 443 |
|
def install(from, dest, mode, prefix = nil) |
| 444 |
|
$stderr.puts "install #{from} #{dest}" if verbose? |
| 445 |
|
return if no_harm? |
| 446 |
|
|
| 447 |
|
realdest = prefix + dest if prefix |
| 448 |
|
realdest = File.join(realdest, File.basename(from)) if File.dir?(realdest) |
| 449 |
|
str = File.binread(from) |
| 450 |
|
if diff?(str, realdest) |
| 451 |
|
verbose_off { |
| 452 |
|
rm_f realdest if File.exist?(realdest) |
| 453 |
|
} |
| 454 |
|
File.open(realdest, 'wb') {|f| |
| 455 |
|
f.write str |
| 456 |
|
} |
| 457 |
|
File.chmod mode, realdest |
| 458 |
|
|
| 459 |
|
File.open("#{objdir_root()}/InstalledFiles", 'a') {|f| |
| 460 |
|
if prefix |
| 461 |
|
f.puts realdest.sub(prefix, '') |
| 462 |
|
else |
| 463 |
|
f.puts realdest |
| 464 |
|
end |
| 465 |
|
} |
| 466 |
|
end |
| 467 |
|
end |
| 468 |
|
|
| 469 |
|
def diff?(new_content, path) |
| 470 |
|
return true unless File.exist?(path) |
| 471 |
|
new_content != File.binread(path) |
| 472 |
|
end |
| 473 |
|
|
| 474 |
|
def command(str) |
| 475 |
|
$stderr.puts str if verbose? |
| 476 |
|
system str or raise RuntimeError, "'system #{str}' failed" |
| 477 |
|
end |
| 478 |
|
|
| 479 |
|
def ruby(str) |
| 480 |
|
command config('ruby-prog') + ' ' + str |
| 481 |
|
end |
| 482 |
|
|
| 483 |
|
def make(task = '') |
| 484 |
|
command config('make-prog') + ' ' + task |
| 485 |
|
end |
| 486 |
|
|
| 487 |
|
def extdir?(dir) |
| 488 |
|
File.exist?(dir + '/MANIFEST') |
| 489 |
|
end |
| 490 |
|
|
| 491 |
|
def all_files_in(dirname) |
| 492 |
|
Dir.open(dirname) {|d| |
| 493 |
|
return d.select {|ent| File.file?("#{dirname}/#{ent}") } |
| 494 |
|
} |
| 495 |
|
end |
| 496 |
|
|
| 497 |
|
REJECT_DIRS = %w( |
| 498 |
|
CVS SCCS RCS CVS.adm |
| 499 |
|
) |
| 500 |
|
|
| 501 |
|
def all_dirs_in(dirname) |
| 502 |
|
Dir.open(dirname) {|d| |
| 503 |
|
return d.select {|n| File.dir?("#{dirname}/#{n}") } - %w(. ..) - REJECT_DIRS |
| 504 |
|
} |
| 505 |
|
end |
| 506 |
|
|
| 507 |
|
end |
| 508 |
|
|
| 509 |
|
# |
| 510 |
|
# Main Installer |
| 511 |
|
# |
| 512 |
|
|
| 513 |
class InstallError < StandardError; end |
class InstallError < StandardError; end |
| 514 |
|
|
| 598 |
end |
end |
| 599 |
|
|
| 600 |
|
|
|
class Installer |
|
|
|
|
|
FILETYPES = %w( bin lib ext data ) |
|
|
|
|
|
include HookScriptAPI |
|
|
include HookUtils |
|
|
include FileOperations |
|
|
|
|
|
def initialize(config, opt, srcroot, objroot) |
|
|
@config = config |
|
|
@options = opt |
|
|
@srcdir = File.expand_path(srcroot) |
|
|
@objdir = File.expand_path(objroot) |
|
|
@currdir = '.' |
|
|
end |
|
|
|
|
|
def inspect |
|
|
"#<#{self.class} #{File.basename(@srcdir)}>" |
|
|
end |
|
|
|
|
|
# |
|
|
# Hook Script API bases |
|
|
# |
|
|
|
|
|
def srcdir_root |
|
|
@srcdir |
|
|
end |
|
|
|
|
|
def objdir_root |
|
|
@objdir |
|
|
end |
|
|
|
|
|
def relpath |
|
|
@currdir |
|
|
end |
|
|
|
|
|
# |
|
|
# configs/options |
|
|
# |
|
|
|
|
|
def no_harm? |
|
|
@options['no-harm'] |
|
|
end |
|
|
|
|
|
def verbose? |
|
|
@options['verbose'] |
|
|
end |
|
|
|
|
|
def verbose_off |
|
|
begin |
|
|
save, @options['verbose'] = @options['verbose'], false |
|
|
yield |
|
|
ensure |
|
|
@options['verbose'] = save |
|
|
end |
|
|
end |
|
|
|
|
|
# |
|
|
# TASK config |
|
|
# |
|
|
|
|
|
def exec_config |
|
|
exec_task_traverse 'config' |
|
|
end |
|
|
|
|
|
def config_dir_bin(rel) |
|
|
end |
|
|
|
|
|
def config_dir_lib(rel) |
|
|
end |
|
|
|
|
|
def config_dir_ext(rel) |
|
|
extconf if extdir?(curr_srcdir()) |
|
|
end |
|
|
|
|
|
def extconf |
|
|
opt = @options['config-opt'].join(' ') |
|
|
command "#{config('ruby-prog')} #{curr_srcdir()}/extconf.rb #{opt}" |
|
|
end |
|
|
|
|
|
def config_dir_data(rel) |
|
|
end |
|
|
|
|
|
# |
|
|
# TASK setup |
|
|
# |
|
|
|
|
|
def exec_setup |
|
|
exec_task_traverse 'setup' |
|
|
end |
|
|
|
|
|
def setup_dir_bin(rel) |
|
|
all_files_in(curr_srcdir()).each do |fname| |
|
|
adjust_shebang "#{curr_srcdir()}/#{fname}" |
|
|
end |
|
|
end |
|
|
|
|
|
# modify: #!/usr/bin/ruby |
|
|
# modify: #! /usr/bin/ruby |
|
|
# modify: #!ruby |
|
|
# not modify: #!/usr/bin/env ruby |
|
|
SHEBANG_RE = /\A\#!\s*\S*ruby\S*/ |
|
|
|
|
|
def adjust_shebang(path) |
|
|
return if no_harm? |
|
|
|
|
|
tmpfile = File.basename(path) + '.tmp' |
|
|
begin |
|
|
File.open(path, 'rb') {|r| |
|
|
File.open(tmpfile, 'wb') {|w| |
|
|
first = r.gets |
|
|
return unless SHEBANG_RE =~ first |
|
|
|
|
|
$stderr.puts "adjusting shebang: #{File.basename path}" if verbose? |
|
|
w.print first.sub(SHEBANG_RE, '#!' + config('ruby-path')) |
|
|
w.write r.read |
|
|
} |
|
|
} |
|
|
move_file tmpfile, File.basename(path) |
|
|
ensure |
|
|
File.unlink tmpfile if File.exist?(tmpfile) |
|
|
end |
|
|
end |
|
|
|
|
|
def setup_dir_lib(rel) |
|
|
end |
|
|
|
|
|
def setup_dir_ext(rel) |
|
|
make if extdir?(curr_srcdir()) |
|
|
end |
|
|
|
|
|
def setup_dir_data(rel) |
|
|
end |
|
|
|
|
|
# |
|
|
# TASK install |
|
|
# |
|
|
|
|
|
def exec_install |
|
|
exec_task_traverse 'install' |
|
|
end |
|
|
|
|
|
def install_dir_bin(rel) |
|
|
install_files collect_filenames_auto(), config('bin-dir') + '/' + rel, 0755 |
|
|
end |
|
|
|
|
|
def install_dir_lib(rel) |
|
|
install_files ruby_scripts(), config('rb-dir') + '/' + rel, 0644 |
|
|
end |
|
|
|
|
|
def install_dir_ext(rel) |
|
|
return unless extdir?(curr_srcdir()) |
|
|
install_files ruby_extentions('.'), |
|
|
config('so-dir') + '/' + File.dirname(rel), |
|
|
0555 |
|
|
end |
|
|
|
|
|
def install_dir_data(rel) |
|
|
install_files collect_filenames_auto(), config('data-dir') + '/' + rel, 0644 |
|
|
end |
|
|
|
|
|
def install_files(list, dest, mode) |
|
|
mkdir_p dest, @options['install-prefix'] |
|
|
list.each do |fname| |
|
|
install fname, dest, mode, @options['install-prefix'] |
|
|
end |
|
|
end |
|
|
|
|
|
def ruby_scripts |
|
|
collect_filenames_auto().select {|n| /\.rb\z/ =~ n } |
|
|
end |
|
|
|
|
|
# picked up many entries from cvs-1.11.1/src/ignore.c |
|
|
reject_patterns = %w( |
|
|
core RCSLOG tags TAGS .make.state |
|
|
.nse_depinfo #* .#* cvslog.* ,* .del-* *.olb |
|
|
*~ *.old *.bak *.BAK *.orig *.rej _$* *$ |
|
|
|
|
|
*.org *.in .* |
|
|
) |
|
|
mapping = { |
|
|
'.' => '\.', |
|
|
'$' => '\$', |
|
|
'#' => '\#', |
|
|
'*' => '.*' |
|
|
} |
|
|
REJECT_PATTERNS = Regexp.new('\A(?:' + |
|
|
reject_patterns.map {|pat| |
|
|
pat.gsub(/[\.\$\#\*]/) {|ch| mapping[ch] } |
|
|
}.join('|') + |
|
|
')\z') |
|
|
|
|
|
def collect_filenames_auto |
|
|
mapdir((existfiles() - hookfiles()).reject {|fname| |
|
|
REJECT_PATTERNS =~ fname |
|
|
}) |
|
|
end |
|
|
|
|
|
def existfiles |
|
|
all_files_in(curr_srcdir()) | all_files_in('.') |
|
|
end |
|
|
|
|
|
def hookfiles |
|
|
%w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt| |
|
|
%w( config setup install clean ).map {|t| sprintf(fmt, t) } |
|
|
}.flatten |
|
|
end |
|
|
|
|
|
def mapdir(filelist) |
|
|
filelist.map {|fname| |
|
|
if File.exist?(fname) # objdir |
|
|
fname |
|
|
else # srcdir |
|
|
File.join(curr_srcdir(), fname) |
|
|
end |
|
|
} |
|
|
end |
|
|
|
|
|
def ruby_extentions(dir) |
|
|
_ruby_extentions(dir) or |
|
|
raise InstallError, "no ruby extention exists: 'ruby #{$0} setup' first" |
|
|
end |
|
|
|
|
|
DLEXT = /\.#{ ::Config::CONFIG['DLEXT'] }\z/ |
|
|
|
|
|
def _ruby_extentions(dir) |
|
|
Dir.open(dir) {|d| |
|
|
return d.select {|fname| DLEXT =~ fname } |
|
|
} |
|
|
end |
|
|
|
|
|
# |
|
|
# TASK clean |
|
|
# |
|
|
|
|
|
def exec_clean |
|
|
exec_task_traverse 'clean' |
|
|
rm_f 'config.save' |
|
|
rm_f 'InstalledFiles' |
|
|
end |
|
|
|
|
|
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 |
|
|
|
|
|
# |
|
|
# TASK distclean |
|
|
# |
|
|
|
|
|
def exec_distclean |
|
|
exec_task_traverse 'distclean' |
|
|
rm_f 'config.save' |
|
|
rm_f 'InstalledFiles' |
|
|
end |
|
|
|
|
|
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 |
|
|
|
|
|
# |
|
|
# lib |
|
|
# |
|
|
|
|
|
def exec_task_traverse(task) |
|
|
run_hook "pre-#{task}" |
|
|
FILETYPES.each do |type| |
|
|
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 |
|
|
run_hook "post-#{task}" |
|
|
end |
|
|
|
|
|
def traverse(task, rel, mid) |
|
|
dive_into(rel) { |
|
|
run_hook "pre-#{task}" |
|
|
__send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '') |
|
|
all_dirs_in(curr_srcdir()).each do |d| |
|
|
traverse task, "#{rel}/#{d}", mid |
|
|
end |
|
|
run_hook "post-#{task}" |
|
|
} |
|
|
end |
|
|
|
|
|
def dive_into(rel) |
|
|
return unless File.dir?("#{@srcdir}/#{rel}") |
|
|
|
|
|
dir = File.basename(rel) |
|
|
Dir.mkdir dir unless File.dir?(dir) |
|
|
prevdir = Dir.pwd |
|
|
Dir.chdir dir |
|
|
$stderr.puts '---> ' + rel if verbose? |
|
|
@currdir = rel |
|
|
yield |
|
|
Dir.chdir prevdir |
|
|
$stderr.puts '<--- ' + rel if verbose? |
|
|
@currdir = File.dirname(rel) |
|
|
end |
|
|
|
|
|
end |
|
|
# |
|
|
# toplevel.rb |
|
|
# |
|
|
|
|
| 601 |
class ToplevelInstaller |
class ToplevelInstaller |
| 602 |
|
|
| 603 |
Version = '3.2.2' |
Version = '3.2.4' |
| 604 |
Copyright = 'Copyright (c) 2000-2003 Minero Aoki' |
Copyright = 'Copyright (c) 2000-2004 Minero Aoki' |
| 605 |
|
|
| 606 |
TASKS = [ |
TASKS = [ |
| 607 |
[ 'config', 'saves your configurations' ], |
[ 'config', 'saves your configurations' ], |
| 993 |
|
|
| 994 |
end |
end |
| 995 |
|
|
| 996 |
|
|
| 997 |
|
class Installer |
| 998 |
|
|
| 999 |
|
FILETYPES = %w( bin lib ext data ) |
| 1000 |
|
|
| 1001 |
|
include HookScriptAPI |
| 1002 |
|
include HookUtils |
| 1003 |
|
include FileOperations |
| 1004 |
|
|
| 1005 |
|
def initialize(config, opt, srcroot, objroot) |
| 1006 |
|
@config = config |
| 1007 |
|
@options = opt |
| 1008 |
|
@srcdir = File.expand_path(srcroot) |
| 1009 |
|
@objdir = File.expand_path(objroot) |
| 1010 |
|
@currdir = '.' |
| 1011 |
|
end |
| 1012 |
|
|
| 1013 |
|
def inspect |
| 1014 |
|
"#<#{self.class} #{File.basename(@srcdir)}>" |
| 1015 |
|
end |
| 1016 |
|
|
| 1017 |
|
# |
| 1018 |
|
# Hook Script API bases |
| 1019 |
|
# |
| 1020 |
|
|
| 1021 |
|
def srcdir_root |
| 1022 |
|
@srcdir |
| 1023 |
|
end |
| 1024 |
|
|
| 1025 |
|
def objdir_root |
| 1026 |
|
@objdir |
| 1027 |
|
end |
| 1028 |
|
|
| 1029 |
|
def relpath |
| 1030 |
|
@currdir |
| 1031 |
|
end |
| 1032 |
|
|
| 1033 |
|
# |
| 1034 |
|
# configs/options |
| 1035 |
|
# |
| 1036 |
|
|
| 1037 |
|
def no_harm? |
| 1038 |
|
@options['no-harm'] |
| 1039 |
|
end |
| 1040 |
|
|
| 1041 |
|
def verbose? |
| 1042 |
|
@options['verbose'] |
| 1043 |
|
end |
| 1044 |
|
|
| 1045 |
|
def verbose_off |
| 1046 |
|
begin |
| 1047 |
|
save, @options['verbose'] = @options['verbose'], false |
| 1048 |
|
yield |
| 1049 |
|
ensure |
| 1050 |
|
@options['verbose'] = save |
| 1051 |
|
end |
| 1052 |
|
end |
| 1053 |
|
|
| 1054 |
|
# |
| 1055 |
|
# TASK config |
| 1056 |
|
# |
| 1057 |
|
|
| 1058 |
|
def exec_config |
| 1059 |
|
exec_task_traverse 'config' |
| 1060 |
|
end |
| 1061 |
|
|
| 1062 |
|
def config_dir_bin(rel) |
| 1063 |
|
end |
| 1064 |
|
|
| 1065 |
|
def config_dir_lib(rel) |
| 1066 |
|
end |
| 1067 |
|
|
| 1068 |
|
def config_dir_ext(rel) |
| 1069 |
|
extconf if extdir?(curr_srcdir()) |
| 1070 |
|
end |
| 1071 |
|
|
| 1072 |
|
def extconf |
| 1073 |
|
opt = @options['config-opt'].join(' ') |
| 1074 |
|
command "#{config('ruby-prog')} #{curr_srcdir()}/extconf.rb #{opt}" |
| 1075 |
|
end |
| 1076 |
|
|
| 1077 |
|
def config_dir_data(rel) |
| 1078 |
|
end |
| 1079 |
|
|
| 1080 |
|
# |
| 1081 |
|
# TASK setup |
| 1082 |
|
# |
| 1083 |
|
|
| 1084 |
|
def exec_setup |
| 1085 |
|
exec_task_traverse 'setup' |
| 1086 |
|
end |
| 1087 |
|
|
| 1088 |
|
def setup_dir_bin(rel) |
| 1089 |
|
all_files_in(curr_srcdir()).each do |fname| |
| 1090 |
|
adjust_shebang "#{curr_srcdir()}/#{fname}" |
| 1091 |
|
end |
| 1092 |
|
end |
| 1093 |
|
|
| 1094 |
|
# modify: #!/usr/bin/ruby |
| 1095 |
|
# modify: #! /usr/bin/ruby |
| 1096 |
|
# modify: #!ruby |
| 1097 |
|
# not modify: #!/usr/bin/env ruby |
| 1098 |
|
SHEBANG_RE = /\A\#!\s*\S*ruby\S*/ |
| 1099 |
|
|
| 1100 |
|
def adjust_shebang(path) |
| 1101 |
|
return if no_harm? |
| 1102 |
|
|
| 1103 |
|
tmpfile = File.basename(path) + '.tmp' |
| 1104 |
|
begin |
| 1105 |
|
File.open(path, 'rb') {|r| |
| 1106 |
|
File.open(tmpfile, 'wb') {|w| |
| 1107 |
|
first = r.gets |
| 1108 |
|
return unless SHEBANG_RE =~ first |
| 1109 |
|
|
| 1110 |
|
$stderr.puts "adjusting shebang: #{File.basename path}" if verbose? |
| 1111 |
|
w.print first.sub(SHEBANG_RE, '#!' + config('ruby-path')) |
| 1112 |
|
w.write r.read |
| 1113 |
|
} |
| 1114 |
|
} |
| 1115 |
|
move_file tmpfile, File.basename(path) |
| 1116 |
|
ensure |
| 1117 |
|
File.unlink tmpfile if File.exist?(tmpfile) |
| 1118 |
|
end |
| 1119 |
|
end |
| 1120 |
|
|
| 1121 |
|
def setup_dir_lib(rel) |
| 1122 |
|
end |
| 1123 |
|
|
| 1124 |
|
def setup_dir_ext(rel) |
| 1125 |
|
make if extdir?(curr_srcdir()) |
| 1126 |
|
end |
| 1127 |
|
|
| 1128 |
|
def setup_dir_data(rel) |
| 1129 |
|
end |
| 1130 |
|
|
| 1131 |
|
# |
| 1132 |
|
# TASK install |
| 1133 |
|
# |
| 1134 |
|
|
| 1135 |
|
def exec_install |
| 1136 |
|
exec_task_traverse 'install' |
| 1137 |
|
end |
| 1138 |
|
|
| 1139 |
|
def install_dir_bin(rel) |
| 1140 |
|
install_files collect_filenames_auto(), "#{config('bin-dir')}/#{rel}", 0755 |
| 1141 |
|
end |
| 1142 |
|
|
| 1143 |
|
def install_dir_lib(rel) |
| 1144 |
|
install_files ruby_scripts(), "#{config('rb-dir')}/#{rel}", 0644 |
| 1145 |
|
end |
| 1146 |
|
|
| 1147 |
|
def install_dir_ext(rel) |
| 1148 |
|
return unless extdir?(curr_srcdir()) |
| 1149 |
|
install_files ruby_extentions('.'), |
| 1150 |
|
"#{config('so-dir')}/#{File.dirname(rel)}", |
| 1151 |
|
0555 |
| 1152 |
|
end |
| 1153 |
|
|
| 1154 |
|
def install_dir_data(rel) |
| 1155 |
|
install_files collect_filenames_auto(), "#{config('data-dir')}/#{rel}", 0644 |
| 1156 |
|
end |
| 1157 |
|
|
| 1158 |
|
def install_files(list, dest, mode) |
| 1159 |
|
mkdir_p dest, @options['install-prefix'] |
| 1160 |
|
list.each do |fname| |
| 1161 |
|
install fname, dest, mode, @options['install-prefix'] |
| 1162 |
|
end |
| 1163 |
|
end |
| 1164 |
|
|
| 1165 |
|
def ruby_scripts |
| 1166 |
|
collect_filenames_auto().select {|n| /\.rb\z/ =~ n } |
| 1167 |
|
end |
| 1168 |
|
|
| 1169 |
|
# picked up many entries from cvs-1.11.1/src/ignore.c |
| 1170 |
|
reject_patterns = %w( |
| 1171 |
|
core RCSLOG tags TAGS .make.state |
| 1172 |
|
.nse_depinfo #* .#* cvslog.* ,* .del-* *.olb |
| 1173 |
|
*~ *.old *.bak *.BAK *.orig *.rej _$* *$ |
| 1174 |
|
|
| 1175 |
|
*.org *.in .* |
| 1176 |
|
) |
| 1177 |
|
mapping = { |
| 1178 |
|
'.' => '\.', |
| 1179 |
|
'$' => '\$', |
| 1180 |
|
'#' => '\#', |
| 1181 |
|
'*' => '.*' |
| 1182 |
|
} |
| 1183 |
|
REJECT_PATTERNS = Regexp.new('\A(?:' + |
| 1184 |
|
reject_patterns.map {|pat| |
| 1185 |
|
pat.gsub(/[\.\$\#\*]/) {|ch| mapping[ch] } |
| 1186 |
|
}.join('|') + |
| 1187 |
|
')\z') |
| 1188 |
|
|
| 1189 |
|
def collect_filenames_auto |
| 1190 |
|
mapdir((existfiles() - hookfiles()).reject {|fname| |
| 1191 |
|
REJECT_PATTERNS =~ fname |
| 1192 |
|
}) |
| 1193 |
|
end |
| 1194 |
|
|
| 1195 |
|
def existfiles |
| 1196 |
|
all_files_in(curr_srcdir()) | all_files_in('.') |
| 1197 |
|
end |
| 1198 |
|
|
| 1199 |
|
def hookfiles |
| 1200 |
|
%w( pre-%s post-%s pre-%s.rb post-%s.rb ).map {|fmt| |
| 1201 |
|
%w( config setup install clean ).map {|t| sprintf(fmt, t) } |
| 1202 |
|
}.flatten |
| 1203 |
|
end |
| 1204 |
|
|
| 1205 |
|
def mapdir(filelist) |
| 1206 |
|
filelist.map {|fname| |
| 1207 |
|
if File.exist?(fname) # objdir |
| 1208 |
|
fname |
| 1209 |
|
else # srcdir |
| 1210 |
|
File.join(curr_srcdir(), fname) |
| 1211 |
|
end |
| 1212 |
|
} |
| 1213 |
|
end |
| 1214 |
|
|
| 1215 |
|
def ruby_extentions(dir) |
| 1216 |
|
_ruby_extentions(dir) or |
| 1217 |
|
raise InstallError, "no ruby extention exists: 'ruby #{$0} setup' first" |
| 1218 |
|
end |
| 1219 |
|
|
| 1220 |
|
DLEXT = /\.#{ ::Config::CONFIG['DLEXT'] }\z/ |
| 1221 |
|
|
| 1222 |
|
def _ruby_extentions(dir) |
| 1223 |
|
Dir.open(dir) {|d| |
| 1224 |
|
return d.select {|fname| DLEXT =~ fname } |
| 1225 |
|
} |
| 1226 |
|
end |
| 1227 |
|
|
| 1228 |
|
# |
| 1229 |
|
# TASK clean |
| 1230 |
|
# |
| 1231 |
|
|
| 1232 |
|
def exec_clean |
| 1233 |
|
exec_task_traverse 'clean' |
| 1234 |
|
rm_f 'config.save' |
| 1235 |
|
rm_f 'InstalledFiles' |
| 1236 |
|
end |
| 1237 |
|
|
| 1238 |
|
def clean_dir_bin(rel) |
| 1239 |
|
end |
| 1240 |
|
|
| 1241 |
|
def clean_dir_lib(rel) |
| 1242 |
|
end |
| 1243 |
|
|
| 1244 |
|
def clean_dir_ext(rel) |
| 1245 |
|
return unless extdir?(curr_srcdir()) |
| 1246 |
|
make 'clean' if File.file?('Makefile') |
| 1247 |
|
end |
| 1248 |
|
|
| 1249 |
|
def clean_dir_data(rel) |
| 1250 |
|
end |
| 1251 |
|
|
| 1252 |
|
# |
| 1253 |
|
# TASK distclean |
| 1254 |
|
# |
| 1255 |
|
|
| 1256 |
|
def exec_distclean |
| 1257 |
|
exec_task_traverse 'distclean' |
| 1258 |
|
rm_f 'config.save' |
| 1259 |
|
rm_f 'InstalledFiles' |
| 1260 |
|
end |
| 1261 |
|
|
| 1262 |
|
def distclean_dir_bin(rel) |
| 1263 |
|
end |
| 1264 |
|
|
| 1265 |
|
def distclean_dir_lib(rel) |
| 1266 |
|
end |
| 1267 |
|
|
| 1268 |
|
def distclean_dir_ext(rel) |
| 1269 |
|
return unless extdir?(curr_srcdir()) |
| 1270 |
|
make 'distclean' if File.file?('Makefile') |
| 1271 |
|
end |
| 1272 |
|
|
| 1273 |
|
# |
| 1274 |
|
# lib |
| 1275 |
|
# |
| 1276 |
|
|
| 1277 |
|
def exec_task_traverse(task) |
| 1278 |
|
run_hook "pre-#{task}" |
| 1279 |
|
FILETYPES.each do |type| |
| 1280 |
|
if config('without-ext') == 'yes' and type == 'ext' |
| 1281 |
|
$stderr.puts 'skipping ext/* by user option' if verbose? |
| 1282 |
|
next |
| 1283 |
|
end |
| 1284 |
|
traverse task, type, "#{task}_dir_#{type}" |
| 1285 |
|
end |
| 1286 |
|
run_hook "post-#{task}" |
| 1287 |
|
end |
| 1288 |
|
|
| 1289 |
|
def traverse(task, rel, mid) |
| 1290 |
|
dive_into(rel) { |
| 1291 |
|
run_hook "pre-#{task}" |
| 1292 |
|
__send__ mid, rel.sub(%r[\A.*?(?:/|\z)], '') |
| 1293 |
|
all_dirs_in(curr_srcdir()).each do |d| |
| 1294 |
|
traverse task, "#{rel}/#{d}", mid |
| 1295 |
|
end |
| 1296 |
|
run_hook "post-#{task}" |
| 1297 |
|
} |
| 1298 |
|
end |
| 1299 |
|
|
| 1300 |
|
def dive_into(rel) |
| 1301 |
|
return unless File.dir?("#{@srcdir}/#{rel}") |
| 1302 |
|
|
| 1303 |
|
dir = File.basename(rel) |
| 1304 |
|
Dir.mkdir dir unless File.dir?(dir) |
| 1305 |
|
prevdir = Dir.pwd |
| 1306 |
|
Dir.chdir dir |
| 1307 |
|
$stderr.puts '---> ' + rel if verbose? |
| 1308 |
|
@currdir = rel |
| 1309 |
|
yield |
| 1310 |
|
Dir.chdir prevdir |
| 1311 |
|
$stderr.puts '<--- ' + rel if verbose? |
| 1312 |
|
@currdir = File.dirname(rel) |
| 1313 |
|
end |
| 1314 |
|
|
| 1315 |
|
end |
| 1316 |
|
|
| 1317 |
|
|
| 1318 |
if $0 == __FILE__ |
if $0 == __FILE__ |
| 1319 |
begin |
begin |
| 1320 |
if multipackage_install? |
if multipackage_install? |