Unify compiler selection logic
This unifies the logic for selecting a compiler between superenv and stdenv. A variation of superenv's `determine_cc`, which now returns a symbol, has been moved into the shared ENV extension. Stdenv uses the result of this directly (as it's always used symbols), while superenv translates that back into a compiler string. This also has the effect of disabling HOMEBREW_USE_(gcc|llvm|clang) in stdenv, which have already been marked as deprecated for some time, and enables the HOMEBREW_CC= environment variable syntax from superenv in stdenv.
This commit is contained in:
parent
221bb2419f
commit
7e1af4b7d5
@ -3,6 +3,11 @@ module SharedEnvExtension
|
|||||||
FC_FLAG_VARS = %w{FCFLAGS FFLAGS}
|
FC_FLAG_VARS = %w{FCFLAGS FFLAGS}
|
||||||
|
|
||||||
COMPILERS = ['clang', 'gcc-4.0', 'gcc-4.2', 'llvm-gcc']
|
COMPILERS = ['clang', 'gcc-4.0', 'gcc-4.2', 'llvm-gcc']
|
||||||
|
COMPLER_ALIASES = {'gcc' => 'gcc-4.2', 'llvm' => 'llvm-gcc'}
|
||||||
|
COMPILER_SYMBOL_MAP = { 'gcc-4.0' => :gcc_4_0,
|
||||||
|
'gcc-4.2' => :gcc,
|
||||||
|
'llvm-gcc' => :llvm,
|
||||||
|
'clang' => :clang }
|
||||||
|
|
||||||
def remove_cc_etc
|
def remove_cc_etc
|
||||||
keys = %w{CC CXX OBJC OBJCXX LD CPP CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS LDFLAGS CPPFLAGS}
|
keys = %w{CC CXX OBJC OBJCXX LD CPP CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS LDFLAGS CPPFLAGS}
|
||||||
@ -65,6 +70,33 @@ module SharedEnvExtension
|
|||||||
def fflags; self['FFLAGS']; end
|
def fflags; self['FFLAGS']; end
|
||||||
def fcflags; self['FCFLAGS']; end
|
def fcflags; self['FCFLAGS']; end
|
||||||
|
|
||||||
|
def compiler
|
||||||
|
if (cc = ARGV.cc)
|
||||||
|
raise("Invalid value for --cc: #{cc}") if COMPILERS.grep(cc).empty?
|
||||||
|
COMPILER_SYMBOL_MAP.fetch(cc, cc)
|
||||||
|
elsif ARGV.include? '--use-gcc'
|
||||||
|
gcc_installed = Formula.factory('apple-gcc42').installed? rescue false
|
||||||
|
# fall back to something else on systems without Apple gcc
|
||||||
|
if MacOS.locate('gcc-4.2') || gcc_installed
|
||||||
|
:gcc
|
||||||
|
else
|
||||||
|
raise "gcc-4.2 not found!"
|
||||||
|
end
|
||||||
|
elsif ARGV.include? '--use-llvm'
|
||||||
|
:llvm
|
||||||
|
elsif ARGV.include? '--use-clang'
|
||||||
|
:clang
|
||||||
|
elsif self['HOMEBREW_CC']
|
||||||
|
cc = COMPLER_ALIASES.fetch(self['HOMEBREW_CC'], self['HOMEBREW_CC'])
|
||||||
|
COMPILER_SYMBOL_MAP.fetch(cc) do |invalid|
|
||||||
|
opoo "Invalid value for HOMEBREW_CC: #{invalid}"
|
||||||
|
MacOS.default_compiler
|
||||||
|
end
|
||||||
|
else
|
||||||
|
MacOS.default_compiler
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Snow Leopard defines an NCURSES value the opposite of most distros
|
# Snow Leopard defines an NCURSES value the opposite of most distros
|
||||||
# See: http://bugs.python.org/issue6848
|
# See: http://bugs.python.org/issue6848
|
||||||
# Currently only used by aalib in core
|
# Currently only used by aalib in core
|
||||||
|
@ -339,30 +339,6 @@ module Stdenv
|
|||||||
set_cpu_flags CC_FLAG_VARS, default, map
|
set_cpu_flags CC_FLAG_VARS, default, map
|
||||||
end
|
end
|
||||||
|
|
||||||
# actually c-compiler, so cc would be a better name
|
|
||||||
def compiler
|
|
||||||
# test for --flags first so that installs can be overridden on a per
|
|
||||||
# install basis. Then test for ENVs in inverse order to flags, this is
|
|
||||||
# sensible, trust me
|
|
||||||
@compiler ||= if (cc = ARGV.cc)
|
|
||||||
COMPILERS.grep(cc).pop ? cc : raise("Invalid value for --cc: #{cc}")
|
|
||||||
elsif ARGV.include? '--use-gcc'
|
|
||||||
:gcc
|
|
||||||
elsif ARGV.include? '--use-llvm'
|
|
||||||
:llvm
|
|
||||||
elsif ARGV.include? '--use-clang'
|
|
||||||
:clang
|
|
||||||
elsif self['HOMEBREW_USE_CLANG']
|
|
||||||
:clang
|
|
||||||
elsif self['HOMEBREW_USE_LLVM']
|
|
||||||
:llvm
|
|
||||||
elsif self['HOMEBREW_USE_GCC']
|
|
||||||
:gcc
|
|
||||||
else
|
|
||||||
MacOS.default_compiler
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def make_jobs
|
def make_jobs
|
||||||
# '-j' requires a positive integral argument
|
# '-j' requires a positive integral argument
|
||||||
if self['HOMEBREW_MAKE_JOBS'].to_i > 0
|
if self['HOMEBREW_MAKE_JOBS'].to_i > 0
|
||||||
|
@ -122,52 +122,8 @@ module Superenv
|
|||||||
private
|
private
|
||||||
|
|
||||||
def determine_cc
|
def determine_cc
|
||||||
if (cc = ARGV.cc)
|
cc = compiler
|
||||||
COMPILERS.grep(cc).pop ? cc : raise("Invalid value for --cc: #{cc}")
|
COMPILER_SYMBOL_MAP.invert.fetch(cc, cc)
|
||||||
elsif ARGV.include? '--use-gcc'
|
|
||||||
gcc_installed = Formula.factory('apple-gcc42').installed? rescue false
|
|
||||||
# fall back to something else on systems without Apple gcc
|
|
||||||
if MacOS.locate('gcc-4.2') || gcc_installed
|
|
||||||
"gcc-4.2"
|
|
||||||
else
|
|
||||||
raise "gcc-4.2 not found!"
|
|
||||||
end
|
|
||||||
elsif ARGV.include? '--use-llvm'
|
|
||||||
"llvm-gcc"
|
|
||||||
elsif ARGV.include? '--use-clang'
|
|
||||||
"clang"
|
|
||||||
elsif self['HOMEBREW_USE_CLANG']
|
|
||||||
opoo %{HOMEBREW_USE_CLANG is deprecated, use HOMEBREW_CC="clang" instead}
|
|
||||||
"clang"
|
|
||||||
elsif self['HOMEBREW_USE_LLVM']
|
|
||||||
opoo %{HOMEBREW_USE_LLVM is deprecated, use HOMEBREW_CC="llvm" instead}
|
|
||||||
"llvm-gcc"
|
|
||||||
elsif self['HOMEBREW_USE_GCC']
|
|
||||||
opoo %{HOMEBREW_USE_GCC is deprecated, use HOMEBREW_CC="gcc" instead}
|
|
||||||
"gcc"
|
|
||||||
elsif self['HOMEBREW_CC']
|
|
||||||
case self['HOMEBREW_CC']
|
|
||||||
when 'clang', 'gcc-4.0' then self['HOMEBREW_CC']
|
|
||||||
# depending on Xcode version plain 'gcc' could actually be
|
|
||||||
# gcc-4.0 or llvm-gcc
|
|
||||||
when 'gcc', 'gcc-4.2' then 'gcc-4.2'
|
|
||||||
when 'llvm', 'llvm-gcc' then 'llvm-gcc'
|
|
||||||
else
|
|
||||||
opoo "Invalid value for HOMEBREW_CC: #{self['HOMEBREW_CC'].inspect}"
|
|
||||||
default_cc
|
|
||||||
end
|
|
||||||
else
|
|
||||||
default_cc
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def default_cc
|
|
||||||
case MacOS.default_compiler
|
|
||||||
when :clang then 'clang'
|
|
||||||
when :llvm then 'llvm-gcc'
|
|
||||||
when :gcc then 'gcc-4.2'
|
|
||||||
when :gcc_4_0 then 'gcc-4.0'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def determine_path
|
def determine_path
|
||||||
@ -288,15 +244,6 @@ module Superenv
|
|||||||
macosxsdk remove_macosxsdk].each{|s| alias_method s, :noop }
|
macosxsdk remove_macosxsdk].each{|s| alias_method s, :noop }
|
||||||
|
|
||||||
### DEPRECATE THESE
|
### DEPRECATE THESE
|
||||||
def compiler
|
|
||||||
case self['HOMEBREW_CC']
|
|
||||||
when "llvm-gcc" then :llvm
|
|
||||||
when "gcc-4.2" then :gcc
|
|
||||||
when "gcc", "clang" then self['HOMEBREW_CC'].to_sym
|
|
||||||
else
|
|
||||||
raise "Invalid value for HOMEBREW_CC: #{self['HOMEBREW_CC'].inspect}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
def deparallelize
|
def deparallelize
|
||||||
delete('MAKEFLAGS')
|
delete('MAKEFLAGS')
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user