2009-08-31 16:01:36 +01:00
|
|
|
# Copyright 2009 Max Howell and other contributors.
|
2009-06-04 19:21:19 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
2009-06-04 19:21:19 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
2009-06-04 19:21:19 +01:00
|
|
|
#
|
2009-08-31 16:01:36 +01:00
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2009-08-10 16:48:21 +01:00
|
|
|
#
|
2009-09-02 14:15:44 +01:00
|
|
|
require 'fileutils'
|
2009-07-24 15:10:01 +01:00
|
|
|
require 'formula'
|
2009-08-21 20:30:13 +01:00
|
|
|
require 'download_strategy'
|
2009-09-02 13:17:15 -06:00
|
|
|
require 'hardware'
|
2009-07-31 16:06:14 +01:00
|
|
|
|
2009-09-02 14:15:44 +01:00
|
|
|
# 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
|
2009-09-03 22:39:49 +01:00
|
|
|
# want to, but the simple fact is it is difficult to force most of the
|
2009-09-02 14:15:44 +01:00
|
|
|
# build systems we support to do it.
|
|
|
|
|
|
|
|
|
2009-09-16 11:28:50 +01:00
|
|
|
ENV['MACOSX_DEPLOYMENT_TARGET']=MACOS_VERSION.to_s
|
2009-09-02 14:15:44 +01:00
|
|
|
|
2009-09-04 15:42:19 +01:00
|
|
|
# ignore existing build vars, thus we should have less bugs to deal with
|
2009-09-04 01:15:40 -04:00
|
|
|
ENV['LDFLAGS']=""
|
|
|
|
|
2009-09-03 22:39:49 +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
|
|
|
|
# http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/i386-and-x86_002d64-Options.html
|
2009-09-05 12:26:13 +01:00
|
|
|
cflags=[]
|
2009-09-02 13:17:15 -06:00
|
|
|
if MACOS_VERSION >= 10.6
|
2009-09-03 22:39:49 +01:00
|
|
|
case Hardware.intel_family
|
2009-09-03 19:31:43 -06:00
|
|
|
when :penryn, :core2
|
2009-09-04 01:15:40 -04:00
|
|
|
# no need to add -mfpmath when you specify -m64
|
|
|
|
cflags<<"-march=core2"<<'-m64'
|
|
|
|
ENV['LDFLAGS']="-arch x86_64"
|
2009-09-03 19:31:43 -06:00
|
|
|
when :core
|
2009-09-04 01:15:40 -04:00
|
|
|
cflags<<"-march=prescott"<<"-mfpmath=sse"
|
2009-09-02 13:17:15 -06:00
|
|
|
end
|
|
|
|
else
|
2009-09-03 22:39:49 +01:00
|
|
|
case Hardware.intel_family
|
2009-09-03 19:31:43 -06:00
|
|
|
when :penryn, :core2
|
|
|
|
cflags<<"-march=nocona"
|
|
|
|
when :core
|
|
|
|
cflags<<"-march=prescott"
|
2009-09-03 22:39:49 +01:00
|
|
|
end
|
2009-09-03 19:31:43 -06:00
|
|
|
cflags<<"-mfpmath=sse"
|
2009-09-04 15:42:19 +01:00
|
|
|
|
2009-09-04 09:46:53 -07:00
|
|
|
ENV['CC']="gcc-4.2"
|
|
|
|
ENV['CXX']="g++-4.2"
|
2009-09-03 19:31:43 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
cflags<<"-mmmx"
|
|
|
|
case Hardware.intel_family
|
2009-09-04 09:46:53 -07:00
|
|
|
when :nehalem
|
|
|
|
cflags<<"-msse4.2"
|
2009-09-03 19:31:43 -06:00
|
|
|
when :penryn
|
|
|
|
cflags<<"-msse4.1"
|
|
|
|
when :core2, :core
|
|
|
|
cflags<<"-msse3"
|
2009-07-31 16:06:14 +01:00
|
|
|
end
|
|
|
|
|
2009-09-02 14:15:44 +01:00
|
|
|
# -w: keep signal to noise high
|
|
|
|
# -fomit-frame-pointer: we are not debugging this software, we are using it
|
2009-09-05 12:26:13 +01:00
|
|
|
BREWKIT_SAFE_FLAGS="-w -pipe -fomit-frame-pointer -mmacosx-version-min=#{MACOS_VERSION}"
|
|
|
|
ENV['CFLAGS']=ENV['CXXFLAGS']="-O3 #{cflags*' '} #{BREWKIT_SAFE_FLAGS}"
|
2009-05-22 00:14:57 +01:00
|
|
|
|
2009-09-02 14:15:44 +01:00
|
|
|
# compile faster
|
2009-09-02 13:17:15 -06:00
|
|
|
ENV['MAKEFLAGS']="-j#{Hardware.processor_count}"
|
2009-05-22 00:14:57 +01:00
|
|
|
|
2009-09-02 14:15:44 +01:00
|
|
|
# /usr/local is always in the build system path
|
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
|
2009-09-02 23:20:15 +01:00
|
|
|
alias_method :j1, :deparallelize
|
2009-08-10 16:48:21 +01:00
|
|
|
def gcc_4_0_1
|
2009-09-02 14:15:44 +01:00
|
|
|
case MACOS_VERSION
|
2009-09-03 22:39:49 +01:00
|
|
|
when 10.5
|
|
|
|
self['CC']=nil
|
|
|
|
self['CXX']=nil
|
|
|
|
when 10.6..11.0
|
|
|
|
self['CC']='gcc-4.0'
|
|
|
|
self['CXX']='g++-4.0'
|
2009-09-04 09:46:53 -07:00
|
|
|
remove_from_cflags '-march=core2'
|
2009-09-02 14:15:44 +01:00
|
|
|
end
|
2009-09-04 09:46:53 -07:00
|
|
|
remove_from_cflags '-msse4.1'
|
|
|
|
remove_from_cflags '-msse4.2'
|
2009-08-10 16:48:21 +01:00
|
|
|
end
|
2009-09-07 10:48:22 -05:00
|
|
|
def llvm_gcc
|
|
|
|
if (10.6..11.0).include?(MACOS_VERSION)
|
|
|
|
self['CC']='/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2'
|
|
|
|
self['CXX']='/Developer/usr/llvm-gcc-4.2/bin/llvm-g++-4.2'
|
|
|
|
else
|
|
|
|
raise "LLVM support is only available on 10.6+"
|
|
|
|
end
|
|
|
|
end
|
2009-08-10 16:48:21 +01:00
|
|
|
def osx_10_4
|
|
|
|
self['MACOSX_DEPLOYMENT_TARGET']=nil
|
|
|
|
remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/)
|
|
|
|
end
|
2009-09-05 12:26:13 +01:00
|
|
|
def minimal_optimization
|
|
|
|
self['CFLAGS']=self['CXXFLAGS']="-Os #{BREWKIT_SAFE_FLAGS}"
|
|
|
|
|
|
|
|
end
|
|
|
|
def no_optimization
|
|
|
|
self['CFLAGS']=self['CXXFLAGS']=BREWKIT_SAFE_FLAGS
|
2009-08-10 16:48:21 +01:00
|
|
|
end
|
2009-08-07 15:41:43 +01:00
|
|
|
def libxml2
|
2009-09-02 13:17:15 -06:00
|
|
|
append_to_cflags ' -I/usr/include/libxml2'
|
2009-08-07 15:41:43 +01:00
|
|
|
end
|
2009-09-21 20:55:41 -07:00
|
|
|
def x11
|
2009-09-02 13:17:15 -06:00
|
|
|
# CPPFLAGS are the C-PreProcessor flags, *not* C++!
|
2009-08-08 14:08:45 +01:00
|
|
|
append 'CPPFLAGS', '-I/usr/X11R6/include'
|
|
|
|
append 'LDFLAGS', '-L/usr/X11R6/lib'
|
|
|
|
end
|
2009-09-21 20:55:41 -07:00
|
|
|
alias_method :libpng, :x11
|
2009-08-07 15:41:43 +01:00
|
|
|
# we've seen some packages fail to build when warnings are disabled!
|
|
|
|
def enable_warnings
|
|
|
|
remove_from_cflags '-w'
|
|
|
|
end
|
2009-09-21 23:50:57 +01:00
|
|
|
# returns the compiler we're using
|
|
|
|
def cc
|
|
|
|
ENV['CC'] or "gcc"
|
|
|
|
end
|
2009-09-02 13:17:15 -06:00
|
|
|
|
2009-08-10 16:48:21 +01:00
|
|
|
private
|
2009-08-08 14:08:45 +01:00
|
|
|
def append key, value
|
|
|
|
ref=self[key]
|
|
|
|
if ref.nil? or ref.empty?
|
|
|
|
self[key]=value
|
|
|
|
else
|
|
|
|
self[key]=ref+' '+value
|
|
|
|
end
|
|
|
|
end
|
2009-09-02 13:17:15 -06:00
|
|
|
def append_to_cflags f
|
|
|
|
append 'CFLAGS', f
|
|
|
|
append 'CXXFLAGS', f
|
|
|
|
end
|
|
|
|
def remove key, value
|
2009-08-08 14:08:45 +01:00
|
|
|
return if self[key].nil?
|
2009-09-02 13:17:15 -06:00
|
|
|
self[key]=self[key].sub value, '' # can't use sub! on ENV
|
2009-08-10 16:48:21 +01:00
|
|
|
self[key]=nil if self[key].empty? # keep things clean
|
|
|
|
end
|
2009-09-02 13:17:15 -06:00
|
|
|
def remove_from_cflags f
|
|
|
|
remove 'CFLAGS', f
|
|
|
|
remove 'CXXFLAGS', f
|
2009-08-10 16:48:21 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
ENV.extend HomebrewEnvExtension
|
|
|
|
|
2009-09-02 14:15:44 +01:00
|
|
|
|
2009-09-11 11:10:20 -05:00
|
|
|
# Clear CDPATH to avoid make issues that depend on changing directories
|
|
|
|
ENV.delete('CDPATH')
|
2009-08-10 16:48:21 +01:00
|
|
|
|
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
|
2009-08-10 23:32:13 +01:00
|
|
|
before.gsub! "/", "\\/" # I guess not escaped as delimiter varies
|
|
|
|
after=after.to_s
|
2009-08-08 16:23:16 +01:00
|
|
|
after.gsub! "\\", "\\\\"
|
|
|
|
after.gsub! "/", "\\/"
|
2009-09-14 18:07:07 +01:00
|
|
|
after.gsub! "$", "\\$"
|
2009-07-27 16:18:47 +01:00
|
|
|
|
2009-09-02 13:17:15 -06:00
|
|
|
# FIXME use proper Ruby for teh exceptions!
|
2009-09-23 16:44:10 +01:00
|
|
|
safe_system "/usr/bin/perl", "-pi", "-e", "s/#{before}/#{after}/g", path
|
2009-05-21 00:04:43 +01:00
|
|
|
end
|