2009-10-15 12:36:09 +01:00
|
|
|
module HomebrewEnvExtension
|
|
|
|
# -w: keep signal to noise high
|
2009-12-02 12:17:14 +00:00
|
|
|
SAFE_CFLAGS_FLAGS = "-w -pipe"
|
2009-10-15 12:36:09 +01:00
|
|
|
|
|
|
|
def setup_build_environment
|
|
|
|
# Clear CDPATH to avoid make issues that depend on changing directories
|
|
|
|
ENV.delete('CDPATH')
|
2010-02-12 13:35:29 +00:00
|
|
|
ENV.delete('CPPFLAGS')
|
|
|
|
ENV.delete('LDFLAGS')
|
2009-10-15 12:36:09 +01:00
|
|
|
|
|
|
|
ENV['MAKEFLAGS']="-j#{Hardware.processor_count}"
|
|
|
|
|
|
|
|
unless HOMEBREW_PREFIX.to_s == '/usr/local'
|
2009-12-01 11:27:44 +00:00
|
|
|
# /usr/local is already an -isystem and -L directory so we skip it
|
|
|
|
ENV['CPPFLAGS'] = "-isystem #{HOMEBREW_PREFIX}/include"
|
2009-10-15 12:36:09 +01:00
|
|
|
ENV['LDFLAGS'] = "-L#{HOMEBREW_PREFIX}/lib"
|
2009-12-09 04:49:19 +01:00
|
|
|
# CMake ignores the variables above
|
|
|
|
ENV['CMAKE_PREFIX_PATH'] = "#{HOMEBREW_PREFIX}"
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
|
|
|
|
2010-02-12 13:35:29 +00:00
|
|
|
if MACOS_VERSION >= 10.6 and (ENV['HOMEBREW_USE_LLVM'] or ARGV.include? '--use-llvm')
|
2010-06-18 14:32:25 -07:00
|
|
|
xcode_path = `/usr/bin/xcode-select -print-path`.chomp
|
|
|
|
xcode_path = "/Developer" if xcode_path.to_s.empty?
|
|
|
|
ENV['CC'] = "#{xcode_path}/usr/bin/llvm-gcc"
|
|
|
|
ENV['CXX'] = "#{xcode_path}/usr/bin/llvm-g++"
|
|
|
|
ENV['LD'] = ENV['CC']
|
|
|
|
cflags = ['-O4'] # link time optimisation baby!
|
2009-10-15 12:36:09 +01:00
|
|
|
else
|
2010-02-24 15:05:21 +00:00
|
|
|
# if we don't set these, many formula fail to build
|
|
|
|
ENV['CC'] = '/usr/bin/cc'
|
|
|
|
ENV['CXX'] = '/usr/bin/c++'
|
2009-10-15 12:36:09 +01:00
|
|
|
cflags = ['-O3']
|
|
|
|
end
|
2010-02-12 13:35:29 +00:00
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
# in rare cases this may break your builds, as the tool for some reason wants
|
|
|
|
# to use a specific linker, however doing this in general causes formula to
|
|
|
|
# build more successfully because we are changing CC and many build systems
|
|
|
|
# don't react properly to that
|
2010-02-24 15:05:21 +00:00
|
|
|
ENV['LD'] = ENV['CC']
|
2009-10-15 12:36:09 +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
|
2010-02-12 13:35:29 +00:00
|
|
|
# we don't set, eg. -msse3 because the march flag does that for us
|
|
|
|
# http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/i386-and-x86_002d64-Options.html
|
2009-10-15 12:36:09 +01:00
|
|
|
if MACOS_VERSION >= 10.6
|
|
|
|
case Hardware.intel_family
|
2010-02-12 13:35:29 +00:00
|
|
|
when :nehalem, :penryn, :core2
|
|
|
|
# the 64 bit compiler adds -mfpmath=sse for us
|
2009-10-15 12:36:09 +01:00
|
|
|
cflags << "-march=core2"
|
|
|
|
when :core
|
|
|
|
cflags<<"-march=prescott"<<"-mfpmath=sse"
|
|
|
|
end
|
2010-02-12 13:35:29 +00:00
|
|
|
# gcc doesn't auto add msse4 or above (based on march flag) yet
|
|
|
|
case Hardware.intel_family
|
|
|
|
when :nehalem
|
|
|
|
cflags << "-msse4" # means msse4.2 and msse4.1
|
|
|
|
when :penryn
|
|
|
|
cflags << "-msse4.1"
|
|
|
|
end
|
2009-10-15 12:36:09 +01:00
|
|
|
else
|
2010-02-12 13:35:29 +00:00
|
|
|
# gcc 4.0 didn't support msse4
|
2009-10-15 12:36:09 +01:00
|
|
|
case Hardware.intel_family
|
2010-02-12 13:35:29 +00:00
|
|
|
when :nehalem, :penryn, :core2
|
2009-10-15 12:36:09 +01:00
|
|
|
cflags<<"-march=nocona"
|
|
|
|
when :core
|
|
|
|
cflags<<"-march=prescott"
|
|
|
|
end
|
|
|
|
cflags<<"-mfpmath=sse"
|
|
|
|
end
|
|
|
|
|
2009-12-02 12:17:14 +00:00
|
|
|
ENV['CFLAGS'] = ENV['CXXFLAGS'] = "#{cflags*' '} #{SAFE_CFLAGS_FLAGS}"
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def deparallelize
|
|
|
|
remove 'MAKEFLAGS', /-j\d+/
|
|
|
|
end
|
|
|
|
alias_method :j1, :deparallelize
|
2009-10-23 14:51:40 +01:00
|
|
|
|
2010-02-12 13:35:29 +00:00
|
|
|
# recommended by Apple, but, eg. wget won't compile with this flag, so…
|
|
|
|
def fast
|
|
|
|
remove_from_cflags /-O./
|
|
|
|
append_to_cflags '-fast'
|
|
|
|
end
|
2010-06-18 14:32:25 -07:00
|
|
|
def O4
|
|
|
|
# LLVM link-time optimization
|
|
|
|
remove_from_cflags /-O./
|
|
|
|
append_to_cflags '-O4'
|
|
|
|
end
|
2009-10-23 14:51:40 +01:00
|
|
|
def O3
|
|
|
|
# Sometimes O4 just takes fucking forever
|
2009-12-02 12:17:14 +00:00
|
|
|
remove_from_cflags /-O./
|
2009-10-23 14:51:40 +01:00
|
|
|
append_to_cflags '-O3'
|
|
|
|
end
|
|
|
|
def O2
|
|
|
|
# Sometimes O3 doesn't work or produces bad binaries
|
2009-12-02 12:17:14 +00:00
|
|
|
remove_from_cflags /-O./
|
2009-10-23 14:51:40 +01:00
|
|
|
append_to_cflags '-O2'
|
|
|
|
end
|
2009-12-02 12:17:14 +00:00
|
|
|
def Os
|
|
|
|
# Sometimes you just want a small one
|
|
|
|
remove_from_cflags /-O./
|
|
|
|
append_to_cflags '-Os'
|
|
|
|
end
|
2009-10-23 14:51:40 +01:00
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
def gcc_4_0_1
|
2010-02-12 13:35:29 +00:00
|
|
|
self['CC'] = self['LD'] = '/usr/bin/gcc-4.0'
|
|
|
|
self['CXX'] = '/usr/bin/g++-4.0'
|
|
|
|
self.O3
|
|
|
|
remove_from_cflags '-march=core2'
|
2010-03-17 15:29:35 -07:00
|
|
|
remove_from_cflags %r{-msse4(\.\d)?}
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
2009-12-02 10:39:06 +00:00
|
|
|
alias_method :gcc_4_0, :gcc_4_0_1
|
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
def gcc_4_2
|
|
|
|
# Sometimes you want to downgrade from LLVM to GCC 4.2
|
2010-02-12 13:35:29 +00:00
|
|
|
self['CC']="/usr/bin/gcc-4.2"
|
|
|
|
self['CXX']="/usr/bin/g++-4.2"
|
2009-10-15 12:36:09 +01:00
|
|
|
self['LD']=self['CC']
|
|
|
|
self.O3
|
|
|
|
end
|
2009-10-23 14:51:40 +01:00
|
|
|
|
2010-06-17 10:57:41 -05:00
|
|
|
def llvm
|
|
|
|
xcode_path = `/usr/bin/xcode-select -print-path`.chomp
|
|
|
|
xcode_path = "/Developer" if xcode_path.to_s.empty?
|
2010-06-18 14:32:25 -07:00
|
|
|
self['CC'] = "#{xcode_path}/usr/bin/llvm-gcc"
|
|
|
|
self['CXX'] = "#{xcode_path}/usr/bin/llvm-g++"
|
2010-06-17 10:57:41 -05:00
|
|
|
self['LD'] = self['CC']
|
2010-06-18 14:32:25 -07:00
|
|
|
self.O4
|
2010-06-17 10:57:41 -05:00
|
|
|
end
|
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
def osx_10_4
|
2009-10-23 14:51:40 +01:00
|
|
|
self['MACOSX_DEPLOYMENT_TARGET']="10.4"
|
2009-10-15 12:36:09 +01:00
|
|
|
remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/)
|
2009-10-23 14:51:40 +01:00
|
|
|
append_to_cflags('-mmacosx-version-min=10.4')
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
2009-10-23 14:51:40 +01:00
|
|
|
def osx_10_5
|
|
|
|
self['MACOSX_DEPLOYMENT_TARGET']="10.5"
|
|
|
|
remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/)
|
|
|
|
append_to_cflags('-mmacosx-version-min=10.5')
|
|
|
|
end
|
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
def minimal_optimization
|
|
|
|
self['CFLAGS']=self['CXXFLAGS']="-Os #{SAFE_CFLAGS_FLAGS}"
|
|
|
|
end
|
|
|
|
def no_optimization
|
|
|
|
self['CFLAGS']=self['CXXFLAGS'] = SAFE_CFLAGS_FLAGS
|
|
|
|
end
|
2009-12-02 12:17:14 +00:00
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
def libxml2
|
|
|
|
append_to_cflags ' -I/usr/include/libxml2'
|
|
|
|
end
|
2010-08-07 16:50:45 -07:00
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
def x11
|
2010-01-11 11:28:37 -08:00
|
|
|
opoo "You do not have X11 installed, this formula may not build." if not x11_installed?
|
2010-08-07 16:50:45 -07:00
|
|
|
|
|
|
|
# There are some config scripts (e.g. freetype) here that should go in the path
|
|
|
|
ENV.prepend 'PATH', '/usr/X11/bin', ':'
|
2009-10-15 12:36:09 +01:00
|
|
|
# CPPFLAGS are the C-PreProcessor flags, *not* C++!
|
|
|
|
append 'CPPFLAGS', '-I/usr/X11R6/include'
|
|
|
|
append 'LDFLAGS', '-L/usr/X11R6/lib'
|
2009-12-09 04:49:19 +01:00
|
|
|
# CMake ignores the variables above
|
|
|
|
append 'CMAKE_PREFIX_PATH', '/usr/X11R6', ':'
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
|
|
|
alias_method :libpng, :x11
|
2010-08-07 16:50:45 -07:00
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
# we've seen some packages fail to build when warnings are disabled!
|
|
|
|
def enable_warnings
|
|
|
|
remove_from_cflags '-w'
|
|
|
|
end
|
|
|
|
# Snow Leopard defines an NCURSES value the opposite of most distros
|
|
|
|
# See: http://bugs.python.org/issue6848
|
|
|
|
def ncurses_define
|
|
|
|
append 'CPPFLAGS', "-DNCURSES_OPAQUE=0"
|
|
|
|
end
|
|
|
|
# returns the compiler we're using
|
|
|
|
def cc
|
|
|
|
ENV['CC'] or "gcc"
|
|
|
|
end
|
|
|
|
def cxx
|
2010-02-08 14:21:46 -08:00
|
|
|
ENV['CXX'] or "g++"
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
2009-10-23 14:51:50 +01:00
|
|
|
|
2009-10-15 12:36:09 +01:00
|
|
|
def m64
|
|
|
|
append_to_cflags '-m64'
|
2009-11-05 18:13:41 +00:00
|
|
|
ENV.append 'LDFLAGS', '-arch x86_64'
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
2009-10-23 14:51:50 +01:00
|
|
|
def m32
|
|
|
|
append_to_cflags '-m32'
|
2009-11-05 18:13:41 +00:00
|
|
|
ENV.append 'LDFLAGS', '-arch i386'
|
2009-10-23 14:51:50 +01:00
|
|
|
end
|
|
|
|
|
2009-10-19 12:44:30 +01:00
|
|
|
# i386 and x86_64 only, no PPC
|
|
|
|
def universal_binary
|
|
|
|
append_to_cflags '-arch i386 -arch x86_64'
|
2009-12-02 12:17:14 +00:00
|
|
|
ENV.O3 if self['CFLAGS'].include? '-O4' # O4 seems to cause the build to fail
|
2010-02-13 23:38:50 +01:00
|
|
|
ENV.append 'LDFLAGS', '-arch i386 -arch x86_64'
|
2010-04-22 11:15:03 -07:00
|
|
|
|
|
|
|
# Can't mix "-march" for a 32-bit CPU with "-arch x86_64"
|
|
|
|
remove_from_cflags(/-march=\S*/) if Hardware.is_32_bit?
|
2009-10-19 12:44:30 +01:00
|
|
|
end
|
2009-10-15 12:36:09 +01:00
|
|
|
|
|
|
|
def prepend key, value, separator = ' '
|
|
|
|
unless self[key].to_s.empty?
|
|
|
|
self[key] = value + separator + self[key]
|
|
|
|
else
|
|
|
|
self[key] = value
|
|
|
|
end
|
|
|
|
end
|
2009-10-21 11:50:37 -07:00
|
|
|
def append key, value, separator = ' '
|
2009-10-15 12:36:09 +01:00
|
|
|
ref=self[key]
|
|
|
|
if ref.nil? or ref.empty?
|
|
|
|
self[key]=value
|
|
|
|
else
|
2009-10-21 11:50:37 -07:00
|
|
|
self[key]=ref + separator + value
|
2009-10-15 12:36:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
def append_to_cflags f
|
|
|
|
append 'CFLAGS', f
|
|
|
|
append 'CXXFLAGS', f
|
|
|
|
end
|
|
|
|
def remove key, value
|
|
|
|
return if self[key].nil?
|
|
|
|
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 f
|
|
|
|
remove 'CFLAGS', f
|
|
|
|
remove 'CXXFLAGS', f
|
|
|
|
end
|
|
|
|
end
|