From 63b903115951799b126482e3f9be1890c6178220 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Mon, 27 May 2013 15:17:49 -0500 Subject: [PATCH] superenv: find Homebrew's gcc-4.2 If we're using a homebrewed gcc-4.2, xcrun may fail to find it (or, worse, find superenv's shim instead). Explicitly add it to the PATH and search all path elements for the requested tool. Also make sure to specify 'gcc-4.2' as the compiler name, not plain 'gcc'. That can resolve to llvm-gcc and to gcc-4.0 on various Xcodes. --- Library/ENV/4.3/xcrun | 6 +++++- Library/Homebrew/superenv.rb | 21 ++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Library/ENV/4.3/xcrun b/Library/ENV/4.3/xcrun index 6afb6cf162..4784cd4d50 100755 --- a/Library/ENV/4.3/xcrun +++ b/Library/ENV/4.3/xcrun @@ -21,7 +21,11 @@ try `/usr/bin/xcrun --find #{arg0}`.chomp # Nuts, Xcode is not setup properly or something. Try to find the tools anyway! try "#{ENV['DEVELOPER_DIR']}/usr/bin/#{arg0}" try "#{ENV['DEVELOPER_DIR']}/Toolchains/XcodeDefault.xctoolchain/usr/bin/#{arg0}" -try "/usr/bin/#{arg0}" +# xcrun won't always be able to find Homebrew's apple-gcc42, +# even when it's in the PATH +ENV['PATH'].split(':').each do |p| + try "#{p}/#{arg0}" +end abort <<-EOS Your Xcode and or CLT are mis-configured. Try some or all of the following: diff --git a/Library/Homebrew/superenv.rb b/Library/Homebrew/superenv.rb index 8c3d131df5..4cb3f9a45b 100644 --- a/Library/Homebrew/superenv.rb +++ b/Library/Homebrew/superenv.rb @@ -61,6 +61,13 @@ class << ENV ENV['CMAKE_INCLUDE_PATH'] = determine_cmake_include_path ENV['CMAKE_LIBRARY_PATH'] = determine_cmake_library_path ENV['ACLOCAL_PATH'] = determine_aclocal_path + + # Homebrew's apple-gcc42 will be outside the PATH in superenv, + # so xcrun may not be able to find it + if ENV['HOMEBREW_CC'] == 'gcc-4.2' && !MacOS.locate('gcc-4.2') + apple_gcc42 = Formula.factory('apple-gcc42') rescue nil + ENV.append('PATH', apple_gcc42.opt_prefix/'bin', ':') if apple_gcc42 + end end def universal_binary @@ -76,8 +83,13 @@ class << ENV def determine_cc if ARGV.include? '--use-gcc' + gcc_installed = Formula.factory('apple-gcc42').installed? rescue false # fall back to something else on systems without Apple gcc - MacOS.locate('gcc-4.2') ? "gcc-4.2" : raise("gcc-4.2 not found!") + 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' @@ -93,7 +105,10 @@ class << ENV "gcc" elsif ENV['HOMEBREW_CC'] case ENV['HOMEBREW_CC'] - when 'clang', 'gcc', 'gcc-4.0' then ENV['HOMEBREW_CC'] + when 'clang', 'gcc-4.0' then ENV['HOMEBREW_CC'] + # depending on Xcode version plain 'gcc' could actually be + # gcc-4.0 or llvm-gcc + when 'gcc' then 'gcc-4.2' when 'llvm', 'llvm-gcc' then 'llvm-gcc' else opoo "Invalid value for HOMEBREW_CC: #{ENV['HOMEBREW_CC']}" @@ -106,7 +121,7 @@ class << ENV case MacOS.default_compiler when :clang then 'clang' when :llvm then 'llvm-gcc' - when :gcc then 'gcc' + when :gcc then 'gcc-4.2' when :gcc_4_0 then 'gcc-4.0' end end