aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend
diff options
context:
space:
mode:
authorMax Howell2012-02-16 23:39:57 +0000
committerMax Howell2012-02-16 23:43:43 +0000
commit4504662033ae7e82659548d70dd1475e8c3a6e12 (patch)
tree0988d5b504b0946a0ea3ea75a0da90be802f4b76 /Library/Homebrew/extend
parent59bd97bb893fd12e99d446aaa8abceb73c5b7afa (diff)
downloadbrew-4504662033ae7e82659548d70dd1475e8c3a6e12.tar.bz2
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.
Diffstat (limited to 'Library/Homebrew/extend')
-rw-r--r--Library/Homebrew/extend/ENV.rb61
1 files changed, 46 insertions, 15 deletions
diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb
index c41b79f12..8a599fa81 100644
--- a/Library/Homebrew/extend/ENV.rb
+++ b/Library/Homebrew/extend/ENV.rb
@@ -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'