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, 'llvm-gcc' => :llvm,
'clang' => :clang } 'clang' => :clang }
COMPILERS = COMPILER_SYMBOL_MAP.values +
GNU_GCC_VERSIONS.map { |n| "gcc-4.#{n}" }
SANITIZED_VARS = %w[ SANITIZED_VARS = %w[
CDPATH GREP_OPTIONS CLICOLOR_FORCE CDPATH GREP_OPTIONS CLICOLOR_FORCE
CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH
@ -108,6 +111,18 @@ module SharedEnvExtension
end end
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 # If the given compiler isn't compatible, will try to select
# an alternate compiler, altering the value of environment variables. # an alternate compiler, altering the value of environment variables.
# If no valid compiler is found, raises an exception. # If no valid compiler is found, raises an exception.

View File

@ -95,47 +95,46 @@ module Stdenv
end end
end end
def gcc_4_0_1 def determine_cc
self.cc = MacOS.locate("gcc-4.0") s = super
self.cxx = MacOS.locate("g++-4.0") MacOS.locate(s) || Pathname.new(s)
set_cpu_cflags '-march=nocona -mssse3'
@compiler = :gcc_4_0
end 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 def gcc
self.cc = MacOS.locate("gcc-4.2") super
self.cxx = MacOS.locate("g++-4.2")
set_cpu_cflags set_cpu_cflags
@compiler = :gcc
end end
alias_method :gcc_4_2, :gcc alias_method :gcc_4_2, :gcc
GNU_GCC_VERSIONS.each do |n| GNU_GCC_VERSIONS.each do |n|
define_method(:"gcc-4.#{n}") do define_method(:"gcc-4.#{n}") do
gcc = "gcc-4.#{n}" super()
gxx = gcc.gsub('c', '+')
self.cc = MacOS.locate(gcc)
self.cxx = MacOS.locate(gxx)
set_cpu_cflags set_cpu_cflags
@compiler = gcc
end end
end end
def llvm def llvm
self.cc = MacOS.locate("llvm-gcc") super
self.cxx = MacOS.locate("llvm-g++")
set_cpu_cflags set_cpu_cflags
@compiler = :llvm
end end
def clang def clang
self.cc = MacOS.locate("clang") super
self.cxx = MacOS.locate("clang++")
replace_in_cflags(/-Xarch_#{Hardware::CPU.arch_32_bit} (-march=\S*)/, '\1') replace_in_cflags(/-Xarch_#{Hardware::CPU.arch_32_bit} (-march=\S*)/, '\1')
# Clang mistakenly enables AES-NI on plain Nehalem # Clang mistakenly enables AES-NI on plain Nehalem
set_cpu_cflags '-march=native', :nehalem => '-march=native -Xclang -target-feature -Xclang -aes' set_cpu_cflags '-march=native', :nehalem => '-march=native -Xclang -target-feature -Xclang -aes'
@compiler = :clang
end end
def remove_macosxsdk version=MacOS.version 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 if MacOS::Xcode.without_clt? then MacOS.sdk_path.to_s else "" end
end end
def determine_cc
cc = compiler
COMPILER_SYMBOL_MAP.invert.fetch(cc, cc)
end
def determine_cxx def determine_cxx
determine_cc.to_s.gsub('gcc', 'g++').gsub('clang', 'clang++') determine_cc.to_s.gsub('gcc', 'g++').gsub('clang', 'clang++')
end end
@ -250,22 +245,6 @@ module Superenv
end end
alias_method :j1, :deparallelize 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 def make_jobs
self['MAKEFLAGS'] =~ /-\w*j(\d)+/ self['MAKEFLAGS'] =~ /-\w*j(\d)+/
[$1.to_i, 1].max [$1.to_i, 1].max