Skip to content
This repository
Browse code

Untangle initialization dependencies in configure.

  • Loading branch information...
commit 56ae1f37e5955c484fcfe411679cd1cdad0ad650 1 parent c93fec3
Brian Shirai brixen authored

Showing 1 changed file with 132 additions and 73 deletions. Show diff stats Hide diff stats

  1. +132 73 configure
205 configure
@@ -9,6 +9,8 @@ require 'rbconfig'
9 9 require 'tempfile'
10 10 require 'fileutils'
11 11 require 'stringio'
  12 +require 'digest/md5'
  13 +require 'net/http'
12 14
13 15 root = File.expand_path File.dirname(__FILE__)
14 16
@@ -16,42 +18,38 @@ require File.join(root, "kernel", "delta", "options")
16 18
17 19 class Configure
18 20
  21 + # Default settings only. All code that may depend on user-selected options
  22 + # must run after options are processed.
19 23 def initialize(root)
20 24 @log = Logger.new "configure.log"
21 25
22 26 @command_line = ARGV.dup
23 27 @log.log "Command line: #{@command_line.join(" ").inspect}"
24 28
  29 + @features = {}
25 30 @defines = []
26 31 @config = File.join(root, "config.rb")
27 32
  33 + # Platform settings
28 34 @host = `sh -c ./rakelib/config.guess`.chomp
29   - /([^-]+)-([^-]+)-(.*)/ =~ @host
30   - @cpu, @vendor, @os = $1, $2, $3
  35 + @cpu = nil
  36 + @vendor = nil
  37 + @os = nil
  38 + @windows = nil
  39 + @darwin = nil
  40 + @bsd = nil
  41 + @linux = nil
31 42 @little_endian = false
32 43 @sizeof = {}
33 44
34   - # TODO: For better cross-compiling support, it may be necessary to
35   - # use the feature facility to check for a define in the compiler.
36   - @windows = (@host =~ /mingw|mswin/) != nil
37   - @darwin = (@host =~ /darwin/) != nil
38   - @bsd = (@host =~ /bsd/) != nil
39   - @linux = (@host =~ /linux/) != nil
40   -
41   - # Set up system commands to run in cmd.exe on Windows.
42   - if @windows
43   - alias :old_system :system
44   - alias :old_backquote :`
45   - alias :system :msys_system
46   - alias :` :msys_backquote
47   - end
  45 + # Build tools
  46 + @cc = nil
  47 + @cxx = nil
  48 + @rake = nil
  49 + @tar = nil
  50 + @pers = nil
48 51
49   - # Compiler / build settings
50   - @cc = ENV['CC'] || 'gcc'
51   - @cxx = ENV['CXX'] || 'g++'
52   - @rake = ENV['RAKE'] || 'rake'
53   - @tar = ENV['TAR'] || (@windows ? 'bsdtar' : 'tar')
54   - @perl = ENV['PERL'] || 'perl'
  52 + # Versions
55 53 @default_version = "18"
56 54 @version_list = ["18", "19"]
57 55 @supported_versions = ["18", "19", "20"]
@@ -74,17 +72,8 @@ class Configure
74 72 @llvm_source_url = "http://llvm.org/releases/3.0/llvm-3.0.tar.gz"
75 73 @llvm_asset_path = "http://asset.rubini.us/prebuilt"
76 74 @llvm_source_build = false
77   -
78   - check_tool_version @cc, '-dumpversion', [4, 1]
79   - check_tool_version @cxx, '-dumpversion', [4, 1]
80   - check_tool_version 'bison', '--version', [2, 3]
81   -
82   - @gcc_major = `#{@cc} -dumpversion`.strip.split(".")[0,2].join(".")
83   - if @host == "i686-pc-linux-gnu" || @host == "x86_64-unknown-linux-gnu"
84   - @llvm_generic_prebuilt = "llvm-#{@llvm_version}-#{@host}-#{@gcc_major}.tar.bz2"
85   - else
86   - @llvm_generic_prebuilt = "llvm-#{@llvm_version}-#{@host}.tar.bz2"
87   - end
  75 + @llvm_generic_prebuilt = nil
  76 + @need_update_prebuilt = false
88 77
89 78 @llvm_parent_path = File.join(root, "vendor")
90 79 @llvm_default = File.join(@llvm_parent_path, "llvm")
@@ -131,15 +120,6 @@ class Configure
131 120 @version = "#{@libversion}.0dev"
132 121 @release_date = "yyyy-mm-dd"
133 122 @config_version = 162
134   -
135   - # TODO: add conditionals for platforms
136   - if RbConfig::CONFIG["build_os"] =~ /darwin/
137   - @ldshared = "#{@cc} -bundle -undefined suppress -flat_namespace"
138   - else
139   - @ldshared = "#{@cc} -shared"
140   - end
141   -
142   - import_env
143 123 end
144 124
145 125 # Set up system commands to run in cmd.exe on Windows. Either Windows
@@ -156,12 +136,6 @@ class Configure
156 136 old_backquote %[cmd.exe /C "#{cmd}"]
157 137 end
158 138
159   - def import_env
160   - @user_cflags = ENV['CFLAGS']
161   - @user_cppflags = ENV['CPPFLAGS']
162   - @user_ldflags = ENV['LDFLAGS']
163   - end
164   -
165 139 def expand(path)
166 140 File.expand_path(path)
167 141 end
@@ -176,6 +150,28 @@ class Configure
176 150 dir
177 151 end
178 152
  153 + def set_host
  154 + /([^-]+)-([^-]+)-(.*)/ =~ @host
  155 + @cpu, @vendor, @os = $1, $2, $3
  156 +
  157 + # TODO: For better cross-compiling support, it may be necessary to
  158 + # use the feature facility to check for a define in the compiler.
  159 + @windows = (@host =~ /mingw|mswin/) != nil
  160 + @darwin = (@host =~ /darwin/) != nil
  161 + @bsd = (@host =~ /bsd/) != nil
  162 + @linux = (@host =~ /linux/) != nil
  163 + end
  164 +
  165 + def set_system_commands
  166 + # Set up system commands to run in cmd.exe on Windows.
  167 + if @windows
  168 + alias :old_system :system
  169 + alias :old_backquote :`
  170 + alias :system :msys_system
  171 + alias :` :msys_backquote
  172 + end
  173 + end
  174 +
179 175 def set_filesystem_paths
180 176 @prefixdir = @sourcedir unless @prefixdir
181 177 @bindir = @prefixdir + "/bin" unless @bindir
@@ -218,7 +214,8 @@ class Configure
218 214 end
219 215
220 216 def options
221   - o = Rubinius::Options.new "Usage: configure [options]", 30
  217 + @options = Rubinius::Options.new "Usage: configure [options]", 30
  218 + o = @options
222 219 o.left_align
223 220
224 221 o.doc " Configure settings"
@@ -305,7 +302,7 @@ class Configure
305 302 end
306 303
307 304 o.on "--update-prebuilt", "Update prebuilt LLVM packages from the internet" do
308   - update_prebuilt @llvm_generic_prebuilt, true
  305 + @need_update_prebuilt = true
309 306 end
310 307
311 308 o.doc "\n System settings"
@@ -391,15 +388,10 @@ class Configure
391 388
392 389 o.doc "\n Optional features"
393 390
394   - @options = o
395   -
396   - @features = {}
397   -
398   - default_on = RUBY_PLATFORM !~ /openbsd/i
399   - feature "execinfo", default_on
  391 + feature "execinfo", true
400 392 feature "C-readline", true
401 393 feature "ruby-readline", false
402   - feature "vendor-zlib", !!@windows
  394 + feature "vendor-zlib", false
403 395 feature "alloc-tracking", false
404 396 feature "fibers", true
405 397
@@ -420,15 +412,15 @@ class Configure
420 412
421 413 end
422 414
423   - def feature(name, on_by_default=true)
424   - @features[name] = on_by_default
  415 + def feature(name, default_value=true)
  416 + @features[name] = ConfigurationToggle.new default_value
425 417
426 418 @options.on "--with-#{name}", "Enable #{name}" do
427   - @features[name] = true
  419 + @features[name].configured = true
428 420 end
429 421
430 422 @options.on "--without-#{name}", "Disable #{name}" do
431   - @features[name] = false
  423 + @features[name].configured = false
432 424 end
433 425 end
434 426
@@ -448,14 +440,10 @@ Unsupported language version requested: #{ver}. Options are #{@supported_version
448 440 versions
449 441 end
450 442
451   - require 'digest/md5'
452   -
453 443 def md5_checksum(md5_path, full_path)
454 444 return Digest::MD5.file(full_path).hexdigest == File.read(md5_path).strip.split(" ").first
455 445 end
456 446
457   - require 'net/http'
458   -
459 447 def download(url, full_path)
460 448 begin
461 449
@@ -666,6 +654,8 @@ Unsupported language version requested: #{ver}. Options are #{@supported_version
666 654 end
667 655
668 656 def setup_auto
  657 + update_prebuilt @llvm_generic_prebuilt, true if @need_update_prebuilt
  658 +
669 659 @log.print " Checking for existing LLVM library tree: "
670 660 if File.directory?("#{@llvm_default}/Release")
671 661 config = llvm_config_cmd "#{@llvm_default}/Release/bin/llvm-config"
@@ -781,6 +771,37 @@ Unsupported language version requested: #{ver}. Options are #{@supported_version
781 771 exit 1
782 772 end
783 773
  774 + def check_tools
  775 + @cc = ENV['CC'] || 'gcc'
  776 + @cxx = ENV['CXX'] || 'g++'
  777 +
  778 + check_tool_version @cc, '-dumpversion', [4, 1]
  779 + check_tool_version @cxx, '-dumpversion', [4, 1]
  780 + check_tool_version 'bison', '--version', [2, 3]
  781 +
  782 + @rake = ENV['RAKE'] || 'rake'
  783 + @tar = ENV['TAR'] || (@windows ? 'bsdtar' : 'tar')
  784 + @perl = ENV['PERL'] || 'perl'
  785 +
  786 + @gcc_major = `#{@cc} -dumpversion`.strip.split(".")[0,2].join(".")
  787 + if @host == "i686-pc-linux-gnu" || @host == "x86_64-unknown-linux-gnu"
  788 + @llvm_generic_prebuilt = "llvm-#{@llvm_version}-#{@host}-#{@gcc_major}.tar.bz2"
  789 + else
  790 + @llvm_generic_prebuilt = "llvm-#{@llvm_version}-#{@host}.tar.bz2"
  791 + end
  792 +
  793 + @user_cflags = ENV['CFLAGS']
  794 + @user_cppflags = ENV['CPPFLAGS']
  795 + @user_ldflags = ENV['LDFLAGS']
  796 +
  797 + # TODO: add conditionals for platforms
  798 + if RbConfig::CONFIG["build_os"] =~ /darwin/
  799 + @ldshared = "#{@cc} -bundle -undefined suppress -flat_namespace"
  800 + else
  801 + @ldshared = "#{@cc} -shared"
  802 + end
  803 + end
  804 +
784 805 def check_program(run=true, link_libs=[])
785 806 begin
786 807 basename = "rbx-configure-test"
@@ -1047,18 +1068,23 @@ int main() { return tgetnum(""); }
1047 1068 end
1048 1069
1049 1070 def detect_features
1050   - if @features["execinfo"] and has_function("backtrace", ["execinfo.h"])
  1071 + # Default on OpenBSD is no execinfo
  1072 + if RUBY_PLATFORM =~ /openbsd/i and @features["execinfo"].configured.nil?
  1073 + @features["execinfo"].configured = false
  1074 + end
  1075 +
  1076 + if @features["execinfo"].value and has_function("backtrace", ["execinfo.h"])
1051 1077 @defines << "HAS_EXECINFO"
1052 1078 end
1053 1079
1054   - if @features["alloc-tracking"]
  1080 + if @features["alloc-tracking"].value
1055 1081 @defines << "RBX_ALLOC_TRACKING"
1056 1082 end
1057 1083
1058   - if @features["ruby-readline"]
  1084 + if @features["ruby-readline"].value
1059 1085 @rb_readline = true
1060 1086 else
1061   - if @features["C-readline"] and
  1087 + if @features["C-readline"].value and
1062 1088 (has_function("readline", ["stdio.h", "stdlib.h", "readline/readline.h"]) or
1063 1089 has_function("readline", ["stdio.h", "stdlib.h", "editline/readline.h"]))
1064 1090 @rb_readline = false
@@ -1067,11 +1093,16 @@ int main() { return tgetnum(""); }
1067 1093 end
1068 1094 end
1069 1095
1070   - if @features["fibers"]
1071   - @fibers = true if @x86_32 or @x86_64
1072   - end
  1096 + if @features["fibers"].value
  1097 + @fibers = true if @x86_32 or @x86_64
  1098 + end
  1099 +
  1100 + # Default on Windows is vendor-zlib
  1101 + if @windows and @features["vendor-zlib"].configured.nil?
  1102 + @features["vendor-zlib"].configured = true
  1103 + end
1073 1104
1074   - if @features["vendor-zlib"]
  1105 + if @features["vendor-zlib"].value
1075 1106 @vendor_zlib = true
1076 1107 # Our vendored zlib uses long as the crc_table type
1077 1108 # If we update vendored zlib in the future, we have to
@@ -1081,6 +1112,7 @@ int main() { return tgetnum(""); }
1081 1112 @include_dirs << "#{@vendordir}/zlib"
1082 1113 @lib_dirs << "#{@vendordir}/zlib"
1083 1114 end
  1115 +
1084 1116 @defines << "HAVE_SPT_REUSEARGV" if @linux || @darwin || @bsd
1085 1117 end
1086 1118
@@ -1173,6 +1205,10 @@ int main() { return tgetnum(""); }
1173 1205 end
1174 1206
1175 1207 def process
  1208 + set_host
  1209 + set_system_commands
  1210 + check_tools
  1211 +
1176 1212 if @use_llvm
1177 1213 @log.write "Configuring LLVM..."
1178 1214 setup_auto
@@ -1738,6 +1774,29 @@ Available commands are:
1738 1774 EOM
1739 1775 end
1740 1776
  1777 +
  1778 + # Configuration item that has both a default and a configured value
  1779 + class ConfigurationToggle
  1780 + attr_reader :default, :configured
  1781 +
  1782 + def initialize(default_value)
  1783 + @default = !!default_value
  1784 + @configured = nil
  1785 + end
  1786 +
  1787 + def configured=(value)
  1788 + @configured = !!value
  1789 + end
  1790 +
  1791 + def value
  1792 + unless @configured.nil?
  1793 + @configured
  1794 + else
  1795 + @default
  1796 + end
  1797 + end
  1798 + end
  1799 +
1741 1800 # Handles user output and logging while running configure.
1742 1801 class Logger
1743 1802 attr_reader :path

0 comments on commit 56ae1f3

Please sign in to comment.
Something went wrong with that request. Please try again.