3 # avoid warnings with -d.
7 srcdir = File.dirname(__FILE__)
8 $:.replace [srcdir+"/lib"] unless defined?(CROSS_COMPILING)
12 mkconfig = File.basename($0)
14 rbconfig_rb = ARGV[0] || 'rbconfig.rb'
15 unless File.directory?(dir = File.dirname(rbconfig_rb))
16 FileUtils.makedirs(dir, :verbose => true)
19 version = RUBY_VERSION
20 def (config = "").write(arg)
25 fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE}
27 # This file was created by #{mkconfig} when ruby was built. Any
28 # changes made to this file will be lost the next time ruby is built.
31 RUBY_VERSION == "#{version}" or
32 raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})"
42 File.foreach "config.status" do |line|
46 when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/
48 val = $3.gsub(/\\(?=,)/, '')
49 when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/
58 when /^"(.+)"\s*(\\)?$/
62 val = continued_line.join("")
67 when /^(?:ac_given_)?INSTALL=(.*)/
68 v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n"
72 next if /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/ =~ name
73 next if /^\$\(ac_\w+\)$/ =~ val
74 next if /^\$\{ac_\w+\}$/ =~ val
75 next if /^\$ac_\w+$/ =~ val
76 next if $install_name and /^RUBY_INSTALL_NAME$/ =~ name
77 next if $so_name and /^RUBY_SO_NAME$/ =~ name
78 if /^program_transform_name$/ =~ name and /^s(\\?.)(.*)\1$/ =~ val
80 sep = %r"#{Regexp.quote($1)}"
81 ptn = $2.sub(/\$\$/, '$').split(sep, 2)
82 name = "ruby_install_name"
83 val = "ruby".sub(/#{ptn[0]}/, ptn[1])
85 val.gsub!(/ +(?!-)/, "=") if name == "configure_args" && /mswin32/ =~ RUBY_PLATFORM
86 val = val.gsub(/\$(?:\$|\{?(\w+)\}?)/) {$1 ? "$(#{$1})" : $&}.dump
88 val = "(TOPDIR || DESTDIR + #{val})"
90 v = " CONFIG[\"#{name}\"] #{vars[name] ? '<< "\n"' : '='} #{val}\n"
97 has_version = true if name == "MAJOR"
102 drive = File::PATH_SEPARATOR == ';'
104 prefix = '/lib/ruby/' + RUBY_VERSION + '/' + RUBY_PLATFORM
105 print " TOPDIR = File.dirname(__FILE__).chomp!(#{prefix.dump})\n"
106 print " DESTDIR = ", (drive ? "TOPDIR && TOPDIR[/\\A[a-z]:/i] || " : ""), "'' unless defined? DESTDIR\n"
107 print " CONFIG = {}\n"
108 print " CONFIG[\"DESTDIR\"] = DESTDIR\n"
111 RUBY_VERSION.scan(/(\d+)\.(\d+)\.(\d+)/) {
112 print " CONFIG[\"MAJOR\"] = \"" + $1 + "\"\n"
113 print " CONFIG[\"MINOR\"] = \"" + $2 + "\"\n"
114 print " CONFIG[\"TEENY\"] = \"" + $3 + "\"\n"
116 patchlevel = IO.foreach(File.join(srcdir, "version.h")) {|l|
117 m = /^\s*#\s*define\s+RUBY_PATCHLEVEL\s+(\d+)/.match(l) and break m[1]
119 print " CONFIG[\"PATCHLEVEL\"] = \"#{patchlevel}\"\n"
122 dest = drive ? /= \"(?!\$[\(\{])(?:[a-z]:)?/i : /= \"(?!\$[\(\{])/
123 v_others.collect! do |x|
124 if /^\s*CONFIG\["(?!abs_|old)[a-z]+(?:_prefix|dir)"\]/ === x
125 x.sub(dest, '= "$(DESTDIR)')
132 v_fast << " CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n"
133 v_fast << " CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n"
136 v_fast << " CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n"
142 CONFIG["ruby_version"] = "$(MAJOR).$(MINOR).$(TEENY)"
143 CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
144 CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
145 CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
146 CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
147 CONFIG["vendorlibdir"] = "$(vendordir)/$(ruby_version)"
148 CONFIG["vendorarchdir"] = "$(vendorlibdir)/$(sitearch)"
149 CONFIG["topdir"] = File.dirname(__FILE__)
151 CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
152 def RbConfig::expand(val, config = CONFIG)
153 val.gsub!(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do
157 elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]]
160 RbConfig::expand(key, config)
162 key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat
170 CONFIG.each_value do |val|
171 RbConfig::expand(val)
174 Config = RbConfig # compatibility for ruby-1.8.4 and older.
175 CROSS_COMPILING = nil unless defined? CROSS_COMPILING
179 mode = IO::RDWR|IO::CREAT
180 mode |= IO::BINARY if defined?(IO::BINARY)
181 open(rbconfig_rb, mode) do |f|
182 if $timestamp and f.stat.size == config.size and f.read == config
183 puts "#{rbconfig_rb} unchanged"
185 puts "#{rbconfig_rb} updated"
191 if String === $timestamp
192 FileUtils.touch($timestamp)