From a654e0b57b861b7ca7d04d640eb9798c40b2fd53 Mon Sep 17 00:00:00 2001 From: yugui Date: Fri, 22 May 2009 11:48:42 +0000 Subject: * instruby.rb: moved into tool/. * mkconfig.rb: ditto. * rubytest.rb: ditto. * runruby.rb: ditto. * common.mk: follows the moves. * configure.in: ditto. * win32/Makefile.sub: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23542 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 16 ++ common.mk | 8 +- configure.in | 2 +- instruby.rb | 540 ----------------------------------------------------- mkconfig.rb | 226 ---------------------- rubytest.rb | 28 --- runruby.rb | 95 ---------- tool/instruby.rb | 540 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tool/mkconfig.rb | 226 ++++++++++++++++++++++ tool/rubytest.rb | 28 +++ tool/runruby.rb | 95 ++++++++++ win32/Makefile.sub | 2 +- 12 files changed, 911 insertions(+), 895 deletions(-) delete mode 100755 instruby.rb delete mode 100755 mkconfig.rb delete mode 100755 rubytest.rb delete mode 100755 runruby.rb create mode 100755 tool/instruby.rb create mode 100755 tool/mkconfig.rb create mode 100755 tool/rubytest.rb create mode 100755 tool/runruby.rb diff --git a/ChangeLog b/ChangeLog index 4a93348140..2a641194a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +Fri May 22 20:10:18 2009 Yuki Sonoda (Yugui) + + * instruby.rb: moved into tool/. + + * mkconfig.rb: ditto. + + * rubytest.rb: ditto. + + * runruby.rb: ditto. + + * common.mk: follows the moves. + + * configure.in: ditto. + + * win32/Makefile.sub: ditto. + Fri May 22 05:09:43 2009 Yukihiro Matsumoto * array.c (rb_ary_slice_bang): avoid call of rb_scan_args() unless diff --git a/common.mk b/common.mk index d4e3ebbd35..37f8d68842 100644 --- a/common.mk +++ b/common.mk @@ -103,7 +103,7 @@ SCRIPT_ARGS = --dest-dir="$(DESTDIR)" \ --make-flags="$(MAKEFLAGS)" EXTMK_ARGS = $(SCRIPT_ARGS) --extension $(EXTS) --extstatic $(EXTSTATIC) \ --make-flags="MINIRUBY='$(MINIRUBY)'" -- -INSTRUBY = $(MINIRUBY) $(srcdir)/instruby.rb +INSTRUBY = $(MINIRUBY) $(srcdir)/tool/instruby.rb INSTRUBY_ARGS = $(SCRIPT_ARGS) \ --data-mode=$(INSTALL_DATA_MODE) \ --prog-mode=$(INSTALL_PROG_MODE) \ @@ -396,7 +396,7 @@ btest-ruby: miniruby$(EXEEXT) $(RBCONFIG) $(PROGRAM) PHONY @$(RUNRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(PROGRAM) -I$(srcdir)/lib" -q $(OPTS) test-sample: miniruby$(EXEEXT) $(RBCONFIG) $(PROGRAM) PHONY - @$(RUNRUBY) $(srcdir)/rubytest.rb + @$(RUNRUBY) $(srcdir)/tool/rubytest.rb test-knownbug: miniruby$(EXEEXT) $(PROGRAM) $(RBCONFIG) PHONY $(MINIRUBY) "$(srcdir)/bootstraptest/runner.rb" --ruby="$(PROGRAM)" $(OPTS) $(srcdir)/KNOWNBUGS.rb @@ -410,8 +410,8 @@ extconf: $(PREP) $(MAKEDIRS) "$(EXTCONFDIR)" $(RUNRUBY) -C "$(EXTCONFDIR)" $(EXTCONF) $(EXTCONFARGS) -$(RBCONFIG): $(srcdir)/mkconfig.rb config.status $(PREP) - @$(MINIRUBY) $(srcdir)/mkconfig.rb -timestamp=$@ \ +$(RBCONFIG): $(srcdir)/tool/mkconfig.rb config.status $(PREP) + @$(MINIRUBY) $(srcdir)/tool/mkconfig.rb -timestamp=$@ \ -install_name=$(RUBY_INSTALL_NAME) \ -so_name=$(RUBY_SO_NAME) rbconfig.rb diff --git a/configure.in b/configure.in index 3680a2d107..baa0930a55 100644 --- a/configure.in +++ b/configure.in @@ -1911,7 +1911,7 @@ else MINIRUBY='./miniruby$(EXEEXT) -I$(srcdir)/lib' MINIRUBY="$MINIRUBY"' -I$(EXTOUT)/common -I./- -r$(srcdir)/ext/purelib.rb' PREP='miniruby$(EXEEXT)' - RUNRUBY='$(MINIRUBY) $(srcdir)/runruby.rb --extout=$(EXTOUT)' + RUNRUBY='$(MINIRUBY) $(srcdir)/tool/runruby.rb --extout=$(EXTOUT)' fi AC_SUBST(MINIRUBY) AC_SUBST(PREP) diff --git a/instruby.rb b/instruby.rb deleted file mode 100755 index 20ce449214..0000000000 --- a/instruby.rb +++ /dev/null @@ -1,540 +0,0 @@ -#!./miniruby - -load "./rbconfig.rb" -include RbConfig -$".unshift File.expand_path("./rbconfig.rb") - -srcdir = File.dirname(__FILE__) -unless defined?(CROSS_COMPILING) and CROSS_COMPILING - $:.replace([File.expand_path("lib", srcdir), Dir.pwd]) -end -require 'fileutils' -require 'shellwords' -require 'optparse' -require 'optparse/shellwords' -require 'tempfile' - -STDOUT.sync = true -File.umask(0) - -def parse_args(argv = ARGV) - $mantype = 'doc' - $destdir = nil - $extout = nil - $make = 'make' - $mflags = [] - $install = [] - $installed_list = nil - $dryrun = false - $rdocdir = nil - $data_mode = 0644 - $prog_mode = 0755 - $dir_mode = nil - $script_mode = nil - $strip = false - $cmdtype = ('bat' if File::ALT_SEPARATOR == '\\') - mflags = [] - opt = OptionParser.new - opt.on('-n') {$dryrun = true} - opt.on('--dest-dir=DIR') {|dir| $destdir = dir} - opt.on('--extout=DIR') {|dir| $extout = (dir unless dir.empty?)} - opt.on('--make=COMMAND') {|make| $make = make} - opt.on('--mantype=MAN') {|man| $mantype = man} - opt.on('--make-flags=FLAGS', '--mflags', Shellwords) do |v| - if arg = v.first - arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg - end - $mflags.concat(v) - end - opt.on('-i', '--install=TYPE', - [:local, :bin, :"bin-arch", :"bin-comm", :lib, :man, :ext, :"ext-arch", :"ext-comm", :rdoc, :capi]) do |ins| - $install << ins - end - opt.on('--data-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode| - $data_mode = mode - end - opt.on('--prog-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode| - $prog_mode = mode - end - opt.on('--dir-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode| - $dir_mode = mode - end - opt.on('--script-mode=OCTAL-MODE', OptionParser::OctalInteger) do |mode| - $script_mode = mode - end - opt.on('--installed-list [FILENAME]') {|name| $installed_list = name} - opt.on('--rdoc-output [DIR]') {|dir| $rdocdir = dir} - opt.on('--cmd-type=TYPE', %w[bat cmd plain]) {|cmd| $cmdtype = (cmd unless cmd == 'plain')} - opt.on('--[no-]strip') {|strip| $strip = strip} - - opt.order!(argv) do |v| - case v - when /\AINSTALL[-_]([-\w]+)=(.*)/ - argv.unshift("--#{$1.tr('_', '-')}=#{$2}") - when /\A\w[-\w+]*=\z/ - mflags << v - when /\A\w[-\w+]*\z/ - $install << v.intern - else - raise OptionParser::InvalidArgument, v - end - end rescue abort [$!.message, opt].join("\n") - - $make, *rest = Shellwords.shellwords($make) - $mflags.unshift(*rest) unless rest.empty? - $mflags.unshift(*mflags) - - def $mflags.set?(flag) - grep(/\A-(?!-).*#{flag.chr}/i) { return true } - false - end - def $mflags.defined?(var) - grep(/\A#{var}=(.*)/) {return block_given? ? yield($1) : $1} - false - end - - if $mflags.set?(?n) - $dryrun = true - else - $mflags << '-n' if $dryrun - end - - $destdir ||= $mflags.defined?("DESTDIR") - if $extout ||= $mflags.defined?("EXTOUT") - RbConfig.expand($extout) - end - - $continue = $mflags.set?(?k) - - if $installed_list ||= $mflags.defined?('INSTALLED_LIST') - RbConfig.expand($installed_list, RbConfig::CONFIG) - $installed_list = open($installed_list, "ab") - $installed_list.sync = true - end - - $rdocdir ||= $mflags.defined?('RDOCOUT') - - $dir_mode ||= $prog_mode | 0700 - $script_mode ||= $prog_mode -end - -parse_args() - -include FileUtils -include FileUtils::NoWrite if $dryrun -@fileutils_output = STDOUT -@fileutils_label = '' - -$install_procs = Hash.new {[]} -def install?(*types, &block) - $install_procs[:all] <<= block - types.each do |type| - $install_procs[type] <<= block - end -end - -def strip_file(file) - if !defined?($strip_command) and (cmd = CONFIG["STRIP"]) - case cmd - when "", "true", ":" then return - else $strip_command = Shellwords.shellwords(cmd) - end - elsif !$strip_command - return - end - system(*($strip_command + [file])) -end - -def install(src, dest, options = {}) - options = options.clone - strip = options.delete(:strip) - options[:preserve] = true - d = with_destdir(dest) - super(src, d, options) - if strip - d = File.join(d, File.basename(src)) if $made_dirs[dest] - strip_file(d) - end - if $installed_list - dest = File.join(dest, File.basename(src)) if $made_dirs[dest] - $installed_list.puts dest - end -end - -def ln_sf(src, dest) - super(src, with_destdir(dest)) - $installed_list.puts dest if $installed_list -end - -$made_dirs = {} -def makedirs(dirs) - dirs = fu_list(dirs) - dirs.collect! do |dir| - realdir = with_destdir(dir) - realdir unless $made_dirs.fetch(dir) do - $made_dirs[dir] = true - $installed_list.puts(File.join(dir, "")) if $installed_list - File.directory?(realdir) - end - end.compact! - super(dirs, :mode => $dir_mode) unless dirs.empty? -end - -FalseProc = proc {false} -def path_matcher(pat) - if pat and !pat.empty? - proc {|f| pat.any? {|n| File.fnmatch?(n, f)}} - else - FalseProc - end -end - -def install_recursive(srcdir, dest, options = {}) - opts = options.clone - noinst = opts.delete(:no_install) - glob = opts.delete(:glob) || "*" - subpath = (srcdir.size+1)..-1 - prune = skip = FalseProc - if noinst - if Array === noinst - prune = noinst.grep(/#{File::SEPARATOR}/o).map!{|f| f.chomp(File::SEPARATOR)} - skip = noinst.grep(/\A[^#{File::SEPARATOR}]*\z/o) - else - if noinst.index(File::SEPARATOR) - prune = [noinst] - else - skip = [noinst] - end - end - skip |= %w"#*# *~ *.old *.bak *.orig *.rej *.diff *.patch *.core" - prune = path_matcher(prune) - skip = path_matcher(skip) - end - File.directory?(srcdir) or return rescue return - paths = [[srcdir, dest, true]] - found = [] - while file = paths.shift - found << file - file, d, dir = *file - if dir - files = [] - Dir.foreach(file) do |f| - src = File.join(file, f) - d = File.join(dest, dir = src[subpath]) - stat = File.lstat(src) rescue next - if stat.directory? - files << [src, d, true] if /\A\./ !~ f and !prune[dir] - else - files << [src, d, false] if File.fnmatch?(glob, f) and !skip[f] - end - end - paths.insert(0, *files) - end - end - for src, d, dir in found - if dir - makedirs(d) - else - makedirs(File.dirname(d)) - install src, d, opts - end - end -end - -def open_for_install(path, mode) - data = open(realpath = with_destdir(path), "rb") {|f| f.read} rescue nil - newdata = yield - unless $dryrun - unless newdata == data - open(realpath, "wb", mode) {|f| f.write newdata} - end - File.chmod(mode, realpath) - end - $installed_list.puts path if $installed_list -end - -def with_destdir(dir) - return dir if !$destdir or $destdir.empty? - dir = dir.sub(/\A\w:/, '') if File::PATH_SEPARATOR == ';' - $destdir + dir -end - -def prepare(mesg, basedir, subdirs=nil) - case - when !subdirs - dirs = basedir - when subdirs.size == 0 - subdirs = nil - when subdirs.size == 1 - dirs = [basedir = File.join(basedir, subdirs)] - subdirs = nil - else - dirs = [basedir, *subdirs.collect {|dir| File.join(basedir, dir)}] - end - printf("installing %-18s %s%s\n", "#{mesg}:", basedir, - (subdirs ? " (#{subdirs.join(', ')})" : "")) - makedirs(dirs) -end - -exeext = CONFIG["EXEEXT"] - -ruby_install_name = CONFIG["ruby_install_name"] -rubyw_install_name = CONFIG["rubyw_install_name"] -goruby_install_name = "go" + ruby_install_name - -version = CONFIG["ruby_version"] -bindir = CONFIG["bindir"] -libdir = CONFIG["libdir"] -archhdrdir = rubyhdrdir = CONFIG["rubyhdrdir"] -archhdrdir += "/" + CONFIG["arch"] -rubylibdir = CONFIG["rubylibdir"] -archlibdir = CONFIG["archdir"] -sitelibdir = CONFIG["sitelibdir"] -sitearchlibdir = CONFIG["sitearchdir"] -vendorlibdir = CONFIG["vendorlibdir"] -vendorarchlibdir = CONFIG["vendorarchdir"] -mandir = CONFIG["mandir"] -capidir = CONFIG["docdir"] -configure_args = Shellwords.shellwords(CONFIG["configure_args"]) -enable_shared = CONFIG["ENABLE_SHARED"] == 'yes' -dll = CONFIG["LIBRUBY_SO"] -lib = CONFIG["LIBRUBY"] -arc = CONFIG["LIBRUBY_A"] - -install?(:local, :arch, :bin, :'bin-arch') do - prepare "binary commands", bindir - - install ruby_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip - if rubyw_install_name and !rubyw_install_name.empty? - install rubyw_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip - end - if File.exist? goruby_install_name+exeext - install goruby_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip - end - if enable_shared and dll != lib - install dll, bindir, :mode => $prog_mode, :strip => $strip - end -end - -install?(:local, :arch, :lib) do - prepare "base libraries", libdir - - install lib, libdir, :mode => $prog_mode, :strip => $strip unless lib == arc - install arc, libdir, :mode => $data_mode - if dll == lib and dll != arc - for link in CONFIG["LIBRUBY_ALIASES"].split - ln_sf(dll, File.join(libdir, link)) - end - end - - prepare "arch files", archlibdir - install "rbconfig.rb", archlibdir, :mode => $data_mode - if CONFIG["ARCHFILE"] - for file in CONFIG["ARCHFILE"].split - install file, archlibdir, :mode => $data_mode - end - end -end - -if $extout - extout = "#$extout" - install?(:ext, :arch, :'ext-arch') do - prepare "extension objects", archlibdir - noinst = %w[-*] | (CONFIG["no_install_files"] || "").split - install_recursive("#{extout}/#{CONFIG['arch']}", archlibdir, :no_install => noinst, :mode => $prog_mode, :strip => $strip) - prepare "extension objects", sitearchlibdir - prepare "extension objects", vendorarchlibdir - end - install?(:ext, :arch, :'ext-arch') do - prepare "extension headers", archhdrdir - install_recursive("#{extout}/include/#{CONFIG['arch']}", archhdrdir, :glob => "*.h", :mode => $data_mode) - end - install?(:ext, :comm, :'ext-comm') do - prepare "extension scripts", rubylibdir - install_recursive("#{extout}/common", rubylibdir, :mode => $data_mode) - prepare "extension scripts", sitelibdir - prepare "extension scripts", vendorlibdir - end - install?(:ext, :comm, :'ext-comm') do - hdrdir = rubyhdrdir + "/ruby" - prepare "extension headers", hdrdir - install_recursive("#{extout}/include/ruby", hdrdir, :glob => "*.h", :mode => $data_mode) - end -end - -install?(:doc, :rdoc) do - if $rdocdir - ridatadir = File.join(CONFIG['datadir'], "ri", CONFIG['ruby_version'], "system") - prepare "rdoc", ridatadir - install_recursive($rdocdir, ridatadir, :mode => $data_mode) - end -end -install?(:doc, :capi) do - prepare "capi-docs", capidir - install_recursive "doc/capi", capidir, :mode => $data_mode -end - -install?(:local, :comm, :bin, :'bin-comm') do - prepare "command scripts", bindir - - ruby_shebang = File.join(bindir, ruby_install_name) - if File::ALT_SEPARATOR - ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR) - end - if trans = CONFIG["program_transform_name"] - exp = [] - trans.gsub!(/\$\$/, '$') - trans.scan(%r[\G[\s;]*(/(?:\\.|[^/])*/)?([sy])(\W)((?:\\.|(?!\3).)*)\3((?:\\.|(?!\3).)*)\3([gi]*)]) do - |addr, cmd, sep, pat, rep, opt| - addr &&= Regexp.new(addr[/\A\/(.*)\/\z/, 1]) - case cmd - when 's' - next if pat == '^' and rep.empty? - exp << [addr, (opt.include?('g') ? :gsub! : :sub!), - Regexp.new(pat, opt.include?('i')), rep] - when 'y' - exp << [addr, :tr!, Regexp.quote(pat), rep] - end - end - trans = proc do |base| - exp.each {|addr, opt, pat, rep| base.__send__(opt, pat, rep) if !addr or addr =~ base} - base - end - elsif /ruby/ =~ ruby_install_name - trans = proc {|base| ruby_install_name.sub(/ruby/, base)} - else - trans = proc {|base| base} - end - for src in Dir[File.join(srcdir, "bin/*")] - next unless File.file?(src) - next if /\/[.#]|(\.(old|bak|orig|rej|diff|patch|core)|~|\/core)$/i =~ src - - name = trans[File.basename(src)] - - shebang = '' - body = '' - open(src, "rb") do |f| - shebang = f.gets - body = f.read - end - shebang.sub!(/^\#!.*?ruby\b/) {"#!" + ruby_shebang} - shebang.sub!(/\r$/, '') - body.gsub!(/\r$/, '') - - cmd = File.join(bindir, name) - cmd << ".#{$cmdtype}" if $cmdtype - open_for_install(cmd, $script_mode) do - case $cmdtype - when "bat" - "#{< noinst, :mode => $data_mode) -end - -install?(:local, :arch, :lib) do - prepare "common headers", rubyhdrdir - - noinst = [] - unless RUBY_PLATFORM =~ /mswin|mingw|bccwin/ - noinst << "win32.h" - end - noinst = nil if noinst.empty? - install_recursive(File.join(srcdir, "include"), rubyhdrdir, :no_install => noinst, :glob => "*.h", :mode => $data_mode) -end - -install?(:local, :comm, :man) do - mdocs = Dir["#{srcdir}/man/*.[1-9]"] - prepare "manpages", mandir, ([] | mdocs.collect {|mdoc| mdoc[/\d+$/]}).sort.collect {|sec| "man#{sec}"} - - mandir = File.join(mandir, "man") - has_goruby = File.exist?(goruby_install_name+exeext) - require File.join(srcdir, "tool/mdoc2man.rb") if $mantype != "doc" - mdocs.each do |mdoc| - next unless File.file?(mdoc) and open(mdoc){|fh| fh.read(1) == '.'} - base = File.basename(mdoc) - if base == "goruby.1" - next unless has_goruby - end - - destdir = mandir + (section = mdoc[/\d+$/]) - destname = ruby_install_name.sub(/ruby/, base.chomp(".#{section}")) - destfile = File.join(destdir, "#{destname}.#{section}") - - if $mantype == "doc" - install mdoc, destfile, :mode => $data_mode - else - w = nil - Tempfile.open(base) do |f| - w = f - open(mdoc) {|r| Mdoc2Man.mdoc2man(r, w)} - end - install w.path, destfile, :mode => $data_mode - w.close! - end - end -end - -install?(:ext, :comm, :gem) do - directories = [] - IO.foreach(File.join(srcdir, "lib/rubygems.rb")) do |line| - if /^\s*DIRECTORIES\s*=\s*%w\[(.*?)\]/ =~ line - directories = $1.split - break - end - end - gpath = CONFIG["sitelibdir"].sub(%r'/site_ruby/(?=[^/]+)', '/gems/') - prepare "default gems", gpath, directories - - destdir = File.join(gpath, directories.grep(/^spec/)[0]) - gems = %w[rake rdoc] - gems.each do |gem| - lib = File.join(srcdir, "lib/#{gem}.rb") - version = open(lib) {|f| f.find {|s| /^\s*\w*VERSION\s*=(?!=)/ =~ s}} or next - version = version.split(%r"=\s*", 2)[1].strip - open_for_install(File.join(destdir, "#{gem}.gemspec"), $data_mode) do |f| - "Gem::Specification.new {|s| s.name, s.version = #{gem.dump}, #{version}}\n" - end - end -end - -$install << :local << :ext if $install.empty? -$install.each do |inst| - if !(procs = $install_procs[inst]) || procs.empty? - next warn("unknown install target - #{inst}") - end - procs.each do |block| - dir = Dir.pwd - begin - block.call - ensure - Dir.chdir(dir) - end - end -end - -# vi:set sw=2: diff --git a/mkconfig.rb b/mkconfig.rb deleted file mode 100755 index 393a1b9ef5..0000000000 --- a/mkconfig.rb +++ /dev/null @@ -1,226 +0,0 @@ -#!./miniruby -s - -# avoid warnings with -d. -$install_name ||= nil -$so_name ||= nil - -srcdir = File.dirname(__FILE__) -$:.replace [srcdir+"/lib"] unless defined?(CROSS_COMPILING) -$:.unshift(".") - -require "fileutils" -mkconfig = File.basename($0) - -rbconfig_rb = ARGV[0] || 'rbconfig.rb' -unless File.directory?(dir = File.dirname(rbconfig_rb)) - FileUtils.makedirs(dir, :verbose => true) -end - -version = RUBY_VERSION -config = "" -def config.write(arg) - concat(arg.to_s) -end -$stdout = config - -fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE} -print %[ -# This file was created by #{mkconfig} when ruby was built. Any -# changes made to this file will be lost the next time ruby is built. - -module RbConfig - RUBY_VERSION == "#{version}" or - raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})" - -] - -arch = RUBY_PLATFORM -v_fast = [] -v_others = [] -vars = {} -continued_name = nil -continued_line = nil -File.foreach "config.status" do |line| - next if /^#/ =~ line - name = nil - case line - when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/ - name = $2 - val = $3.gsub(/\\(?=,)/, '') - when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/ - name = $1 - val = $2 - if $3 - continued_line = [] - continued_line << val - continued_name = name - next - end - when /^"(.*)"\s*(\\)?$/ - if continued_line - continued_line << $1 - next if $2 - val = continued_line.join("") - name = continued_name - continued_line = nil - end - when /^(?:ac_given_)?INSTALL=(.*)/ - v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n" - end - - if name - case name - when /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/; next - when /^(?:X|(?:MINI|RUN)RUBY$)/; next - when /^(?:MAJOR|MINOR|TEENY)$/; next - when /^RUBY_INSTALL_NAME$/; next if $install_name - when /^RUBY_SO_NAME$/; next if $so_name - when /^arch$/; if val.empty? then val = arch else arch = val end - when /^sitearch/; val = '$(arch)' if val.empty? - end - case val - when /^\$\(ac_\w+\)$/; next - when /^\$\{ac_\w+\}$/; next - when /^\$ac_\w+$/; next - end - if /^program_transform_name$/ =~ name - val.sub!(/\As(\W)(?:\^|\$\$)\1\1(;|\z)/, '') - if val.empty? - $install_name ||= "ruby" - next - end - unless $install_name - $install_name = "ruby" - val.gsub!(/\$\$/, '$') - val.scan(%r[\G[\s;]*(/(?:\\.|[^/])*/)?([sy])(\W)((?:\\.|(?!\3).)*)\3((?:\\.|(?!\3).)*)\3([gi]*)]) do - |addr, cmd, sep, pat, rep, opt| - if addr - Regexp.new(addr[/\A\/(.*)\/\z/, 1]) =~ $install_name or next - end - case cmd - when 's' - pat = Regexp.new(pat, opt.include?('i')) - if opt.include?('g') - $install_name.gsub!(pat, rep) - else - $install_name.sub!(pat, rep) - end - when 'y' - $install_name.tr!(Regexp.quote(pat), rep) - end - end - end - end - val.gsub!(/ +(?!-)/, "=") if name == "configure_args" && /mswin32/ =~ RUBY_PLATFORM - val = val.gsub(/\$(?:\$|\{?(\w+)\}?)/) {$1 ? "$(#{$1})" : $&}.dump - if /^prefix$/ =~ name - val = "(TOPDIR || DESTDIR + #{val})" - end - v = " CONFIG[\"#{name}\"] #{vars[name] ? '<< "\n"' : '='} #{val}\n" - vars[name] = true - if fast[name] - v_fast << v - else - v_others << v - end - case name - when "ruby_version" - version = val[/\A"(.*)"\z/, 1] - end - end -# break if /^CEOF/ -end - -drive = File::PATH_SEPARATOR == ';' - -prefix = "/lib/ruby/#{version}/#{arch}" -print " TOPDIR = File.dirname(__FILE__).chomp!(#{prefix.dump})\n" -print " DESTDIR = ", (drive ? "TOPDIR && TOPDIR[/\\A[a-z]:/i] || " : ""), "'' unless defined? DESTDIR\n" -print " CONFIG = {}\n" -print " CONFIG[\"DESTDIR\"] = DESTDIR\n" - -versions = {} -IO.foreach(File.join(srcdir, "version.h")) do |l| - m = /^\s*#\s*define\s+RUBY_(VERSION_(MAJOR|MINOR|TEENY)|PATCHLEVEL)\s+(-?\d+)/.match(l) - if m - versions[m[2]||m[1]] = m[3] - break if versions.size == 4 - end -end -%w[MAJOR MINOR TEENY PATCHLEVEL].each do |v| - print " CONFIG[#{v.dump}] = #{versions[v].dump}\n" -end - -dest = drive ? /= \"(?!\$[\(\{])(?:[a-z]:)?/i : /= \"(?!\$[\(\{])/ -v_others.collect! do |x| - if /^\s*CONFIG\["(?!abs_|old)[a-z]+(?:_prefix|dir)"\]/ === x - x.sub(dest, '= "$(DESTDIR)') - else - x - end -end - -if $install_name - v_fast << " CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n" - v_fast << " CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n" -end -if $so_name - v_fast << " CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n" -end - -print(*v_fast) -print(*v_others) -print < $dir_mode) unless dirs.empty? +end + +FalseProc = proc {false} +def path_matcher(pat) + if pat and !pat.empty? + proc {|f| pat.any? {|n| File.fnmatch?(n, f)}} + else + FalseProc + end +end + +def install_recursive(srcdir, dest, options = {}) + opts = options.clone + noinst = opts.delete(:no_install) + glob = opts.delete(:glob) || "*" + subpath = (srcdir.size+1)..-1 + prune = skip = FalseProc + if noinst + if Array === noinst + prune = noinst.grep(/#{File::SEPARATOR}/o).map!{|f| f.chomp(File::SEPARATOR)} + skip = noinst.grep(/\A[^#{File::SEPARATOR}]*\z/o) + else + if noinst.index(File::SEPARATOR) + prune = [noinst] + else + skip = [noinst] + end + end + skip |= %w"#*# *~ *.old *.bak *.orig *.rej *.diff *.patch *.core" + prune = path_matcher(prune) + skip = path_matcher(skip) + end + File.directory?(srcdir) or return rescue return + paths = [[srcdir, dest, true]] + found = [] + while file = paths.shift + found << file + file, d, dir = *file + if dir + files = [] + Dir.foreach(file) do |f| + src = File.join(file, f) + d = File.join(dest, dir = src[subpath]) + stat = File.lstat(src) rescue next + if stat.directory? + files << [src, d, true] if /\A\./ !~ f and !prune[dir] + else + files << [src, d, false] if File.fnmatch?(glob, f) and !skip[f] + end + end + paths.insert(0, *files) + end + end + for src, d, dir in found + if dir + makedirs(d) + else + makedirs(File.dirname(d)) + install src, d, opts + end + end +end + +def open_for_install(path, mode) + data = open(realpath = with_destdir(path), "rb") {|f| f.read} rescue nil + newdata = yield + unless $dryrun + unless newdata == data + open(realpath, "wb", mode) {|f| f.write newdata} + end + File.chmod(mode, realpath) + end + $installed_list.puts path if $installed_list +end + +def with_destdir(dir) + return dir if !$destdir or $destdir.empty? + dir = dir.sub(/\A\w:/, '') if File::PATH_SEPARATOR == ';' + $destdir + dir +end + +def prepare(mesg, basedir, subdirs=nil) + case + when !subdirs + dirs = basedir + when subdirs.size == 0 + subdirs = nil + when subdirs.size == 1 + dirs = [basedir = File.join(basedir, subdirs)] + subdirs = nil + else + dirs = [basedir, *subdirs.collect {|dir| File.join(basedir, dir)}] + end + printf("installing %-18s %s%s\n", "#{mesg}:", basedir, + (subdirs ? " (#{subdirs.join(', ')})" : "")) + makedirs(dirs) +end + +exeext = CONFIG["EXEEXT"] + +ruby_install_name = CONFIG["ruby_install_name"] +rubyw_install_name = CONFIG["rubyw_install_name"] +goruby_install_name = "go" + ruby_install_name + +version = CONFIG["ruby_version"] +bindir = CONFIG["bindir"] +libdir = CONFIG["libdir"] +archhdrdir = rubyhdrdir = CONFIG["rubyhdrdir"] +archhdrdir += "/" + CONFIG["arch"] +rubylibdir = CONFIG["rubylibdir"] +archlibdir = CONFIG["archdir"] +sitelibdir = CONFIG["sitelibdir"] +sitearchlibdir = CONFIG["sitearchdir"] +vendorlibdir = CONFIG["vendorlibdir"] +vendorarchlibdir = CONFIG["vendorarchdir"] +mandir = CONFIG["mandir"] +capidir = CONFIG["docdir"] +configure_args = Shellwords.shellwords(CONFIG["configure_args"]) +enable_shared = CONFIG["ENABLE_SHARED"] == 'yes' +dll = CONFIG["LIBRUBY_SO"] +lib = CONFIG["LIBRUBY"] +arc = CONFIG["LIBRUBY_A"] + +install?(:local, :arch, :bin, :'bin-arch') do + prepare "binary commands", bindir + + install ruby_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip + if rubyw_install_name and !rubyw_install_name.empty? + install rubyw_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip + end + if File.exist? goruby_install_name+exeext + install goruby_install_name+exeext, bindir, :mode => $prog_mode, :strip => $strip + end + if enable_shared and dll != lib + install dll, bindir, :mode => $prog_mode, :strip => $strip + end +end + +install?(:local, :arch, :lib) do + prepare "base libraries", libdir + + install lib, libdir, :mode => $prog_mode, :strip => $strip unless lib == arc + install arc, libdir, :mode => $data_mode + if dll == lib and dll != arc + for link in CONFIG["LIBRUBY_ALIASES"].split + ln_sf(dll, File.join(libdir, link)) + end + end + + prepare "arch files", archlibdir + install "rbconfig.rb", archlibdir, :mode => $data_mode + if CONFIG["ARCHFILE"] + for file in CONFIG["ARCHFILE"].split + install file, archlibdir, :mode => $data_mode + end + end +end + +if $extout + extout = "#$extout" + install?(:ext, :arch, :'ext-arch') do + prepare "extension objects", archlibdir + noinst = %w[-*] | (CONFIG["no_install_files"] || "").split + install_recursive("#{extout}/#{CONFIG['arch']}", archlibdir, :no_install => noinst, :mode => $prog_mode, :strip => $strip) + prepare "extension objects", sitearchlibdir + prepare "extension objects", vendorarchlibdir + end + install?(:ext, :arch, :'ext-arch') do + prepare "extension headers", archhdrdir + install_recursive("#{extout}/include/#{CONFIG['arch']}", archhdrdir, :glob => "*.h", :mode => $data_mode) + end + install?(:ext, :comm, :'ext-comm') do + prepare "extension scripts", rubylibdir + install_recursive("#{extout}/common", rubylibdir, :mode => $data_mode) + prepare "extension scripts", sitelibdir + prepare "extension scripts", vendorlibdir + end + install?(:ext, :comm, :'ext-comm') do + hdrdir = rubyhdrdir + "/ruby" + prepare "extension headers", hdrdir + install_recursive("#{extout}/include/ruby", hdrdir, :glob => "*.h", :mode => $data_mode) + end +end + +install?(:doc, :rdoc) do + if $rdocdir + ridatadir = File.join(CONFIG['datadir'], "ri", CONFIG['ruby_version'], "system") + prepare "rdoc", ridatadir + install_recursive($rdocdir, ridatadir, :mode => $data_mode) + end +end +install?(:doc, :capi) do + prepare "capi-docs", capidir + install_recursive "doc/capi", capidir, :mode => $data_mode +end + +install?(:local, :comm, :bin, :'bin-comm') do + prepare "command scripts", bindir + + ruby_shebang = File.join(bindir, ruby_install_name) + if File::ALT_SEPARATOR + ruby_bin = ruby_shebang.tr(File::SEPARATOR, File::ALT_SEPARATOR) + end + if trans = CONFIG["program_transform_name"] + exp = [] + trans.gsub!(/\$\$/, '$') + trans.scan(%r[\G[\s;]*(/(?:\\.|[^/])*/)?([sy])(\W)((?:\\.|(?!\3).)*)\3((?:\\.|(?!\3).)*)\3([gi]*)]) do + |addr, cmd, sep, pat, rep, opt| + addr &&= Regexp.new(addr[/\A\/(.*)\/\z/, 1]) + case cmd + when 's' + next if pat == '^' and rep.empty? + exp << [addr, (opt.include?('g') ? :gsub! : :sub!), + Regexp.new(pat, opt.include?('i')), rep] + when 'y' + exp << [addr, :tr!, Regexp.quote(pat), rep] + end + end + trans = proc do |base| + exp.each {|addr, opt, pat, rep| base.__send__(opt, pat, rep) if !addr or addr =~ base} + base + end + elsif /ruby/ =~ ruby_install_name + trans = proc {|base| ruby_install_name.sub(/ruby/, base)} + else + trans = proc {|base| base} + end + for src in Dir[File.join(srcdir, "bin/*")] + next unless File.file?(src) + next if /\/[.#]|(\.(old|bak|orig|rej|diff|patch|core)|~|\/core)$/i =~ src + + name = trans[File.basename(src)] + + shebang = '' + body = '' + open(src, "rb") do |f| + shebang = f.gets + body = f.read + end + shebang.sub!(/^\#!.*?ruby\b/) {"#!" + ruby_shebang} + shebang.sub!(/\r$/, '') + body.gsub!(/\r$/, '') + + cmd = File.join(bindir, name) + cmd << ".#{$cmdtype}" if $cmdtype + open_for_install(cmd, $script_mode) do + case $cmdtype + when "bat" + "#{< noinst, :mode => $data_mode) +end + +install?(:local, :arch, :lib) do + prepare "common headers", rubyhdrdir + + noinst = [] + unless RUBY_PLATFORM =~ /mswin|mingw|bccwin/ + noinst << "win32.h" + end + noinst = nil if noinst.empty? + install_recursive(File.join(srcdir, "include"), rubyhdrdir, :no_install => noinst, :glob => "*.h", :mode => $data_mode) +end + +install?(:local, :comm, :man) do + mdocs = Dir["#{srcdir}/man/*.[1-9]"] + prepare "manpages", mandir, ([] | mdocs.collect {|mdoc| mdoc[/\d+$/]}).sort.collect {|sec| "man#{sec}"} + + mandir = File.join(mandir, "man") + has_goruby = File.exist?(goruby_install_name+exeext) + require File.join(srcdir, "tool/mdoc2man.rb") if $mantype != "doc" + mdocs.each do |mdoc| + next unless File.file?(mdoc) and open(mdoc){|fh| fh.read(1) == '.'} + base = File.basename(mdoc) + if base == "goruby.1" + next unless has_goruby + end + + destdir = mandir + (section = mdoc[/\d+$/]) + destname = ruby_install_name.sub(/ruby/, base.chomp(".#{section}")) + destfile = File.join(destdir, "#{destname}.#{section}") + + if $mantype == "doc" + install mdoc, destfile, :mode => $data_mode + else + w = nil + Tempfile.open(base) do |f| + w = f + open(mdoc) {|r| Mdoc2Man.mdoc2man(r, w)} + end + install w.path, destfile, :mode => $data_mode + w.close! + end + end +end + +install?(:ext, :comm, :gem) do + directories = [] + IO.foreach(File.join(srcdir, "lib/rubygems.rb")) do |line| + if /^\s*DIRECTORIES\s*=\s*%w\[(.*?)\]/ =~ line + directories = $1.split + break + end + end + gpath = CONFIG["sitelibdir"].sub(%r'/site_ruby/(?=[^/]+)', '/gems/') + prepare "default gems", gpath, directories + + destdir = File.join(gpath, directories.grep(/^spec/)[0]) + gems = %w[rake rdoc] + gems.each do |gem| + lib = File.join(srcdir, "lib/#{gem}.rb") + version = open(lib) {|f| f.find {|s| /^\s*\w*VERSION\s*=(?!=)/ =~ s}} or next + version = version.split(%r"=\s*", 2)[1].strip + open_for_install(File.join(destdir, "#{gem}.gemspec"), $data_mode) do |f| + "Gem::Specification.new {|s| s.name, s.version = #{gem.dump}, #{version}}\n" + end + end +end + +$install << :local << :ext if $install.empty? +$install.each do |inst| + if !(procs = $install_procs[inst]) || procs.empty? + next warn("unknown install target - #{inst}") + end + procs.each do |block| + dir = Dir.pwd + begin + block.call + ensure + Dir.chdir(dir) + end + end +end + +# vi:set sw=2: diff --git a/tool/mkconfig.rb b/tool/mkconfig.rb new file mode 100755 index 0000000000..d725fe0929 --- /dev/null +++ b/tool/mkconfig.rb @@ -0,0 +1,226 @@ +#!./miniruby -s + +# avoid warnings with -d. +$install_name ||= nil +$so_name ||= nil + +srcdir = File.expand_path('..', File.dirname(__FILE__)) +$:.replace [srcdir+"/lib"] unless defined?(CROSS_COMPILING) +$:.unshift(".") + +require "fileutils" +mkconfig = File.basename($0) + +rbconfig_rb = ARGV[0] || 'rbconfig.rb' +unless File.directory?(dir = File.dirname(rbconfig_rb)) + FileUtils.makedirs(dir, :verbose => true) +end + +version = RUBY_VERSION +config = "" +def config.write(arg) + concat(arg.to_s) +end +$stdout = config + +fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE} +print %[ +# This file was created by #{mkconfig} when ruby was built. Any +# changes made to this file will be lost the next time ruby is built. + +module RbConfig + RUBY_VERSION == "#{version}" or + raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})" + +] + +arch = RUBY_PLATFORM +v_fast = [] +v_others = [] +vars = {} +continued_name = nil +continued_line = nil +File.foreach "config.status" do |line| + next if /^#/ =~ line + name = nil + case line + when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/ + name = $2 + val = $3.gsub(/\\(?=,)/, '') + when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/ + name = $1 + val = $2 + if $3 + continued_line = [] + continued_line << val + continued_name = name + next + end + when /^"(.*)"\s*(\\)?$/ + if continued_line + continued_line << $1 + next if $2 + val = continued_line.join("") + name = continued_name + continued_line = nil + end + when /^(?:ac_given_)?INSTALL=(.*)/ + v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n" + end + + if name + case name + when /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/; next + when /^(?:X|(?:MINI|RUN)RUBY$)/; next + when /^(?:MAJOR|MINOR|TEENY)$/; next + when /^RUBY_INSTALL_NAME$/; next if $install_name + when /^RUBY_SO_NAME$/; next if $so_name + when /^arch$/; if val.empty? then val = arch else arch = val end + when /^sitearch/; val = '$(arch)' if val.empty? + end + case val + when /^\$\(ac_\w+\)$/; next + when /^\$\{ac_\w+\}$/; next + when /^\$ac_\w+$/; next + end + if /^program_transform_name$/ =~ name + val.sub!(/\As(\W)(?:\^|\$\$)\1\1(;|\z)/, '') + if val.empty? + $install_name ||= "ruby" + next + end + unless $install_name + $install_name = "ruby" + val.gsub!(/\$\$/, '$') + val.scan(%r[\G[\s;]*(/(?:\\.|[^/])*/)?([sy])(\W)((?:\\.|(?!\3).)*)\3((?:\\.|(?!\3).)*)\3([gi]*)]) do + |addr, cmd, sep, pat, rep, opt| + if addr + Regexp.new(addr[/\A\/(.*)\/\z/, 1]) =~ $install_name or next + end + case cmd + when 's' + pat = Regexp.new(pat, opt.include?('i')) + if opt.include?('g') + $install_name.gsub!(pat, rep) + else + $install_name.sub!(pat, rep) + end + when 'y' + $install_name.tr!(Regexp.quote(pat), rep) + end + end + end + end + val.gsub!(/ +(?!-)/, "=") if name == "configure_args" && /mswin32/ =~ RUBY_PLATFORM + val = val.gsub(/\$(?:\$|\{?(\w+)\}?)/) {$1 ? "$(#{$1})" : $&}.dump + if /^prefix$/ =~ name + val = "(TOPDIR || DESTDIR + #{val})" + end + v = " CONFIG[\"#{name}\"] #{vars[name] ? '<< "\n"' : '='} #{val}\n" + vars[name] = true + if fast[name] + v_fast << v + else + v_others << v + end + case name + when "ruby_version" + version = val[/\A"(.*)"\z/, 1] + end + end +# break if /^CEOF/ +end + +drive = File::PATH_SEPARATOR == ';' + +prefix = "/lib/ruby/#{version}/#{arch}" +print " TOPDIR = File.dirname(__FILE__).chomp!(#{prefix.dump})\n" +print " DESTDIR = ", (drive ? "TOPDIR && TOPDIR[/\\A[a-z]:/i] || " : ""), "'' unless defined? DESTDIR\n" +print " CONFIG = {}\n" +print " CONFIG[\"DESTDIR\"] = DESTDIR\n" + +versions = {} +IO.foreach(File.join(srcdir, "version.h")) do |l| + m = /^\s*#\s*define\s+RUBY_(VERSION_(MAJOR|MINOR|TEENY)|PATCHLEVEL)\s+(-?\d+)/.match(l) + if m + versions[m[2]||m[1]] = m[3] + break if versions.size == 4 + end +end +%w[MAJOR MINOR TEENY PATCHLEVEL].each do |v| + print " CONFIG[#{v.dump}] = #{versions[v].dump}\n" +end + +dest = drive ? /= \"(?!\$[\(\{])(?:[a-z]:)?/i : /= \"(?!\$[\(\{])/ +v_others.collect! do |x| + if /^\s*CONFIG\["(?!abs_|old)[a-z]+(?:_prefix|dir)"\]/ === x + x.sub(dest, '= "$(DESTDIR)') + else + x + end +end + +if $install_name + v_fast << " CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n" + v_fast << " CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n" +end +if $so_name + v_fast << " CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n" +end + +print(*v_fast) +print(*v_others) +print <