1#!./miniruby -s 2 3# avoid warnings with -d. 4$install_name ||= nil 5$so_name ||= nil 6 7srcdir = File.expand_path('../..', __FILE__) 8$:.replace [srcdir+"/lib"] unless defined?(CROSS_COMPILING) 9$:.unshift(".") 10 11require "fileutils" 12mkconfig = File.basename($0) 13 14rbconfig_rb = ARGV[0] || 'rbconfig.rb' 15unless File.directory?(dir = File.dirname(rbconfig_rb)) 16 FileUtils.makedirs(dir, :verbose => true) 17end 18 19version = RUBY_VERSION 20config = "" 21def config.write(arg) 22 concat(arg.to_s) 23end 24$stdout = config 25 26fast = {'prefix'=>TRUE, 'ruby_install_name'=>TRUE, 'INSTALL'=>TRUE, 'EXEEXT'=>TRUE} 27print %[ 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. 30 31module RbConfig 32 RUBY_VERSION == "#{version}" or 33 raise "ruby lib version (#{version}) doesn't match executable version (\#{RUBY_VERSION})" 34 35] 36 37arch = RUBY_PLATFORM 38win32 = /mswin/ =~ arch 39universal = /universal.*darwin/ =~ arch 40v_fast = [] 41v_others = [] 42v_runtime = {} 43vars = {} 44continued_name = nil 45continued_line = nil 46File.foreach "config.status" do |line| 47 next if /^#/ =~ line 48 name = nil 49 case line 50 when /^s([%,])@(\w+)@\1(?:\|\#_!!_\#\|)?(.*)\1/ 51 name = $2 52 val = $3.gsub(/\\(?=,)/, '') 53 when /^S\["(\w+)"\]\s*=\s*"(.*)"\s*(\\)?$/ 54 name = $1 55 val = $2 56 if $3 57 continued_line = [val] 58 continued_name = name 59 next 60 end 61 when /^"(.*)"\s*(\\)?$/ 62 next if !continued_line 63 continued_line << $1 64 next if $2 65 continued_line.each {|s| s.sub!(/\\n\z/, "\n")} 66 val = continued_line.join 67 name = continued_name 68 continued_line = nil 69 when /^(?:ac_given_)?INSTALL=(.*)/ 70 v_fast << " CONFIG[\"INSTALL\"] = " + $1 + "\n" 71 end 72 73 if name 74 case name 75 when /^(?:ac_.*|configure_input|(?:top_)?srcdir|\w+OBJS)$/; next 76 when /^(?:X|(?:MINI|RUN|BASE)RUBY$)/; next 77 when /^(?:MAJOR|MINOR|TEENY)$/; next 78 when /^RUBY_INSTALL_NAME$/; next if $install_name 79 when /^RUBY_SO_NAME$/; next if $so_name 80 when /^arch$/; if val.empty? then val = arch else arch = val end 81 when /^sitearch$/; val = '$(arch)' if val.empty? 82 end 83 case val 84 when /^\$\(ac_\w+\)$/; next 85 when /^\$\{ac_\w+\}$/; next 86 when /^\$ac_\w+$/; next 87 end 88 if /^program_transform_name$/ =~ name 89 val.sub!(/\As(\\?\W)(?:\^|\${1,2})\1\1(;|\z)/, '') 90 if val.empty? 91 $install_name ||= "ruby" 92 next 93 end 94 unless $install_name 95 $install_name = "ruby" 96 val.gsub!(/\$\$/, '$') 97 val.scan(%r[\G[\s;]*(/(?:\\.|[^/])*/)?([sy])(\\?\W)((?:(?!\3)(?:\\.|.))*)\3((?:(?!\3)(?:\\.|.))*)\3([gi]*)]) do 98 |addr, cmd, sep, pat, rep, opt| 99 if addr 100 Regexp.new(addr[/\A\/(.*)\/\z/, 1]) =~ $install_name or next 101 end 102 case cmd 103 when 's' 104 pat = Regexp.new(pat, opt.include?('i')) 105 if opt.include?('g') 106 $install_name.gsub!(pat, rep) 107 else 108 $install_name.sub!(pat, rep) 109 end 110 when 'y' 111 $install_name.tr!(Regexp.quote(pat), rep) 112 end 113 end 114 end 115 end 116 eq = win32 && vars[name] ? '<< "\n"' : '=' 117 vars[name] = val 118 if name == "configure_args" 119 if win32 120 val.gsub!(/\G(--[-a-z0-9]+)((=\S+)|(?:\s+(?!-)\S+)+)?(\s*)/) { 121 _, opt, list, arg, sep = *$~ 122 "#{opt}#{arg || list && list.sub(/^\s+/, '=').tr_s(' ', ',')}#{sep}" 123 } 124 end 125 val.gsub!(/--with-out-ext/, "--without-ext") 126 end 127 val = val.gsub(/\$(?:\$|\{?(\w+)\}?)/) {$1 ? "$(#{$1})" : $&}.dump 128 case name 129 when /^prefix$/ 130 val = "(TOPDIR || DESTDIR + #{val})" 131 when /^ARCH_FLAG$/ 132 val = "arch_flag || #{val}" if universal 133 when /^UNIVERSAL_ARCHNAMES$/ 134 universal, val = val, 'universal' if universal 135 when /^includedir$/ 136 val = "(ENV['SDKROOT'] || (File.exists?(File.join(CONFIG['prefix'],'include')) ? '' : %x(xcode-select --print-path >/dev/null 2>&1 && xcrun --sdk macosx --show-sdk-path 2>/dev/null).chomp)) + #{val}" 137 when /^(CXXFLAGS|LDFLAGS|CFLAGS|LDSHARED|LIBRUBY_LDSHARED)$/ 138 if universal 139 # configure didn't strip -arch nor -m32/64 from CXXFLAGS 140 # replace the first with ARCH_FLAG and delete the rest 141 if val.sub!(/-(arch\s*\w+|m(32|64))/, '$(ARCH_FLAG)') 142 val.gsub!(/\s*-(arch\s*\w+|m(32|64))/, '') 143 end 144 end 145 end 146 v = " CONFIG[\"#{name}\"] #{eq} #{val}\n" 147 if fast[name] 148 v_fast << v 149 else 150 v_others << v 151 end 152 case name 153 when "ruby_version" 154 version = val[/\A"(.*)"\z/, 1] 155 end 156 end 157# break if /^CEOF/ 158end 159 160drive = File::PATH_SEPARATOR == ';' 161 162def vars.expand(val, config = self) 163 newval = val.gsub(/\$\$|\$\(([^()]+)\)|\$\{([^{}]+)\}/) { 164 var = $& 165 if !(v = $1 || $2) 166 '$' 167 elsif key = config[v = v[/\A[^:]+(?=(?::(.*?)=(.*))?\z)/]] 168 pat, sub = $1, $2 169 config[v] = false 170 config[v] = expand(key, config) 171 key = key.gsub(/#{Regexp.quote(pat)}(?=\s|\z)/n) {sub} if pat 172 key 173 else 174 var 175 end 176 } 177 val.replace(newval) unless newval == val 178 val 179end 180vars["prefix"] = "" 181vars["exec_prefix"] = "" 182prefix = vars.expand(vars["rubyarchdir"]) 183print " TOPDIR = File.dirname(__FILE__).chomp!(#{prefix.dump})\n" 184print " DESTDIR = ", (drive ? "TOPDIR && TOPDIR[/\\A[a-z]:/i] || " : ""), "'' unless defined? DESTDIR\n" 185print <<'ARCH' if universal 186 arch_flag = ENV['ARCHFLAGS'] || ((e = ENV['RC_ARCHS']) && e.split.uniq.map {|a| "-arch #{a}"}.join(' ')) 187ARCH 188print " universal = #{universal}\n" if universal 189print " CONFIG = {}\n" 190print " CONFIG[\"DESTDIR\"] = DESTDIR\n" 191 192versions = {} 193IO.foreach(File.join(srcdir, "version.h")) do |l| 194 m = /^\s*#\s*define\s+RUBY_(PATCHLEVEL)\s+(-?\d+)/.match(l) 195 if m 196 versions[m[1]] = m[2] 197 break 198 end 199end 200IO.foreach(File.join(srcdir, "include/ruby/version.h")) do |l| 201 m = /^\s*#\s*define\s+RUBY_API_VERSION_(MAJOR|MINOR|TEENY)\s+(-?\d+)/.match(l) 202 if m 203 versions[m[1]] = m[2] 204 break if versions.size == 4 205 end 206end 207%w[MAJOR MINOR TEENY PATCHLEVEL].each do |v| 208 print " CONFIG[#{v.dump}] = #{versions[v].dump}\n" 209end 210 211dest = drive ? %r'= "(?!\$[\(\{])(?i:[a-z]:)' : %r'= "(?!\$[\(\{])' 212v_disabled = {} 213v_others.collect! do |x| 214 if /^\s*CONFIG\["((?!abs_|old)[a-z]+(?:_prefix|dir))"\]/ === x 215 name = $1 216 if /= "no"$/ =~ x 217 v_disabled[name] = true 218 v_others.delete(name) 219 next 220 end 221 x.sub(dest, '= "$(DESTDIR)') 222 else 223 x 224 end 225end 226v_others.compact! 227 228if $install_name 229 v_fast << " CONFIG[\"ruby_install_name\"] = \"" + $install_name + "\"\n" 230 v_fast << " CONFIG[\"RUBY_INSTALL_NAME\"] = \"" + $install_name + "\"\n" 231end 232if $so_name 233 v_fast << " CONFIG[\"RUBY_SO_NAME\"] = \"" + $so_name + "\"\n" 234end 235 236print(*v_fast) 237print(*v_others) 238print <<EOS 239 CONFIG["archdir"] = "$(rubyarchdir)" 240 CONFIG["topdir"] = File.dirname(__FILE__) 241 MAKEFILE_CONFIG = {} 242 CONFIG.each{|k,v| MAKEFILE_CONFIG[k] = v.dup} 243 def RbConfig::expand(val, config = CONFIG) 244 newval = val.gsub(/\\$\\$|\\$\\(([^()]+)\\)|\\$\\{([^{}]+)\\}/) { 245 var = $& 246 if !(v = $1 || $2) 247 '$' 248 elsif key = config[v = v[/\\A[^:]+(?=(?::(.*?)=(.*))?\\z)/]] 249 pat, sub = $1, $2 250 config[v] = false 251 config[v] = RbConfig::expand(key, config) 252 key = key.gsub(/\#{Regexp.quote(pat)}(?=\\s|\\z)/n) {sub} if pat 253 key 254 else 255 var 256 end 257 } 258 val.replace(newval) unless newval == val 259 val 260 end 261 CONFIG.each_value do |val| 262 RbConfig::expand(val) 263 end 264 265 # returns the absolute pathname of the ruby command. 266 def RbConfig.ruby 267 File.join( 268 RbConfig::CONFIG["bindir"], 269 RbConfig::CONFIG["ruby_install_name"] + RbConfig::CONFIG["EXEEXT"] 270 ) 271 end 272end 273autoload :Config, "rbconfig/obsolete.rb" # compatibility for ruby-1.8.4 and older. 274CROSS_COMPILING = nil unless defined? CROSS_COMPILING 275RUBY_FRAMEWORK = true 276RUBY_FRAMEWORK_VERSION = RbConfig::CONFIG['ruby_version'] 277APPLE_GEM_HOME = File.join(RbConfig::CONFIG['libdir'], 'ruby/gems', RbConfig::CONFIG['ruby_version']) 278EOS 279 280$stdout = STDOUT 281mode = IO::RDWR|IO::CREAT 282mode |= IO::BINARY if defined?(IO::BINARY) 283open(rbconfig_rb, mode) do |f| 284 if $timestamp and f.stat.size == config.size and f.read == config 285 puts "#{rbconfig_rb} unchanged" 286 else 287 puts "#{rbconfig_rb} updated" 288 f.rewind 289 f.truncate(0) 290 f.print(config) 291 end 292end 293if String === $timestamp 294 FileUtils.touch($timestamp) 295end 296 297# vi:set sw=2: 298