Fix some "GCC cannot create executables"

This regards Issue Homebrew/homebrew#30.

Turns out -march=native isn't supported by Apple's GCC, but while investigating it I found they'd back ported the -march=core2 option, so we win anyway.

Logic reverted to how it was yesterday.

I moved the gcc options stuff back to brewkit.rb as we manipulate the cflags more later and it seemed bad form to split the logic for this area over two files.

Additionally the brew command exits immediately on powerpc now. Brewkit doesn't throw as theoretically it is a useful library file for other projects.
This commit is contained in:
Max Howell 2009-09-03 22:39:49 +01:00
parent 18d9fbee98
commit a12569699e
3 changed files with 48 additions and 84 deletions

View File

@ -29,50 +29,56 @@ require 'hardware'
# TODO
# 1. Indeed, there should be an option to build 32 or 64 bit binaries
# 2. Homebrew will not support building 32 and 64 bit lipo'd binaries, I
# want to mind, but the simple fact is it is difficult to force most of the
# want to, but the simple fact is it is difficult to force most of the
# build systems we support to do it.
`/usr/bin/sw_vers -productVersion` =~ /(10\.\d+)(\.\d+)?/
MACOS_VERSION=$1.to_f
ENV['MACOSX_DEPLOYMENT_TARGET']=$1
ENV['MACOSX_DEPLOYMENT_TARGET']=MACOS_VERSION.to_s
ENV['LDFLAGS']='' # to be consistent, we ignore the existing environment
# this is first, so when you see it in output, you notice it
cflags='-O3'
cflags=%w[-O3]
# optimise all the way to eleven, references:
# http://en.gentoo-wiki.com/wiki/Safe_Cflags/Intel
# http://forums.mozillazine.org/viewtopic.php?f=12&t=577299
# http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/i386-and-x86_002d64-Options.html
if MACOS_VERSION >= 10.6
if Hardware.is_64bit?
# 64 bits baby!
cflags<<" -m64"
ENV['LDFLAGS']="-arch x86_64"
case Hardware.intel_family
when :penryn
cflags<<'-march=core2'<<'-msse4.1'
when :core2
cflags<<"-march=core2"<<'-msse4'
when :core1
cflags<<"-march=prescott"<<'-msse3'
end
ENV['LDFLAGS']="-arch x86_64"
cflags<<'-m64'<<'-mmmx'
else
# GCC 4.2.1 is smart and will figure out the right compile flags
# http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/i386-and-x86_002d64-Options.html
cflags<<"-march=native"
end
case Hardware.cpu_type
when :ppc then abort "Sorry, Homebrew does not support PowerPC architectures"
when :dunno then abort "Sorry, Homebrew cannot determine what kind of Mac this is!"
case Hardware.intel_family
when :penryn
cflags<<"-march=nocona"<<'-msse4.1'
when :core2
cflags<<"-march=nocona"<<'-msse4'
when :core1
cflags<<"-march=prescott"<<'-msse3'
end
# to be consistent with cflags, we ignore the existing environment
ENV['LDFLAGS']=""
cflags<<'-mmmx'<<"-mfpmath=sse"
# gcc 4.0 is the default on Leopard
ENV['CC']='gcc-4.2'
ENV['CXX']='g++-4.2'
end
# -w: keep signal to noise high
# -fomit-frame-pointer: we are not debugging this software, we are using it
ENV['CFLAGS']="#{cflags} -w -pipe -fomit-frame-pointer -mmacosx-version-min=#{MACOS_VERSION}"
ENV['CXXFLAGS']=ENV['CFLAGS']
ENV['CFLAGS']=ENV['CXXFLAGS']="#{cflags*' '} -w -pipe -fomit-frame-pointer -mmacosx-version-min=#{MACOS_VERSION}"
# lets use gcc 4.2, Xcode does after all
if MACOS_VERSION==10.5
ENV['CC']='gcc-4.2'
ENV['CXX']='g++-4.2'
end
# compile faster
ENV['MAKEFLAGS']="-j#{Hardware.processor_count}"
# /usr/local is always in the build system path
unless HOMEBREW_PREFIX.to_s == '/usr/local'
ENV['CPPFLAGS']="-I#{HOMEBREW_PREFIX}/include"
@ -88,23 +94,14 @@ module HomebrewEnvExtension
alias_method :j1, :deparallelize
def gcc_4_0_1
case MACOS_VERSION
when 10.5
self['CC']=nil
self['CXX']=nil
when 10.6..11.0
self['CC']='gcc-4.0'
self['CXX']='g++-4.0'
when 10.5
self['CC']=nil
self['CXX']=nil
when 10.6..11.0
self['CC']='gcc-4.0'
self['CXX']='g++-4.0'
remove_from_cflags '-march=core2' # we *should* add back in stuff but meh for now
end
# argh, we have to figure out the compile options ourselves and get
# rid of -march=native, so we optimise all the way to eleven, references:
# http://en.gentoo-wiki.com/wiki/Safe_Cflags/Intel
# http://forums.mozillazine.org/viewtopic.php?f=12&t=577299
# http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/i386-and-x86_002d64-Options.html
remove_from_cflags '-march=native'
append_to_cflags Hardware.gcc_march
append_to_cflags Hardware.gcc_msse
append_to_cflags Hardware.gcc_mmx
end
def osx_10_4
self['MACOSX_DEPLOYMENT_TARGET']=nil

View File

@ -60,41 +60,6 @@ class Hardware
@@processor_count ||= `/usr/sbin/sysctl -n hw.ncpu`.to_i
end
def self.gcc_march # what to pass to gcc
@@gcc_march ||= if self.cpu_type == :intel
case self.intel_family
when :core
" -march=prescott"
when :core2, :penryn, :nehalem
# GCC 4.3 has a -march=core2, but this isn't 4.3 and nocona is correct
" -march=nocona"
end
else
""
end
end
def self.gcc_msse # what to pass to gcc
# avoid sse4 for now in case it blows up
@@gcc_msse ||= if sysctl_bool("hw.optional.sse3")
" -msse3 -mfpmath=sse"
else
""
end
end
def self.gcc_mmmx # what to pass to gcc
@@gcc_mmmx ||= if sysctl_bool("hw.optional.mmx")
" -mmmx"
else
""
end
end
def self.is_64bit?
@@is_64bit ||= sysctl_bool("hw.cpu64bit_capable")
end
protected
def self.sysctl_bool(property)
result = nil

View File

@ -1,9 +1,9 @@
#!/usr/bin/ruby
$:.unshift ENV['RUBYLIB']=File.expand_path(__FILE__+'/../../Library/Homebrew')
require 'pathname+yeast'
require 'ARGV+yeast'
require 'utils'
require 'hardware'
require 'brew.h'
if Process.uid == 0
@ -20,17 +20,19 @@ HOMEBREW_VERSION='0.4'
HOMEBREW_WWW='http://bit.ly/Homebrew'
HOMEBREW_USER_AGENT="Homebrew #{HOMEBREW_VERSION} (Ruby #{VERSION}; Mac OS X 10.5 Leopard)"
if %w[/ /usr].include? HOMEBREW_PREFIX.to_s then abort <<-troba
You have placed Homebrew at the prefix: #{HOMEBREW_PREFIX}
This is not currently supported. Voice your support for this feature at:
#{HOMEBREW_WWW}
troba
if %w[/ /usr].include? HOMEBREW_PREFIX.to_s then abort <<-EOS
You have placed Homebrew at the prefix: #{HOMEBREW_PREFIX}
This is not currently supported. Voice your support for this feature at:
#{HOMEBREW_WWW}
EOS
end
if `sw_vers -productVersion` =~ /10\.(\d)\.(\d+)/ and $1.to_i < 5
onoe "Homebrew requires Leopard or higher"
abort "But thanks for your interest anyway!"
end
if Hardware.cpu_type == :ppc or Hardware.cpu_type == :dunno
abort "Sorry, Homebrew does not support your computer's CPU architecture."
end
begin