PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/ruby-1.9.3-p194/tool/mkconfig.rb

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