aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/brewkit.rb
diff options
context:
space:
mode:
authorspicyj2009-09-02 13:17:15 -0600
committerMax Howell2009-09-03 16:34:31 +0100
commitba8ba4c4516ea337910eca02c17ae879ae095cb6 (patch)
treef506e7970356fd608e56f362a6336fe4d6e106c6 /Library/Homebrew/brewkit.rb
parent91d9a707b62e3152c7a026bf0b6698944d1b3f87 (diff)
downloadbrew-ba8ba4c4516ea337910eca02c17ae879ae095cb6.tar.bz2
Improvements to build environment determination
Simplified hardware model testing. Even smarter compiler option generation using sysctl and new GCC 4.2 features. Get processor count from sysctl and thus remove our dependency on RubyCocoa.
Diffstat (limited to 'Library/Homebrew/brewkit.rb')
-rw-r--r--Library/Homebrew/brewkit.rb84
1 files changed, 42 insertions, 42 deletions
diff --git a/Library/Homebrew/brewkit.rb b/Library/Homebrew/brewkit.rb
index 6d80a1233..18d30a4d1 100644
--- a/Library/Homebrew/brewkit.rb
+++ b/Library/Homebrew/brewkit.rb
@@ -21,11 +21,10 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
-require 'osx/cocoa' # to get number of cores
require 'fileutils'
require 'formula'
require 'download_strategy'
-require 'hw.model'
+require 'hardware'
# TODO
# 1. Indeed, there should be an option to build 32 or 64 bit binaries
@@ -34,7 +33,7 @@ require 'hw.model'
# build systems we support to do it.
-`sw_vers -productVersion` =~ /(10\.\d+)(\.\d+)?/
+`/usr/bin/sw_vers -productVersion` =~ /(10\.\d+)(\.\d+)?/
MACOS_VERSION=$1.to_f
ENV['MACOSX_DEPLOYMENT_TARGET']=MACOS_VERSION.to_s
@@ -43,33 +42,21 @@ 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'
-# 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
-case hw_model
- when :core1
- # Core DUO is a 32 bit chip
- # NOTE technically we can do -msse4 with gcc 4.2, but I can't test it, so
- # haven't tried it, if you have a core1 chip, then please test and commit --mxcl
- cflags<<" -march=prescott -mfpmath=sse -msse3 -mmmx"
- when :core2
- # Core 2 DUO is a 64 bit chip
- if MACOS_VERSION >= 10.6
- # 64 bits baby! -mfpmath=sse is automatically switched on by -m64
- # GCC 4.3 has a -march=core2, but this is 4.2 and nocona is correct
- cflags<<" -m64 -march=nocona -msse4 -mmmx"
- ENV['LDFLAGS']="-arch x86_64"
- else
- # We don't build 64 bit before 10.6 as nothing else is 64 bit, so any
- # libraries we build would be unusable by 32 bit software
- cflags<<" -march=nocona -mfpmath=sse -msse3 -mmmx"
- end
- when :xeon
- # TODO what optimisations for xeon?
+if MACOS_VERSION >= 10.6
+ if Hardware.is_64bit?
+ # 64 bits baby!
+ cflags<<" -m64"
+ ENV['LDFLAGS']="-arch x86_64"
+ end
+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
- 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.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!"
end
# -w: keep signal to noise high
@@ -77,14 +64,13 @@ end
ENV['CFLAGS']="#{cflags} -w -pipe -fomit-frame-pointer -mmacosx-version-min=#{MACOS_VERSION}"
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
+# 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#{OSX::NSProcessInfo.processInfo.processorCount}"
+ENV['MAKEFLAGS']="-j#{Hardware.processor_count}"
# /usr/local is always in the build system path
@@ -109,6 +95,16 @@ module HomebrewEnvExtension
self['CC']='gcc-4.0'
self['CXX']='g++-4.0'
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
@@ -118,10 +114,11 @@ module HomebrewEnvExtension
%w[-mfpmath=sse -msse3 -mmmx -march=\w+].each {|s| remove_from_cflags s}
end
def libxml2
- self['CXXFLAGS']=self['CFLAGS']+=' -I/usr/include/libxml2'
+ append_to_cflags ' -I/usr/include/libxml2'
end
# TODO rename or alias to x11
def libpng
+ # CPPFLAGS are the C-PreProcessor flags, *not* C++!
append 'CPPFLAGS', '-I/usr/X11R6/include'
append 'LDFLAGS', '-L/usr/X11R6/lib'
end
@@ -129,7 +126,7 @@ module HomebrewEnvExtension
def enable_warnings
remove_from_cflags '-w'
end
-
+
private
def append key, value
ref=self[key]
@@ -139,14 +136,18 @@ private
self[key]=ref+' '+value
end
end
- def remove key, rx
+ def append_to_cflags f
+ append 'CFLAGS', f
+ append 'CXXFLAGS', f
+ end
+ def remove key, value
return if self[key].nil?
- # sub! doesn't work as "the string is frozen"
- self[key]=self[key].sub rx, ''
+ self[key]=self[key].sub value, '' # can't use sub! on ENV
self[key]=nil if self[key].empty? # keep things clean
end
- def remove_from_cflags rx
- %w[CFLAGS CXXFLAGS].each {|key| remove key, rx}
+ def remove_from_cflags f
+ remove 'CFLAGS', f
+ remove 'CXXFLAGS', f
end
end
@@ -157,7 +158,7 @@ ENV.extend HomebrewEnvExtension
# http://github.com/mxcl/homebrew/issues/#issue/13
paths=ENV['PATH'].split(':').reject do |p|
p.squeeze! '/'
- p=~%r[^/opt/local] or p=~%r[^/sw]
+ p =~ %r[^/opt/local] or p =~ %r[^/sw]
end
ENV['PATH']=paths*':'
@@ -169,7 +170,6 @@ def inreplace(path, before, after)
after.gsub! "\\", "\\\\"
after.gsub! "/", "\\/"
- # TODO this sucks
- # either use 'ed', or allow regexp and use a proper ruby function
+ # FIXME use proper Ruby for teh exceptions!
safe_system "perl", "-pi", "-e", "s/#{before}/#{after}/g", path
end