(linenum→info "unix/slp.c:2238")

ruby/1.9.0/mkconfig.rb

    1: #!./miniruby -s
    2: 
    3: # avoid warnings with -d.
    4: $install_name ||= nil
    5: $so_name ||= nil
    6: 
    7: srcdir = File.dirname(__FILE__)
    8: $:.replace [srcdir+"/lib", "."]
    9: 
   10: require "fileutils"
   11: mkconfig = File.basename($0)
   12: 
   13: rbconfig_rb = ARGV[0] || 'rbconfig.rb'
   14: unless File.directory?(dir = File.dirname(rbconfig_rb))
   15:   FileUtils.makedirs(dir, :verbose => true)
   16: end
   17: 
   18: version = RUBY_VERSION
   19: def (config = "").write(arg)
   20:   concat(arg.to_s)
   21: end
   22: $stdout = config
   23: 
   24: fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE}
   25: print %[
   26: # This file was created by #{mkconfig} when ruby was built.  Any
   27: # changes made to this file will be lost the next time ruby is built.
   28: 
   29: module RbConfig
   30:   RUBY_VERSION == "#{version}" or
   31:     raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})"
   32: 
   33: ]
   34: 
   35: v_fast = []
   36: v_others = []
   37: vars = {}
   38: has_version = false
   39: continued_name = nil
   40: continued_line = nil
   41: File.foreach "config.status" do |line|
   42:   next if /^#/ =~ line
   43:   name = nil
   44:   case line
   45:   when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/
   46:     name = $2
   47:     val = $3.gsub(/\\(?=,)/, '')
   48:   when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/
   49:     name = $1
   50:     val = $2
   51:     if $3
   52:       continued_line = []
   53:       continued_line << val
   54:       continued_name = name
   55:       next
   56:     end
   57:   when /^"(.+)"\s*(\\)?$/
   58:     if continued_line
   59:       continued_line <<  $1
   60:       unless $2
   61:         val = continued_line.join("")
   62:         name = continued_name
   63:         continued_line = nil
   64:       end
   65:     end
   66:   when /^(?:ac_given_)?INSTALL=(.*)/
   67:     v_fast << "  CONFIG[\"INSTALL\"] = " + $1 + "\n"
   68:   end
   69: 
   70:   if name
   71:     next if /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/ =~ name
   72:     next if /^\$\(ac_\w+\)$/ =~ val
   73:     next if /^\$\{ac_\w+\}$/ =~ val
   74:     next if /^\$ac_\w+$/ =~ val
   75:     next if $install_name and /^RUBY_INSTALL_NAME$/ =~ name
   76:     next if $so_name and /^RUBY_SO_NAME$/ =~  name
   77:     if /^program_transform_name$/ =~ name and /^s(\\?.)(.*)\1$/ =~ val
   78:       next if $install_name
   79:       sep = %r"#{Regexp.quote($1)}"
   80:       ptn = $2.sub(/\$\$/, '$').split(sep, 2)
   81:       name = "ruby_install_name"
   82:       val = "ruby".sub(/#{ptn[0]}/, ptn[1])
   83:     end
   84:     val.gsub!(/ +(?!-)/, "=") if name == "configure_args" && /mswin32/ =~ RUBY_PLATFORM
   85:     val = val.gsub(/\$(?:\$|\{?(\w+)\}?)/) {$1 ? "$(#{$1})" : $&}.dump
   86:     if /^prefix$/ =~ name
   87:       val = "(TOPDIR || DESTDIR + #{val})"
   88:     end
   89:     v = "  CONFIG[\"#{name}\"] #{vars[name] ? '<< "\n"' : '='} #{val}\n"
   90:     vars[name] = true
   91:     if fast[name]
   92:       v_fast << v
   93:     else
   94:       v_others << v
   95:     end
   96:     has_version = true if name == "MAJOR"
   97:   end
   98: #  break if /^CEOF/
   99: end
  100: 
  101: drive = File::PATH_SEPARATOR == ';'
  102: 
  103: prefix = '/lib/ruby/' + RUBY_VERSION.sub(/\.\d+$/, '') + '/' + RUBY_PLATFORM
  104: print "  TOPDIR = File.dirname(__FILE__).chomp!(#{prefix.dump})\n"
  105: print "  DESTDIR = ", (drive ? "TOPDIR && TOPDIR[/\\A[a-z]:/i] || " : ""), "'' unless defined? DESTDIR\n"
  106: print "  CONFIG = {}\n"
  107: print "  CONFIG[\"DESTDIR\"] = DESTDIR\n"
  108: 
  109: unless has_version
  110:   RUBY_VERSION.scan(/(\d+)\.(\d+)\.(\d+)/) {
  111:     print "  CONFIG[\"MAJOR\"] = \"" + $1 + "\"\n"
  112:     print "  CONFIG[\"MINOR\"] = \"" + $2 + "\"\n"
  113:     print "  CONFIG[\"TEENY\"] = \"" + $3 + "\"\n"
  114:   }
  115:   patchlevel = IO.foreach(File.join(srcdir, "version.h")) {|l|
  116:     m = /^\s*#\s*define\s+RUBY_PATCHLEVEL\s+(\d+)/.match(l) and break m[1]
  117:   }
  118:   print "  CONFIG[\"PATCHLEVEL\"] = \"#{patchlevel}\"\n"
  119: end
  120: 
  121: dest = drive ? /= \"(?!\$[\(\{])(?:[a-z]:)?/i : /= \"(?!\$[\(\{])/
  122: v_others.collect! do |x|
  123:   if /^\s*CONFIG\["(?!abs_|old)[a-z]+(?:_prefix|dir)"\]/ === x
  124:     x.sub(dest, '= "$(DESTDIR)')
  125:   else
  126:     x
  127:   end
  128: end
  129: 
  130: if $install_name
  131:   v_fast << "  CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n"
  132:   v_fast << "  CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n"
  133: end
  134: if $so_name
  135:   v_fast << "  CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n"
  136: end
  137: 
  138: print(*v_fast)
  139: print(*v_others)
  140: print <<EOS
  141:   CONFIG["ruby_version"] = "$(MAJOR).$(MINOR).$(TEENY)"
  142:   CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
  143:   CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
  144:   CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
  145:   CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
  146:   CONFIG["vendorlibdir"] = "$(vendordir)/$(ruby_version)"
  147:   CONFIG["vendorarchdir"] = "$(vendorlibdir)/$(sitearch)"
  148:   CONFIG["topdir"] = File.dirname(__FILE__)
  149:   MAKEFILE_CONFIG = {}
  150:   CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
  151:   def RbConfig::expand(val, config = CONFIG)
  152:     val.gsub!(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do |var|
  153:       if !(v = $1 || $2)
  154:         '$'
  155:       elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]]
  156:         pat, sub = $1, $2
  157:         config[v] = false
  158:         RbConfig::expand(key, config)
  159:         config[v] = key
  160:         key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat
  161:         key
  162:       else
  163:         var
  164:       end
  165:     end
  166:     val
  167:   end
  168:   CONFIG.each_value do |val|
  169:     RbConfig::expand(val)
  170:   end
  171: end
  172: Config = RbConfig # compatibility for ruby-1.8.4 and older.
  173: CROSS_COMPILING = nil unless defined? CROSS_COMPILING
  174: EOS
  175: 
  176: $stdout = STDOUT
  177: mode = IO::RDWR|IO::CREAT
  178: mode |= IO::BINARY if defined?(IO::BINARY)
  179: open(rbconfig_rb, mode) do |f|
  180:   if $timestamp and f.stat.size == config.size and f.read == config
  181:     puts "#{rbconfig_rb} unchanged"
  182:   else
  183:     puts "#{rbconfig_rb} updated"
  184:     f.rewind
  185:     f.truncate(0)
  186:     f.print(config)
  187:   end
  188: end
  189: if String === $timestamp
  190:   FileUtils.touch($timestamp)
  191: end
  192: 
  193: # vi:set sw=2:
Syntax (Markdown)