setup.rb in facets-1.7.0 vs setup.rb in facets-1.7.30

- 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 - -# CHANGE - Needed to install within an abitrary root dir. -# This is hack! B/c setup.rb has become spegetti code, -# I am forced to do this hack. Setup.rb should 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 @@ -87,16 +60,22 @@ 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 + def [](key) lookup(key).resolve(self) end def []=(key, val) @@ -135,11 +114,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 +139,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 = File.join(c['bindir'], c['ruby_install_name'] + c['EXEEXT']) - 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 +333,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,11 +358,13 @@ val end end class BoolItem < Item - def config_type() 'bool' end + def config_type + 'bool' + end def help_opt "--#{@name}" end @@ -392,32 +380,40 @@ end 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 @@ -540,13 +536,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,19 +620,15 @@ 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) } @@ -669,11 +659,11 @@ end def ruby(*args) command config('rubyprog'), *args end - + def make(task = nil) command(*[config('makeprog'), task].compact) end def extdir?(dir) @@ -709,19 +699,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 @@ -755,35 +764,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 @@ -818,11 +826,11 @@ __send__ "parsearg_#{task}" init_installers __send__ "exec_#{task}" end end - + def run_metaconfigs @config.load_script "#{@ardir}/metaconfig" end def init_installers @@ -831,14 +839,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 @@ -963,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 # @@ -1158,20 +1173,29 @@ def inspect "#<#{self.class} #{File.basename(@srcdir)}>" end - def noop(rel) ; 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 @@ -1349,10 +1373,9 @@ 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