2009-06-04 19:21:19 +01:00
|
|
|
# Copyright 2009 Max Howell <max@methylblue.com>
|
|
|
|
#
|
|
|
|
# This file is part of Homebrew.
|
|
|
|
#
|
|
|
|
# Homebrew is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Homebrew is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Homebrew. If not, see <http://www.gnu.org/licenses/>.
|
2009-08-10 16:48:21 +01:00
|
|
|
#
|
2009-06-03 19:17:41 +01:00
|
|
|
require 'osx/cocoa' # to get number of cores
|
2009-07-24 15:10:01 +01:00
|
|
|
require 'formula'
|
2009-07-31 16:06:14 +01:00
|
|
|
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
|
2009-05-21 02:24:45 +01:00
|
|
|
|
2009-05-22 00:14:57 +01:00
|
|
|
# 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
|
2009-07-31 16:06:14 +01:00
|
|
|
# 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"
|
|
|
|
|
2009-08-01 17:54:44 +01:00
|
|
|
when :xeon
|
2009-07-31 16:06:14 +01:00
|
|
|
# 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']
|
2009-05-22 00:14:57 +01:00
|
|
|
|
|
|
|
# lets use gcc 4.2, it is newer and "better", at least I believe so, mail me
|
|
|
|
# if I'm wrong
|
|
|
|
ENV['CC']='gcc-4.2'
|
|
|
|
ENV['CXX']='g++-4.2'
|
2009-06-03 19:17:41 +01:00
|
|
|
ENV['MAKEFLAGS']="-j#{OSX::NSProcessInfo.processInfo.processorCount}"
|
2009-05-22 00:14:57 +01:00
|
|
|
|
2009-07-31 16:06:14 +01:00
|
|
|
|
2009-08-10 16:48:21 +01:00
|
|
|
unless HOMEBREW_PREFIX.to_s == '/usr/local'
|
2009-07-31 02:51:17 +01:00
|
|
|
ENV['CPPFLAGS']="-I#{HOMEBREW_PREFIX}/include"
|
|
|
|
ENV['LDFLAGS']="-L#{HOMEBREW_PREFIX}/lib"
|
2009-05-23 16:38:28 +01:00
|
|
|
end
|
2009-05-21 04:35:36 +01:00
|
|
|
|
2009-07-31 16:06:14 +01:00
|
|
|
|
2009-08-10 16:48:21 +01:00
|
|
|
# you can use these functions for packages that have build issues
|
|
|
|
module HomebrewEnvExtension
|
|
|
|
def deparallelize
|
|
|
|
remove 'MAKEFLAGS', /-j\d+/
|
|
|
|
end
|
|
|
|
def gcc_4_0_1
|
|
|
|
self['CC']=nil
|
|
|
|
self['CXX']=nil
|
|
|
|
end
|
|
|
|
def osx_10_4
|
|
|
|
self['MACOSX_DEPLOYMENT_TARGET']=nil
|
|
|
|
remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/)
|
|
|
|
end
|
|
|
|
def generic_i386
|
|
|
|
%w[-mfpmath=sse -msse3 -mmmx -march=\w+].each {|s| remove_from_cflags s}
|
|
|
|
end
|
|
|
|
private
|
|
|
|
def remove key, rx
|
|
|
|
# sub! doesn't work as "the string is frozen"
|
|
|
|
self[key]=self[key].sub rx, ''
|
|
|
|
self[key]=nil if self[key].empty? # keep things clean
|
|
|
|
end
|
|
|
|
def remove_from_cflags rx
|
|
|
|
%w[CFLAGS CXXFLAGS].each {|key| remove key, rx}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ENV.extend HomebrewEnvExtension
|
|
|
|
|
|
|
|
|
2009-05-21 00:04:43 +01:00
|
|
|
def inreplace(path, before, after)
|
2009-07-27 16:18:47 +01:00
|
|
|
before=Regexp.escape before.to_s
|
|
|
|
after=Regexp.escape after.to_s
|
2009-07-31 02:51:17 +01:00
|
|
|
before.gsub! "/", "\\\/"
|
|
|
|
after.gsub! "/", "\\\/"
|
|
|
|
before.gsub! "'", '\''
|
|
|
|
after.gsub! "'", '\''
|
2009-07-27 16:18:47 +01:00
|
|
|
|
|
|
|
# TODO this sucks
|
|
|
|
# either use 'ed', or allow regexp and use a proper ruby function
|
|
|
|
`perl -pi -e $'s/#{before}/#{after}/g' "#{path}"`
|
2009-05-21 00:04:43 +01:00
|
|
|
end
|