3
# avoid warnings with -d.
7
srcdir = File.dirname(__FILE__)
8
$:.replace [srcdir+"/lib", "."]
11
mkconfig = File.basename($0)
13
rbconfig_rb = ARGV[0] || 'rbconfig.rb'
14
unless File.directory?(dir = File.dirname(rbconfig_rb))
15
FileUtils.makedirs(dir, :verbose => true)
18
version = RUBY_VERSION
19
def (config = "").write(arg)
24
fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE}
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.
30
RUBY_VERSION == "#{version}" or
31
raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})"
41
File.foreach "config.status" do |line|
45
when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/
47
val = $3.gsub(/\\(?=,)/, '')
48
when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/
57
when /^"(.+)"\s*(\\)?$/
61
val = continued_line.join("")
66
when /^(?:ac_given_)?INSTALL=(.*)/
67
v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n"
71
next if /^(?:ac_.*|DEFS|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
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])
84
val.gsub!(/ +(?!-)/, "=") if name == "configure_args" && /mswin32/ =~ RUBY_PLATFORM
85
val = val.gsub(/\$(?:\$|\{?(\w+)\}?)/) {$1 ? "$(#{$1})" : $&}.dump
87
val = "(TOPDIR || DESTDIR + #{val})"
89
v = " CONFIG[\"#{name}\"] #{vars[name] ? '<< "\n"' : '='} #{val}\n"
96
has_version = true if name == "MAJOR"
101
drive = File::PATH_SEPARATOR == ';'
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"
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"
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]
118
print " CONFIG[\"PATCHLEVEL\"] = \"#{patchlevel}\"\n"
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)')
131
v_fast << " CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n"
132
v_fast << " CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n"
135
v_fast << " CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n"
141
CONFIG["ruby_version"] = "$(MAJOR).$(MINOR)"
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["topdir"] = File.dirname(__FILE__)
148
CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup}
149
def Config::expand(val, config = CONFIG)
150
val.gsub!(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) do |var|
153
elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]]
156
Config::expand(key, config)
158
key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat
166
CONFIG.each_value do |val|
170
RbConfig = Config # compatibility for ruby-1.9
171
CROSS_COMPILING = nil unless defined? CROSS_COMPILING
175
mode = IO::RDWR|IO::CREAT
176
mode |= IO::BINARY if defined?(IO::BINARY)
177
open(rbconfig_rb, mode) do |f|
178
if $timestamp and f.stat.size == config.size and f.read == config
179
puts "#{rbconfig_rb} unchanged"
181
puts "#{rbconfig_rb} updated"
187
if String === $timestamp
188
FileUtils.touch($timestamp)