diff --git a/Library/Homebrew/brewkit.rb b/Library/Homebrew/brewkit.rb index 1ff6e0af23..bc208236a5 100644 --- a/Library/Homebrew/brewkit.rb +++ b/Library/Homebrew/brewkit.rb @@ -17,13 +17,38 @@ require 'osx/cocoa' # to get number of cores require 'formula' +require 'hw.model' + +ENV['MACOSX_DEPLOYMENT_TARGET']='10.5' +ENV['CFLAGS']='-O3 -w -pipe -fomit-frame-pointer -mmacosx-version-min=10.5' +ENV['LDFLAGS']='' # to be consistent, we ignore the environment usually already # 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.0.1/gcc/i386-and-x86_002d64-Options.html -ENV['MACOSX_DEPLOYMENT_TARGET']='10.5' -ENV['CFLAGS']=ENV['CXXFLAGS']='-O3 -w -pipe -fomit-frame-pointer -march=prescott -mmacosx-version-min=10.5' +# http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/i386-and-x86_002d64-Options.html +case hw_model + when :core1 + # Core DUO is a 32 bit chip + ENV['CFLAGS']="#{ENV['CFLAGS']} -march=prescott -mfpmath=sse -msse3 -mmmx" + when :core2 + # Core 2 DUO is a 64 bit chip + # GCC 4.3 will have a -march=core2, but for now nocona is correct + ENV['CFLAGS']="#{ENV['CFLAGS']} -march=nocona -mfpmath=sse -msse3 -mmmx" + + # OK so we're not doing 64 bit yet... but we will with Snow Leopard + # -mfpmath=sse defaults to on for the x64 compiler + #ENV['CFLAGS']="#{ENV['CFLAGS']} -march=nocona -msse3 -mmmx -m64" + #ENV['LDFLAGS']="-arch x86_64" + + when :xeon, :macpro + # TODO what optimisations for xeon? + + 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!" +end + +ENV['CXXFLAGS']=ENV['CFLAGS'] # lets use gcc 4.2, it is newer and "better", at least I believe so, mail me # if I'm wrong @@ -31,11 +56,13 @@ ENV['CC']='gcc-4.2' ENV['CXX']='g++-4.2' ENV['MAKEFLAGS']="-j#{OSX::NSProcessInfo.processInfo.processorCount}" + unless HOMEBREW_PREFIX == '/usr/local' ENV['CPPFLAGS']="-I#{HOMEBREW_PREFIX}/include" ENV['LDFLAGS']="-L#{HOMEBREW_PREFIX}/lib" end + def inreplace(path, before, after) before=Regexp.escape before.to_s after=Regexp.escape after.to_s diff --git a/Library/Homebrew/env.rb b/Library/Homebrew/env.rb index 7ff57071eb..a9cb6aa915 100644 --- a/Library/Homebrew/env.rb +++ b/Library/Homebrew/env.rb @@ -18,6 +18,7 @@ require 'pathname+yeast' require 'utils' +# TODO if whoami == root then use /Library/Caches/Homebrew instead HOMEBREW_VERSION='0.3' HOMEBREW_CACHE=File.expand_path "~/Library/Caches/Homebrew" HOMEBREW_PREFIX=Pathname.new(__FILE__).dirname.parent.parent.realpath diff --git a/Library/Homebrew/hw.model.c b/Library/Homebrew/hw.model.c new file mode 100644 index 0000000000..12436057b8 --- /dev/null +++ b/Library/Homebrew/hw.model.c @@ -0,0 +1,12 @@ +#include +#include + +int main() +{ + char buf[32]; + size_t sz = sizeof(buf); + int r = sysctlbyname("hw.model", buf, &sz, NULL, 0); + if (r == 0) + printf("%.*s", sz, buf); + return r; +} diff --git a/Library/Homebrew/hw.model.rb b/Library/Homebrew/hw.model.rb new file mode 100644 index 0000000000..87e6a6b3c7 --- /dev/null +++ b/Library/Homebrew/hw.model.rb @@ -0,0 +1,82 @@ +def hw_model_output + exe=Pathname.new(HOMEBREW_CACHE)+'hw.model' + Kernel.system "gcc -Os #{File.dirname __FILE__}/hw.model.c -o #{exe}" unless exe.file? + /(.*)(\d+),(\d+)/ =~ `#{exe}` + yield $1, $2.to_i, $3.to_i +end + +# http://support.apple.com/kb/HT3696 +# http://www.cocoadev.com/index.pl?MacintoshModels +def hw_model + hw_model_output do |model, major, minor| + case model + when "iMac" + if major <=4 + :core1 + elsif major <=8 + :core2 + else + $unknown_hw_model=true + :core2 + end + + when "MacBookAir" + if major <= 1 + :core2 + else + $unknown_hw_model=true + :core2 + end + + when "MacBook" + if major <= 1 + :core1 + elsif major <= 4 + :core2 + else + $unknown_hw_model=true + :core2 + end + + when "MacBookPro" + if major <= 1 + :core1 + elsif major <= 5 + :core2 + else + $unknown_hw_model=true + :core2 + end + + when "Macmini" # Mac mini (Core Duo/Solo) + if major <= 1 + :core + else + $unknown_hw_model=true + :core + end + + when "MacPro" + if major <= 3 + :xeon + else + $unknown_hw_model=true + :xeon + end + + when "PowerBook", "PowerMac", "RackMac" then :ppc + + when "Xserve" + if major <=2 + :xeon + else + $unknown_hw_model=true + :xeon + end + + when "ADP" then :dunno # Developer Transition Kit + when "M43ADP" then :dunno # Development Mac Pro + else :dunno + end + end +end