diff options
Diffstat (limited to 'Library/Homebrew/extend')
| -rw-r--r-- | Library/Homebrew/extend/ENV.rb | 167 |
1 files changed, 113 insertions, 54 deletions
diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 898da6237..ca0a51e99 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -32,8 +32,8 @@ module HomebrewEnvExtension unless self['CC'] @compiler = MacOS.default_compiler self.send @compiler - self['CC'] = '/usr/bin/cc' - self['CXX'] = '/usr/bin/c++' + self['CC'] = MacOS.locate("cc") + self['CXX'] = MacOS.locate("c++") self['OBJC'] = self['CC'] end @@ -42,6 +42,17 @@ module HomebrewEnvExtension # build more successfully because we are changing CC and many build systems # don't react properly to that. self['LD'] = self['CC'] + + # Add lib and include etc. from the current macosxsdk to compiler flags: + macosxsdk MacOS.version + + # For Xcode 4.3 (*without* the "Command Line Tools for Xcode") compiler and tools inside of Xcode: + if not MacOS.clt_installed? and MacOS.xcode_installed? and MacOS.xcode_version >= "4.3" + # Some tools (clang, etc.) are in the xctoolchain dir of Xcode + append 'PATH', "#{MacOS.xctoolchain_path}/usr/bin", ":" if MacOS.xctoolchain_path + # Others are now at /Applications/Xcode.app/Contents/Developer/usr/bin + append 'PATH', "#{MacOS.dev_tools_path}", ":" + end end def deparallelize @@ -86,7 +97,7 @@ module HomebrewEnvExtension end def gcc_4_0_1 - # we don't use xcrun because gcc 4.0 has not been provided since Xcode 4 + # we don't use locate because gcc 4.0 has not been provided since Xcode 4 self['CC'] = "#{MacOS.dev_tools_path}/gcc-4.0" self['LD'] = self['CC'] self['CXX'] = "#{MacOS.dev_tools_path}/g++-4.0" @@ -97,33 +108,6 @@ module HomebrewEnvExtension end alias_method :gcc_4_0, :gcc_4_0_1 - def xcrun tool - if File.executable? "/usr/bin/#{tool}" - "/usr/bin/#{tool}" - elsif not MacOS.xctools_fucked? and system "/usr/bin/xcrun -find #{tool} 1>/dev/null 2>&1" - # xcrun was provided first with Xcode 4.3 and allows us to proxy - # tool usage thus avoiding various bugs - "/usr/bin/xcrun #{tool}" - else - # otherwise lets try and figure it out ourselves - fn = "#{MacOS.dev_tools_path}/#{tool}" - if File.executable? fn - fn - else - # This is for the use-case where xcode-select is not set up with - # Xcode 4.3. The tools in Xcode 4.3 are split over two locations, - # usually xcrun would figure that out for us, but it won't work if - # xcode-select is not configured properly. - fn = "#{MacOS.xcode_prefix}/Toolchains/XcodeDefault.xctoolchain/usr/bin/#{tool}" - if File.executable? fn - fn - else - nil - end - end - end - end - # if your formula doesn't like CC having spaces use this def expand_xcrun self['CC'] =~ %r{/usr/bin/xcrun (.*)} @@ -139,9 +123,9 @@ module HomebrewEnvExtension # However they still provide a gcc symlink to llvm # But we don't want LLVM of course. - self['CC'] = xcrun "gcc-4.2" + self['CC'] = MacOS.locate "gcc-4.2" self['LD'] = self['CC'] - self['CXX'] = xcrun "g++-4.2" + self['CXX'] = MacOS.locate "g++-4.2" self['OBJC'] = self['CC'] unless self['CC'] @@ -149,7 +133,7 @@ module HomebrewEnvExtension self['LD'] = self['CC'] self['CXX'] = "#{HOMEBREW_PREFIX}/bin/g++-4.2" self['OBJC'] = self['CC'] - raise "GCC could not be found" if not File.exist? self['CC'] + raise "GCC could not be found" unless File.exist? self['CC'] end if not self['CC'] =~ %r{^/usr/bin/xcrun } @@ -163,18 +147,18 @@ module HomebrewEnvExtension alias_method :gcc_4_2, :gcc def llvm - self['CC'] = xcrun "llvm-gcc" + self['CC'] = MacOS.locate "llvm-gcc" self['LD'] = self['CC'] - self['CXX'] = xcrun "llvm-g++" + self['CXX'] = MacOS.locate "llvm-g++" self['OBJC'] = self['CC'] set_cpu_cflags 'core2 -msse4', :penryn => 'core2 -msse4.1', :core2 => 'core2', :core => 'prescott' @compiler = :llvm end def clang - self['CC'] = xcrun "clang" + self['CC'] = MacOS.locate "clang" self['LD'] = self['CC'] - self['CXX'] = xcrun "clang++" + self['CXX'] = MacOS.locate "clang++" self['OBJC'] = self['CC'] replace_in_cflags(/-Xarch_i386 (-march=\S*)/, '\1') # Clang mistakenly enables AES-NI on plain Nehalem @@ -238,39 +222,114 @@ Please take one of the following actions: end end - def osx_10_4 - self['MACOSX_DEPLOYMENT_TARGET']="10.4" + def remove_macosxsdk v=MacOS.version + # Clear all lib and include dirs from CFLAGS, CPPFLAGS, LDFLAGS that were + # previously added by macosxsdk + v = v.to_s remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/) - append_to_cflags('-mmacosx-version-min=10.4') + self['MACOSX_DEPLOYMENT_TARGET'] = nil + remove 'CPPFLAGS', "-isystem #{HOMEBREW_PREFIX}/include" + remove 'LDFLAGS', "-L#{HOMEBREW_PREFIX}/lib" + sdk = MacOS.sdk_path(v) + unless sdk.nil? + self['SDKROOT'] = nil + remove 'CPPFLAGS', "-isysroot #{sdk}" + remove 'CPPFLAGS', "-isystem #{sdk}/usr/include" + remove 'CPPFLAGS', "-I#{sdk}/usr/include" + remove_from_cflags "-isystem #{sdk}/usr/include" + remove_from_cflags "-isysroot #{sdk}" + remove_from_cflags "-L#{sdk}/usr/lib" + remove_from_cflags "-I#{sdk}/usr/include" + remove 'LDFLAGS', "-L#{sdk}/usr/lib" + remove 'LDFLAGS', "-I#{sdk}/usr/include" + if HOMEBREW_PREFIX.to_s == '/usr/local' + self['CMAKE_PREFIX_PATH'] = nil + else + # It was set in setup_build_environment, so we have to restore it here. + self['CMAKE_PREFIX_PATH'] = "#{HOMEBREW_PREFIX}" + end + remove 'CMAKE_FRAMEWORK_PATH', "#{sdk}/System/Library/Frameworks" + end end - 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') + + def macosxsdk v=MacOS.version + # Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS. + remove_macosxsdk + # Allow cool style of ENV.macosxsdk 10.8 here (no "" :) + v = v.to_s + append_to_cflags("-mmacosx-version-min=#{v}") + self['MACOSX_DEPLOYMENT_TARGET'] = v + append 'CPPFLAGS', "-isystem #{HOMEBREW_PREFIX}/include" + prepend 'LDFLAGS', "-L#{HOMEBREW_PREFIX}/lib" + sdk = MacOS.sdk_path(v) + unless sdk.nil? + # Extra setup to support Xcode 4.3+ without CLT. + self['SDKROOT'] = sdk + # Teach the preprocessor and compiler (some don't respect CPPFLAGS) + # where system includes are: + append 'CPPFLAGS', "-isysroot #{sdk}" + append_to_cflags "-isysroot #{sdk}" + append 'CPPFLAGS', "-isystem #{sdk}/usr/include" + # Suggested by mxcl (https://github.com/mxcl/homebrew/pull/10510#issuecomment-4187996): + append_to_cflags "-isystem #{sdk}/usr/include" + # Some software needs this (e.g. python shows error: /usr/include/zlib.h: No such file or directory) + append 'CPPFLAGS', "-I#{sdk}/usr/include" + # Needed because CC passes this to the linker and some projects + # forget to use the LDFLAGS explicitly: + append_to_cflags "-L#{sdk}/usr/lib" + # And finally the "normal" things one expects for the CFLAGS and LDFLAGS: + append_to_cflags "-I#{sdk}/usr/include" + prepend 'LDFLAGS', "-L#{sdk}/usr/lib" + # Believe it or not, sometime only the LDFLAGS are used :/ + prepend 'LDFLAGS', "-I#{sdk}/usr/include" + # Needed to build cmake itself and perhaps some cmake projects: + append 'CMAKE_PREFIX_PATH', "#{sdk}/usr", ':' + append 'CMAKE_FRAMEWORK_PATH', "#{sdk}/System/Library/Frameworks", ':' + end end def minimal_optimization self['CFLAGS'] = self['CXXFLAGS'] = "-Os #{SAFE_CFLAGS_FLAGS}" + macosxsdk unless MacOS.clt_installed? end def no_optimization self['CFLAGS'] = self['CXXFLAGS'] = SAFE_CFLAGS_FLAGS + macosxsdk unless MacOS.clt_installed? end # Some configure scripts won't find libxml2 without help def libxml2 - append 'CPPFLAGS', '-I/usr/include/libxml2' + if MacOS.clt_installed? + append 'CPPFLAGS', '-I/usr/include/libxml2' + else + # Use the includes form the sdk + append 'CPPFLAGS', "-I#{MacOS.sdk_path}/usr/include/libxml2" + end end def x11 - opoo "You do not have X11 installed, this formula may not build." if not MacOS.x11_installed? - - # There are some config scripts (e.g. freetype) here that should go in the path - prepend 'PATH', '/usr/X11/bin', ':' - # CPPFLAGS are the C-PreProcessor flags, *not* C++! - append 'CPPFLAGS', '-I/usr/X11/include' - append 'LDFLAGS', '-L/usr/X11/lib' - # CMake ignores the variables above - append 'CMAKE_PREFIX_PATH', '/usr/X11', ':' + opoo "You do not have X11 installed, this formula may not build." unless MacOS.x11_installed? + + if MacOS.clt_installed? + # For Xcode < 4.3 clt_installed? is true. So here is the old style /usr/X11: + # There are some config scripts (e.g. freetype) here that should go in the path + # (note we don't use MacOS.sdk_path here, because there is no ./usr/bin in there) + prepend 'PATH', "/usr/X11/bin", ':' + # CPPFLAGS are the C-PreProcessor flags, *not* C++! + append 'CPPFLAGS', "-I/usr/X11/include" + # Even without Xcode or the CLTs, /usr/X11/lib is there + append 'LDFLAGS', "-L/usr/X11/lib" + else + # For Xcode 4.3 and above *without* CLT, we find the includes in the SDK: + # Only the SDK has got include files. (they are no longer in /usr/X11/include !) + # Todo: do we need to add cairo, fontconfig, GL, libpng15, pixman-1, VG, xcb, too? + append 'CFLAGS', "-I#{MacOS.sdk_path}/usr/X11/include" + append 'CPPFLAGS', "-I#{MacOS.sdk_path}/usr/X11/include" + append 'CPPFLAGS', "-I#{MacOS.sdk_path}/usr/X11/include/freetype2" + # The libs are still in /usr/X11/lib but to be consistent with the includes, we use the SDK, right? + append 'LDFLAGS', "-L#{MacOS.sdk_path}/usr/X11/lib" + append 'CMAKE_INCLUDE_PATH', "#{MacOS.sdk_path}/usr/X11/include", ':' + end end alias_method :libpng, :x11 |
