Move the compiler-selecting methods to ENV/shared

Closes Homebrew/homebrew#30210.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
Shaun Jackman 2014-06-18 16:12:32 -04:00 committed by Jack Nagel
parent 4d9d01893e
commit 42c20b0979
3 changed files with 34 additions and 41 deletions

View File

@ -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.

View File

@ -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

View File

@ -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