From 11f8b2f49c57bd09b79d0aac2ecd11869d9289d2 Mon Sep 17 00:00:00 2001 From: Misty De Meo Date: Tue, 4 Jun 2013 10:18:14 -0500 Subject: [PATCH] Experimental support for non-Apple GCCs --- Library/ENV/4.3/cc | 6 ++---- Library/Homebrew/extend/ENV/shared.rb | 26 +++++++++++++++++++++++++- Library/Homebrew/extend/ENV/std.rb | 4 ++++ Library/Homebrew/extend/ENV/super.rb | 4 ++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Library/ENV/4.3/cc b/Library/ENV/4.3/cc index 835079617b..8075017d8e 100755 --- a/Library/ENV/4.3/cc +++ b/Library/ENV/4.3/cc @@ -68,10 +68,8 @@ class Cmd 'clang++' when /llvm-gcc/ 'llvm-g++-4.2' - when /gcc(-4.2)?$/ - 'g++-4.2' - when /gcc-4.0/ - 'g++-4.0' + when /gcc(-\d\.\d)?$/ + 'g++' + $1.to_s end else @arg0 diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 12fc7446ae..7e8b4e0958 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -2,7 +2,7 @@ module SharedEnvExtension CC_FLAG_VARS = %w{CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS} 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', /(gcc-\d\.\d)/] COMPLER_ALIASES = {'gcc' => 'gcc-4.2', 'llvm' => 'llvm-gcc'} COMPILER_SYMBOL_MAP = { 'gcc-4.0' => :gcc_4_0, 'gcc-4.2' => :gcc, @@ -150,4 +150,28 @@ module SharedEnvExtension flags.each { |key| self[key] = cflags } set_cpu_flags(flags) end + + def warn_about_non_apple_gcc(gcc) + opoo "Experimental support for non-Apple GCC enabled. Some builds may fail!" + + begin + gcc_name = 'gcc' + gcc.delete('.') + gcc = Formula.factory(gcc_name) + if !gcc.installed? + raise <<-EOS.undent + The requested Homebrew GCC, #{gcc_name}, was not installed. + You must: + brew tap homebrew/versions + brew install #{gcc_name} + EOS + end + + ENV.append('PATH', gcc.opt_prefix/'bin', ':') + rescue FormulaUnavailableError + raise <<-EOS.undent + Homebrew GCC requested, but formula #{gcc_name} not found! + You may need to: brew tap homebrew/versions + EOS + end + end end diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 97c1bf615d..67ab85952a 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -68,6 +68,10 @@ module Stdenv self.cxx = MacOS.locate("c++") end + if self['CC'] =~ GNU_GCC_REGEXP + warn_about_non_apple_gcc($1) + end + # Add lib and include etc. from the current macosxsdk to compiler flags: macosxsdk MacOS.version diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index e82f5508e9..49a59017c3 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -109,6 +109,10 @@ module Superenv end append_path('PATH', apple_gcc42.opt_prefix/'bin') if apple_gcc42 end + + if ENV['HOMEBREW_CC'] =~ /gcc-(\d\.\d)/ && $1 != '4.2' + warn_about_non_apple_gcc($1) + end end def universal_binary