Use xcrun; Ensure clang is the default compiler with Xcode 4.3
Using xcrun as a proxy to execute the compiler tools is per its design. This means you can't treat ENV['CC'] as a path anymore, but I think I found the cases this was being expected and corrected them. It was not proper anyway to assume the variable was a path, it can be anything. Like a proxy. Like xcrun. Also more thoroughly clear ENV.
This commit is contained in:
parent
59bd97bb89
commit
4504662033
@ -18,9 +18,11 @@ module Homebrew extend self
|
||||
value = env[k]
|
||||
if value
|
||||
results = value
|
||||
if File.exists? value and File.symlink? value
|
||||
target = Pathname.new(value)
|
||||
results += " => #{target.realpath}"
|
||||
if value =~ %r{^/usr/bin/xcrun (.*)}
|
||||
path = `/usr/bin/xcrun -find #{$1}`
|
||||
results += " => #{path}"
|
||||
elsif File.exists? value and File.symlink? value
|
||||
results += " => #{Pathname.new(value).realpath}"
|
||||
end
|
||||
puts "#{k}: #{results}"
|
||||
end
|
||||
|
||||
@ -5,10 +5,9 @@ module HomebrewEnvExtension
|
||||
def setup_build_environment
|
||||
# Clear CDPATH to avoid make issues that depend on changing directories
|
||||
delete('CDPATH')
|
||||
delete('CPPFLAGS')
|
||||
delete('LDFLAGS')
|
||||
delete('GREP_OPTIONS') # can break CMake (lol)
|
||||
delete('CLICOLOR_FORCE') # autotools doesn't like this
|
||||
remove_cc_etc
|
||||
|
||||
self['MAKEFLAGS'] = "-j#{self.make_jobs}"
|
||||
|
||||
@ -27,10 +26,9 @@ module HomebrewEnvExtension
|
||||
self.send self.compiler
|
||||
|
||||
# we must have a working compiler!
|
||||
unless File.exist? ENV['CC'] and File.exist? ENV['CXX']
|
||||
unless ENV['CC']
|
||||
@compiler = MacOS.default_compiler
|
||||
self.send @compiler
|
||||
|
||||
ENV['CC'] = '/usr/bin/cc'
|
||||
ENV['CXX'] = '/usr/bin/c++'
|
||||
end
|
||||
@ -79,6 +77,7 @@ module HomebrewEnvExtension
|
||||
end
|
||||
|
||||
def gcc_4_0_1
|
||||
# we don't use xcrun because gcc 4.0 has not been provided since Xcode 4
|
||||
self['CC'] = "#{MacOS.dev_tools_path}/gcc-4.0"
|
||||
self['CXX'] = "#{MacOS.dev_tools_path}/g++-4.0"
|
||||
replace_in_cflags '-O4', '-O3'
|
||||
@ -87,34 +86,66 @@ module HomebrewEnvExtension
|
||||
end
|
||||
alias_method :gcc_4_0, :gcc_4_0_1
|
||||
|
||||
def xcrun tool
|
||||
if File.executable? "/usr/bin/#{tool}"
|
||||
"/usr/bin/#{tool}"
|
||||
elsif system "/usr/bin/xcrun -find #{tool} 2>1 1>/dev/null"
|
||||
# xcrun was provided first with Xcode 4.3 and allows us to proxy
|
||||
# tool usage thus avoiding various bugs
|
||||
"/usr/bin/xcrun #{tool}"
|
||||
else
|
||||
# otherwise lets try and figure it out ourselves
|
||||
fn = "#{MacOS.dev_tools_path}/#{tool}"
|
||||
if File.file? fn
|
||||
fn
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# if your formula doesn't like CC having spaces use this
|
||||
def expand_xcrun
|
||||
ENV['CC'] =~ %r{/usr/bin/xcrun (.*)}
|
||||
ENV['CC'] = `/usr/bin/xcrun -find #{$1}`.chomp if $1
|
||||
ENV['CXX'] =~ %r{/usr/bin/xcrun (.*)}
|
||||
ENV['CXX'] = `/usr/bin/xcrun -find #{$1}`.chomp if $1
|
||||
end
|
||||
|
||||
def gcc args = {}
|
||||
# Apple stopped shipping gcc-4.2 with Xcode 4.2
|
||||
# However they still provide a gcc symlink to llvm
|
||||
# But we don't want LLVM of course.
|
||||
|
||||
gcc_path = Pathname.new "#{MacOS.dev_tools_path}/gcc-4.2"
|
||||
gxx_path = Pathname.new "#{MacOS.dev_tools_path}/g++-4.2"
|
||||
self['CC'] = gcc_path.exist? ? gcc_path : HOMEBREW_PREFIX+'bin/gcc-4.2'
|
||||
self['CXX'] = gxx_path.exist? ? gxx_path : HOMEBREW_PREFIX+'bin/g++-4.2'
|
||||
ENV['CC'] = xcrun "gcc-4.2"
|
||||
ENV['CXX'] = xcrun "g++-4.2"
|
||||
|
||||
unless ENV['CC']
|
||||
ENV['CC'] = "#{HOMEBREW_PREFIX}/bin/gcc-4.2"
|
||||
ENV['CXX'] = "#{HOMEBREW_PREFIX}/bin/g++-4.2"
|
||||
raise "GCC could not be found" if not File.exist? ENV['CC']
|
||||
end
|
||||
|
||||
if not ENV['CC'] =~ %r{^/usr/bin/xcrun}
|
||||
raise "GCC could not be found" if Pathname.new(ENV['CC']).realpath.to_s =~ /llvm/
|
||||
end
|
||||
|
||||
replace_in_cflags '-O4', '-O3'
|
||||
set_cpu_cflags 'core2 -msse4', :penryn => 'core2 -msse4.1', :core2 => 'core2', :core => 'prescott', :bottle => 'generic'
|
||||
@compiler = :gcc
|
||||
|
||||
raise "GCC could not be found" if not File.exist? ENV['CC'] \
|
||||
or (Pathname.new(ENV['CC']).realpath.to_s =~ /llvm/)
|
||||
end
|
||||
alias_method :gcc_4_2, :gcc
|
||||
|
||||
def llvm
|
||||
self['CC'] = "#{MacOS.dev_tools_path}/llvm-gcc"
|
||||
self['CXX'] = "#{MacOS.dev_tools_path}/llvm-g++"
|
||||
self['CC'] = xcrun "llvm-gcc"
|
||||
self['CXX'] = xcrun "llvm-g++"
|
||||
set_cpu_cflags 'core2 -msse4', :penryn => 'core2 -msse4.1', :core2 => 'core2', :core => 'prescott'
|
||||
@compiler = :llvm
|
||||
end
|
||||
|
||||
def clang args = {}
|
||||
self['CC'] = "#{MacOS.dev_tools_path}/clang"
|
||||
self['CXX'] = "#{MacOS.dev_tools_path}/clang++"
|
||||
self['CC'] = xcrun "clang"
|
||||
self['CXX'] = xcrun "clang++"
|
||||
replace_in_cflags(/-Xarch_i386 (-march=\S*)/, '\1')
|
||||
# Clang mistakenly enables AES-NI on plain Nehalem
|
||||
set_cpu_cflags 'native', :nehalem => 'native -Xclang -target-feature -Xclang -aes'
|
||||
|
||||
@ -267,11 +267,9 @@ module MacOS extend self
|
||||
end
|
||||
|
||||
def default_cc
|
||||
cc = Pathname.new("#{dev_tools_path}/cc")
|
||||
# Xcode 4.3.0 has no /Applications/Xcode/Contents/Developer/usr/bin/cc
|
||||
# Xcode 4.3.0 has no GCC
|
||||
cc = Pathname.new("#{dev_tools_path}/llvm-gcc") unless cc.file?
|
||||
cc.realpath.basename.to_s
|
||||
cc = `/usr/bin/xcrun -find cc 2> /dev/null`.chomp
|
||||
cc = "#{dev_tools_path}/cc" if cc.empty?
|
||||
Pathname.new(cc).realpath.basename.to_s
|
||||
end
|
||||
|
||||
def default_compiler
|
||||
@ -281,7 +279,9 @@ module MacOS extend self
|
||||
when "clang" then :clang
|
||||
else
|
||||
# guess :(
|
||||
if xcode_version >= "4.2"
|
||||
if xcode_version >= "4.3"
|
||||
:clang
|
||||
elsif xcode_version >= "4.2"
|
||||
:llvm
|
||||
else
|
||||
:gcc
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user