Skip to content

Commit

Permalink
Find the dev tools, even with Xcode 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Feb 16, 2012
1 parent 52392ae commit 968274d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 21 deletions.
23 changes: 15 additions & 8 deletions Library/Homebrew/extend/ENV.rb
Expand Up @@ -22,11 +22,14 @@ def setup_build_environment
# Os is the default Apple uses for all its stuff so let's trust them
self['CFLAGS'] = self['CXXFLAGS'] = "-Os #{SAFE_CFLAGS_FLAGS}"

# set us up for the user's compiler choice
self.send self.compiler

# we must have a working compiler!
unless File.exist? ENV['CC'] and File.exist? ENV['CXX']
@compiler = MacOS.default_compiler
self.send @compiler

ENV['CC'] = '/usr/bin/cc'
ENV['CXX'] = '/usr/bin/c++'
end
Expand Down Expand Up @@ -75,17 +78,21 @@ def Og
end

def gcc_4_0_1
self['CC'] = '/usr/bin/gcc-4.0'
self['CXX'] = '/usr/bin/g++-4.0'
self['CC'] = "#{MacOS.dev_tools_path}/gcc-4.0"
self['CXX'] = "#{MacOS.dev_tools_path}/g++-4.0"
replace_in_cflags '-O4', '-O3'
set_cpu_cflags 'nocona -mssse3', :core => 'prescott', :bottle => 'generic'
@compiler = :gcc
end
alias_method :gcc_4_0, :gcc_4_0_1

def gcc args = {}
gcc_path = Pathname.new "/usr/bin/gcc-4.2"
gxx_path = Pathname.new "/usr/bin/g++-4.2"
# 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'
replace_in_cflags '-O4', '-O3'
Expand All @@ -98,15 +105,15 @@ def gcc args = {}
alias_method :gcc_4_2, :gcc

def llvm
self['CC'] = "/usr/bin/llvm-gcc"
self['CXX'] = "/usr/bin/llvm-g++"
self['CC'] = "#{MacOS.dev_tools_path}/llvm-gcc"
self['CXX'] = "#{MacOS.dev_tools_path}/llvm-g++"
set_cpu_cflags 'core2 -msse4', :penryn => 'core2 -msse4.1', :core2 => 'core2', :core => 'prescott'
@compiler = :llvm
end

def clang args = {}
self['CC'] = "/usr/bin/clang"
self['CXX'] = "/usr/bin/clang++"
self['CC'] = "#{MacOS.dev_tools_path}/clang"
self['CXX'] = "#{MacOS.dev_tools_path}/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'
Expand Down
53 changes: 40 additions & 13 deletions Library/Homebrew/utils.rb
Expand Up @@ -251,30 +251,57 @@ def version
MACOS_VERSION
end

def dev_tools_path
@dev_tools_path ||= if File.file? "/usr/bin/cc" and File.file? "/usr/bin/make"
# probably a safe enough assumption
"/usr/bin"
elsif File.file? "#{xcode_prefix}/usr/bin/make"
# cc stopped existing with Xcode 4.3, there are c89 and c99 options though
"#{xcode_prefix}/usr/bin"
else
# yes this seems dumb, but we can't throw because the existance of
# dev tools is not mandatory for installing formula. Eventually we
# should make forumla specify if they need dev tools or not.
"/usr/bin"
end
end

def default_cc
Pathname.new("/usr/bin/cc").realpath.basename.to_s
cc = if !File.file? "/usr/bin/cc" and xcode_version > 4.3
# there is no cc file in Xcode 4.3.0 in the /Developer/usr/bin directory
"llvm-gcc"
else
"cc"
end
Pathname.new("#{dev_tools_path}/cc").realpath.basename.to_s
end

def default_compiler
case default_cc
when /^gcc/ then :gcc
when /^llvm/ then :llvm
when "clang" then :clang
else :gcc # a hack, but a sensible one prolly
else
# guess :(
if xcode_version > 4.2
:llvm
else
:gcc
end
end
end

def gcc_42_build_version
@gcc_42_build_version ||= if File.exist? "/usr/bin/gcc-4.2" \
and not Pathname.new("/usr/bin/gcc-4.2").realpath.basename.to_s =~ /^llvm/
`/usr/bin/gcc-4.2 --version` =~ /build (\d{4,})/
@gcc_42_build_version ||= if File.exist? "#{dev_tools_path}/gcc-4.2" \
and not Pathname.new("#{dev_tools_path}/gcc-4.2").realpath.basename.to_s =~ /^llvm/
`#{dev_tools_path}/gcc-4.2 --version` =~ /build (\d{4,})/
$1.to_i
end
end

def gcc_40_build_version
@gcc_40_build_version ||= if File.exist? "/usr/bin/gcc-4.0"
`/usr/bin/gcc-4.0 --version` =~ /build (\d{4,})/
@gcc_40_build_version ||= if File.exist? "#{dev_tools_path}/gcc-4.0"
`#{dev_tools_path}/gcc-4.0 --version` =~ /build (\d{4,})/
$1.to_i
end
end
Expand Down Expand Up @@ -332,22 +359,22 @@ def xcode_version
def llvm_build_version
# for Xcode 3 on OS X 10.5 this will not exist
# NOTE may not be true anymore but we can't test
@llvm_build_version ||= if File.exist? "/usr/bin/llvm-gcc"
`/usr/bin/llvm-gcc --version` =~ /LLVM build (\d{4,})/
@llvm_build_version ||= if File.exist? "#{dev_tools_path}/llvm-gcc"
`#{dev_tools_path}/llvm-gcc --version` =~ /LLVM build (\d{4,})/
$1.to_i
end
end

def clang_version
@clang_version ||= if File.exist? "/usr/bin/clang"
`/usr/bin/clang --version` =~ /clang version (\d\.\d)/
@clang_version ||= if File.exist? "#{dev_tools_path}/clang"
`#{dev_tools_path}/clang --version` =~ /clang version (\d\.\d)/
$1
end
end

def clang_build_version
@clang_build_version ||= if File.exist? "/usr/bin/clang"
`/usr/bin/clang --version` =~ %r[tags/Apple/clang-(\d{2,})]
@clang_build_version ||= if File.exist? "#{dev_tools_path}/clang"
`#{dev_tools_path}/clang --version` =~ %r[tags/Apple/clang-(\d{2,})]
$1.to_i
end
end
Expand Down

0 comments on commit 968274d

Please sign in to comment.