mkconfig.rb


DEFINITIONS

This source file includes following functions.


   1  #!./miniruby -s
   2  
   3  require File.dirname($0)+"/lib/ftools"
   4  
   5  rbconfig_rb = ARGV[0] || 'rbconfig.rb'
   6  srcdir = $srcdir if $srcdir
   7  File.makedirs(File.dirname(rbconfig_rb), true)
   8  
   9  version = RUBY_VERSION
  10  rbconfig_rb_tmp = rbconfig_rb + '.tmp'
  11  config = open(rbconfig_rb_tmp, "w")
  12  $orgout = $stdout.dup
  13  $stdout.reopen(config)
  14  
  15  fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE}
  16  print %[
  17  module Config
  18  
  19    RUBY_VERSION == "#{version}" or
  20      raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})"
  21  
  22  # This file was created by configrb when ruby was built. Any changes
  23  # made to this file will be lost the next time ruby is built.
  24  ]
  25  
  26  print "  DESTDIR = '' if not defined? DESTDIR\n  CONFIG = {}\n"
  27  v_fast = []
  28  v_others = []
  29  has_srcdir = false
  30  has_version = false
  31  File.foreach "config.status" do |line|
  32    next if /^#/ =~ line
  33    if /^s[%,]@program_transform_name@[%,]s,(.*)/ =~ line
  34      next if $install_name
  35      ptn = $1.sub(/\$\$/, '$').split(/,/)        #'
  36      v_fast << "  CONFIG[\"ruby_install_name\"] = \"" + "ruby".sub(/#{ptn[0]}/,ptn[1]) + "\"\n"
  37    elsif /^s[%,]@(\w+)@[%,](.*)[%,]/ =~ line
  38      name = $1
  39      val = $2 || ""
  40      next if /^(INSTALL|DEFS|configure_input|srcdir|top_srcdir)$/ =~ name
  41      next if $install_name and /^RUBY_INSTALL_NAME$/ =~ name
  42      next if $so_name and /^RUBY_SO_NAME$/ =~  name
  43      v = "  CONFIG[\"" + name + "\"] = " +
  44        val.strip.gsub(/\$\{?(\w+)\}?/) {"$(#{$1})"}.dump + "\n"
  45      if fast[name]
  46        v_fast << v
  47      else
  48        v_others << v
  49      end
  50      has_version = true if name == "MAJOR"
  51    elsif /^(?:ac_given_)?srcdir=(.*)/ =~ line
  52      v_fast << "  CONFIG[\"srcdir\"] = \"" + File.expand_path($1) + "\"\n"
  53      has_srcdir = true
  54    elsif /^ac_given_INSTALL=(.*)/ =~ line
  55      v_fast << "  CONFIG[\"INSTALL\"] = " + $1 + "\n"
  56    end
  57  #  break if /^CEOF/
  58  end
  59  
  60  if not has_srcdir
  61    v_fast << "  CONFIG[\"srcdir\"] = \"" + File.expand_path(srcdir || '.') + "\"\n"
  62  end
  63  
  64  if not has_version
  65    RUBY_VERSION.scan(/(\d+)\.(\d+)\.(\d+)/) {
  66      print "  CONFIG[\"MAJOR\"] = \"" + $1 + "\"\n"
  67      print "  CONFIG[\"MINOR\"] = \"" + $2 + "\"\n"
  68      print "  CONFIG[\"TEENY\"] = \"" + $3 + "\"\n"
  69    }
  70  end
  71  
  72  v_fast.collect! do |x|
  73    if /"prefix"/ === x
  74      prefix = Regexp.quote('/lib/ruby/' + RUBY_VERSION.sub(/\.\d+$/, '') + '/' + RUBY_PLATFORM)
  75      puts "  TOPDIR = File.dirname(__FILE__).sub!(%r'#{prefix}\\Z', '')"
  76      x.sub(/= (.*)/, '= (TOPDIR || DESTDIR + \1)')
  77    else
  78      x
  79    end
  80  end
  81  
  82  if $install_name
  83    v_fast << "  CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n"
  84    v_fast << "  CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n"
  85  end
  86  if $so_name
  87    v_fast << "  CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n"
  88  end
  89  
  90  print v_fast, v_others
  91  print <<EOS
  92    CONFIG["ruby_version"] = "$(MAJOR).$(MINOR)"
  93    CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
  94    CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
  95    CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
  96    CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
  97    CONFIG["compile_dir"] = "#{Dir.pwd}"
  98    MAKEFILE_CONFIG = {}
  99    CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
 100    def Config::expand(val)
 101      val.gsub!(/\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do |var|
 102        if key = CONFIG[$1 || $2]
 103          Config::expand(key)
 104        else
 105          var
 106        end
 107      end
 108      val
 109    end
 110    CONFIG.each_value do |val|
 111      Config::expand(val)
 112    end
 113  end
 114  EOS
 115  $stdout.flush
 116  $stdout.reopen($orgout)
 117  config.close
 118  File.rename(rbconfig_rb_tmp, rbconfig_rb)
 119  
 120  # vi:set sw=2: