diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 5a91c1574a..57efff8fab 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -13,6 +13,9 @@ module SharedEnvExtension 'llvm-gcc' => :llvm, 'clang' => :clang } + COMPILERS = COMPILER_SYMBOL_MAP.values + + GNU_GCC_VERSIONS.map { |n| "gcc-4.#{n}" } + SANITIZED_VARS = %w[ CDPATH GREP_OPTIONS CLICOLOR_FORCE CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH @@ -108,6 +111,18 @@ module SharedEnvExtension end end + def determine_cc + COMPILER_SYMBOL_MAP.invert.fetch(compiler, compiler) + end + + COMPILERS.each do |x| + define_method x do + @compiler = x + self.cc = determine_cc + self.cxx = determine_cxx + end + end + # If the given compiler isn't compatible, will try to select # an alternate compiler, altering the value of environment variables. # If no valid compiler is found, raises an exception. diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index f433e50bc6..cf8804fabe 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -95,47 +95,46 @@ module Stdenv end end - def gcc_4_0_1 - self.cc = MacOS.locate("gcc-4.0") - self.cxx = MacOS.locate("g++-4.0") - set_cpu_cflags '-march=nocona -mssse3' - @compiler = :gcc_4_0 + def determine_cc + s = super + MacOS.locate(s) || Pathname.new(s) end - alias_method :gcc_4_0, :gcc_4_0_1 + + def determine_cxx + path = determine_cc + dir, base = path.dirname, path.basename + dir / base.to_s.sub("gcc", "g++").sub("clang", "clang++") + end + + def gcc_4_0 + super + set_cpu_cflags '-march=nocona -mssse3' + end + alias_method :gcc_4_0_1, :gcc_4_0 def gcc - self.cc = MacOS.locate("gcc-4.2") - self.cxx = MacOS.locate("g++-4.2") + super set_cpu_cflags - @compiler = :gcc end alias_method :gcc_4_2, :gcc GNU_GCC_VERSIONS.each do |n| define_method(:"gcc-4.#{n}") do - gcc = "gcc-4.#{n}" - gxx = gcc.gsub('c', '+') - self.cc = MacOS.locate(gcc) - self.cxx = MacOS.locate(gxx) + super() set_cpu_cflags - @compiler = gcc end end def llvm - self.cc = MacOS.locate("llvm-gcc") - self.cxx = MacOS.locate("llvm-g++") + super set_cpu_cflags - @compiler = :llvm end def clang - self.cc = MacOS.locate("clang") - self.cxx = MacOS.locate("clang++") + super replace_in_cflags(/-Xarch_#{Hardware::CPU.arch_32_bit} (-march=\S*)/, '\1') # Clang mistakenly enables AES-NI on plain Nehalem set_cpu_cflags '-march=native', :nehalem => '-march=native -Xclang -target-feature -Xclang -aes' - @compiler = :clang end def remove_macosxsdk version=MacOS.version diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index fb32dc8062..dc7a0183e1 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -103,11 +103,6 @@ module Superenv if MacOS::Xcode.without_clt? then MacOS.sdk_path.to_s else "" end end - def determine_cc - cc = compiler - COMPILER_SYMBOL_MAP.invert.fetch(cc, cc) - end - def determine_cxx determine_cc.to_s.gsub('gcc', 'g++').gsub('clang', 'clang++') end @@ -250,22 +245,6 @@ module Superenv end alias_method :j1, :deparallelize - COMPILER_SYMBOL_MAP.values.each do |compiler| - define_method compiler do - @compiler = compiler - self.cc = determine_cc - self.cxx = determine_cxx - end - end - - GNU_GCC_VERSIONS.each do |n| - define_method(:"gcc-4.#{n}") do - @compiler = "gcc-4.#{n}" - self.cc = determine_cc - self.cxx = determine_cxx - end - end - def make_jobs self['MAKEFLAGS'] =~ /-\w*j(\d)+/ [$1.to_i, 1].max