Make --cc override the compiler selector

This commit is contained in:
Jack Nagel 2014-09-18 15:50:54 -05:00
parent 04dae13ae7
commit c5f2f6b539
4 changed files with 37 additions and 24 deletions

View File

@ -80,11 +80,14 @@ class CompilerSelector
:gcc_4_0 => [:gcc_4_0, :gcc, :llvm, :gnu, :clang],
}
def self.select_for(formula)
compilers = COMPILER_PRIORITY.fetch(MacOS.default_compiler)
def self.select_for(formula, compilers=self.compilers)
new(formula, MacOS, compilers).compiler
end
def self.compilers
COMPILER_PRIORITY.fetch(MacOS.default_compiler)
end
attr_reader :formula, :failures, :versions, :compilers
def initialize(formula, versions, compilers)

View File

@ -27,6 +27,10 @@ module SharedEnvExtension
GOBIN
]
def setup_build_environment(formula=nil)
@formula = formula
end
def reset
SANITIZED_VARS.each { |k| delete(k) }
end
@ -101,15 +105,21 @@ module SharedEnvExtension
def fcflags; self['FCFLAGS']; end
def compiler
@compiler ||= if (cc = ARGV.cc || homebrew_cc)
COMPILER_SYMBOL_MAP.fetch(cc) do |other|
case other
when GNU_GCC_REGEXP
other
else
raise "Invalid value for --cc: #{other}"
end
@compiler ||= if (cc = ARGV.cc)
warn_about_non_apple_gcc($1) if cc =~ GNU_GCC_REGEXP
fetch_compiler(cc, "--cc")
elsif (cc = homebrew_cc)
warn_about_non_apple_gcc($1) if cc =~ GNU_GCC_REGEXP
compiler = fetch_compiler(cc, "HOMEBREW_CC")
if @formula
compilers = [compiler] + CompilerSelector.compilers
compiler = CompilerSelector.select_for(@formula, compilers)
end
compiler
elsif @formula
CompilerSelector.select_for(@formula)
else
MacOS.default_compiler
end
@ -127,13 +137,6 @@ module SharedEnvExtension
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.
def validate_cc!(formula)
send CompilerSelector.select_for(formula)
end
# Snow Leopard defines an NCURSES value the opposite of most distros
# See: http://bugs.python.org/issue6848
# Currently only used by aalib in core
@ -260,4 +263,15 @@ module SharedEnvExtension
def homebrew_cc
self["HOMEBREW_CC"]
end
def fetch_compiler(value, source)
COMPILER_SYMBOL_MAP.fetch(value) do |other|
case other
when GNU_GCC_REGEXP
other
else
raise "Invalid value for #{source}: #{other}"
end
end
end
end

View File

@ -16,6 +16,7 @@ module Stdenv
end
def setup_build_environment(formula=nil)
super
reset
if MacOS.version >= :mountain_lion
@ -55,10 +56,8 @@ module Stdenv
append 'LDFLAGS', '-Wl,-headerpad_max_install_names'
send(compiler)
validate_cc!(formula) unless formula.nil?
if cc =~ GNU_GCC_REGEXP
warn_about_non_apple_gcc($1)
gcc_formula = gcc_version_formula($1)
append_path "PATH", gcc_formula.opt_bin.to_s
end

View File

@ -34,11 +34,10 @@ module Superenv
end
def setup_build_environment(formula=nil)
super
reset
send(compiler)
self.cc = determine_cc
self.cxx = determine_cxx
validate_cc!(formula) unless formula.nil?
self['MAKEFLAGS'] ||= "-j#{determine_make_jobs}"
self['PATH'] = determine_path
self['PKG_CONFIG_PATH'] = determine_pkg_config_path
@ -85,8 +84,6 @@ module Superenv
# On 10.8 and newer, these flags will also be present:
# s - apply fix for sed's Unicode support
# a - apply fix for apr-1-config path
warn_about_non_apple_gcc($1) if homebrew_cc =~ GNU_GCC_REGEXP
end
private