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
26 fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE}
28 # This file was created by #{mkconfig} when ruby was built. Any
29 # changes made to this file will be lost the next time ruby is built.
32 RUBY_VERSION == "#{version}" or
33 raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})"
43 File.foreach "config.status" do |line|
47 when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/
49 val = $3.gsub(/\\(?=,)/, '')
50 when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/
59 when /^"(.+)"\s*(\\)?$/
63 val = continued_line.join("")
68 when /^(?:ac_given_)?INSTALL=(.*)/
69 v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n"
73 next if /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/ =~ name
74 next if /^\$\(ac_\w+\)$/ =~ val
75 next if /^\$\{ac_\w+\}$/ =~ val
76 next if /^\$ac_\w+$/ =~ val
77 next if $install_name and /^RUBY_INSTALL_NAME$/ =~ name
78 next if $so_name and /^RUBY_SO_NAME$/ =~ name
79 next if /^(?:X|(?:MINI|RUN)RUBY$)/ =~ name
80 if /^program_transform_name$/ =~ name and /^s(\\?.)(.*)\1$/ =~ val
82 sep = %r"#{Regexp.quote($1)}"
83 ptn = $2.sub(/\$\$/, '$').split(sep, 2)
84 name = "ruby_install_name"
85 val = "ruby".sub(/#{ptn[0]}/, ptn[1])
87 val.gsub!(/ +(?!-)/, "=") if name == "configure_args" && /mswin32/ =~ RUBY_PLATFORM
88 val = val.gsub(/\$(?:\$|\{?(\w+)\}?)/) {$1 ? "$(#{$1})" : $&}.dump
90 val = "(TOPDIR || DESTDIR + #{val})"
92 v = " CONFIG[\"#{name}\"] #{vars[name] ? '<< "\n"' : '='} #{val}\n"
99 has_version = true if name == "MAJOR"
104 drive = File::PATH_SEPARATOR == ';'
106 prefix = '/lib/ruby/' + RUBY_VERSION + '/' + RUBY_PLATFORM
107 print " TOPDIR = File.dirname(__FILE__).chomp!(#{prefix.dump})\n"
108 print " DESTDIR = ", (drive ? "TOPDIR && TOPDIR[/\\A[a-z]:/i] || " : ""), "'' unless defined? DESTDIR\n"
109 print " CONFIG = {}\n"
110 print " CONFIG[\"DESTDIR\"] = DESTDIR\n"
113 RUBY_VERSION.scan(/(\d+)\.(\d+)\.(\d+)/) {
114 print " CONFIG[\"MAJOR\"] = \"" + $1 + "\"\n"
115 print " CONFIG[\"MINOR\"] = \"" + $2 + "\"\n"
116 print " CONFIG[\"TEENY\"] = \"" + $3 + "\"\n"
118 patchlevel = IO.foreach(File.join(srcdir, "version.h")) {|l|
119 m = /^\s*#\s*define\s+RUBY_PATCHLEVEL\s+(\d+)/.match(l) and break m[1]
121 print " CONFIG[\"PATCHLEVEL\"] = \"#{patchlevel}\"\n"
124 dest = drive ? /= \"(?!\$[\(\{])(?:[a-z]:)?/i : /= \"(?!\$[\(\{])/
125 v_others.collect! do |x|
126 if /^\s*CONFIG\["(?!abs_|old)[a-z]+(?:_prefix|dir)"\]/ === x
127 x.sub(dest, '= "$(DESTDIR)')
134 v_fast << " CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n"
135 v_fast << " CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n"
138 v_fast << " CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n"
144 CONFIG["rubylibdir"] = "$(libdir)/ruby/$(ruby_version)"
145 CONFIG["archdir"] = "$(rubylibdir)/$(arch)"
146 CONFIG["sitelibdir"] = "$(sitedir)/$(ruby_version)"
147 CONFIG["sitearchdir"] = "$(sitelibdir)/$(sitearch)"
148 CONFIG["vendorlibdir"] = "$(vendordir)/$(ruby_version)"
149 CONFIG["vendorarchdir"] = "$(vendorlibdir)/$(sitearch)"
150 CONFIG["topdir"] = File.dirname(__FILE__)
152 CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
153 def RbConfig::expand(val, config = CONFIG)
154 val.gsub!(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do
158 elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]]
161 RbConfig::expand(key, config)
163 key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat
171 CONFIG.each_value do |val|
172 RbConfig::expand(val)
175 Config = RbConfig # compatibility for ruby-1.8.4 and older.
176 CROSS_COMPILING = nil unless defined? CROSS_COMPILING
180 mode = IO::RDWR|IO::CREAT
181 mode |= IO::BINARY if defined?(IO::BINARY)
182 open(rbconfig_rb, mode) do |f|
183 if $timestamp and f.stat.size == config.size and f.read == config
184 puts "#{rbconfig_rb} unchanged"
186 puts "#{rbconfig_rb} updated"
192 if String === $timestamp
193 FileUtils.touch($timestamp)