| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "hardware" | 
					
						
							|  |  |  | require "extend/ENV/shared" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-17 14:34:02 +08:00
										 |  |  | # TODO: deprecate compiling related codes after it's only used by brew test. | 
					
						
							| 
									
										
										
										
											2015-11-16 22:34:00 +08:00
										 |  |  | # @private | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | module Stdenv | 
					
						
							|  |  |  |   include SharedEnvExtension | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   SAFE_CFLAGS_FLAGS = "-w -pipe" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   DEFAULT_FLAGS = "-march=core2 -msse4" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def self.extended(base) | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     unless ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin" | 
					
						
							|  |  |  |       base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def setup_build_environment(formula = nil) | 
					
						
							| 
									
										
										
										
											2014-09-18 15:50:54 -05:00
										 |  |  |     super | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if MacOS.version >= :mountain_lion | 
					
						
							|  |  |  |       # Mountain Lion's sed is stricter, and errors out when | 
					
						
							|  |  |  |       # it encounters files with mixed character sets | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       delete("LC_ALL") | 
					
						
							|  |  |  |       self["LC_CTYPE"]="C" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Set the default pkg-config search path, overriding the built-in paths | 
					
						
							|  |  |  |     # Anything in PKG_CONFIG_PATH is searched before paths in this variable | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     self["MAKEFLAGS"] = "-j#{make_jobs}" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     unless HOMEBREW_PREFIX.to_s == "/usr/local" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       # /usr/local is already an -isystem and -L directory so we skip it | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       self["CPPFLAGS"] = "-isystem#{HOMEBREW_PREFIX}/include" | 
					
						
							|  |  |  |       self["LDFLAGS"] = "-L#{HOMEBREW_PREFIX}/lib" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       # CMake ignores the variables above | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-11 16:46:42 -05:00
										 |  |  |     frameworks = HOMEBREW_PREFIX.join("Frameworks") | 
					
						
							|  |  |  |     if frameworks.directory? | 
					
						
							|  |  |  |       append "CPPFLAGS", "-F#{frameworks}" | 
					
						
							|  |  |  |       append "LDFLAGS", "-F#{frameworks}" | 
					
						
							|  |  |  |       self["CMAKE_FRAMEWORK_PATH"] = frameworks.to_s | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Os is the default Apple uses for all its stuff so let's trust them | 
					
						
							|  |  |  |     set_cflags "-Os #{SAFE_CFLAGS_FLAGS}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     append "LDFLAGS", "-Wl,-headerpad_max_install_names" | 
					
						
							| 
									
										
										
										
											2013-08-23 11:36:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-29 21:11:03 -05:00
										 |  |  |     send(compiler) | 
					
						
							| 
									
										
										
										
											2013-09-10 23:08:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-03 10:06:55 -05:00
										 |  |  |     if cc =~ GNU_GCC_REGEXP | 
					
						
							| 
									
										
										
										
											2015-06-21 21:18:23 -04:00
										 |  |  |       gcc_formula = gcc_version_formula($&) | 
					
						
							| 
									
										
										
										
											2014-08-06 20:52:36 -05:00
										 |  |  |       append_path "PATH", gcc_formula.opt_bin.to_s | 
					
						
							| 
									
										
										
										
											2013-06-04 10:18:14 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     # Add lib and include etc. from the current macosxsdk to compiler flags: | 
					
						
							|  |  |  |     macosxsdk MacOS.version | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-26 22:11:29 -05:00
										 |  |  |     if MacOS::Xcode.without_clt? | 
					
						
							| 
									
										
										
										
											2016-03-16 22:09:41 -07:00
										 |  |  |       append_path "PATH", "#{MacOS::Xcode.prefix}/usr/bin" | 
					
						
							|  |  |  |       append_path "PATH", "#{MacOS::Xcode.toolchain_path}/usr/bin" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-05-23 19:04:25 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Leopard's ld needs some convincing that it's building 64-bit | 
					
						
							|  |  |  |     # See: https://github.com/mistydemeo/tigerbrew/issues/59 | 
					
						
							|  |  |  |     if MacOS.version == :leopard && MacOS.prefer_64_bit? | 
					
						
							|  |  |  |       append "LDFLAGS", "-arch #{Hardware::CPU.arch_64_bit}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Many, many builds are broken thanks to Leopard's buggy ld. | 
					
						
							|  |  |  |       # Our ld64 fixes many of those builds, though of course we can't | 
					
						
							|  |  |  |       # depend on it already being installed to build itself. | 
					
						
							|  |  |  |       ld64 if Formula["ld64"].installed? | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   def determine_pkg_config_libdir | 
					
						
							|  |  |  |     paths = [] | 
					
						
							| 
									
										
										
										
											2014-09-11 16:48:05 -05:00
										 |  |  |     paths << "#{HOMEBREW_PREFIX}/lib/pkgconfig" | 
					
						
							|  |  |  |     paths << "#{HOMEBREW_PREFIX}/share/pkgconfig" | 
					
						
							| 
									
										
										
										
											2016-03-20 01:44:36 +08:00
										 |  |  |     paths << "#{HOMEBREW_ENV_PATH}/pkgconfig/#{MacOS.version}" | 
					
						
							| 
									
										
										
										
											2014-09-11 16:48:05 -05:00
										 |  |  |     paths << "/usr/lib/pkgconfig" | 
					
						
							| 
									
										
										
										
											2013-08-15 21:50:13 +02:00
										 |  |  |     paths.select { |d| File.directory? d }.join(File::PATH_SEPARATOR) | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-25 02:03:00 -07:00
										 |  |  |   # Removes the MAKEFLAGS environment variable, causing make to use a single job. | 
					
						
							|  |  |  |   # This is useful for makefiles with race conditions. | 
					
						
							|  |  |  |   # When passed a block, MAKEFLAGS is removed only for the duration of the block and is restored after its completion. | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   def deparallelize | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     old = self["MAKEFLAGS"] | 
					
						
							|  |  |  |     remove "MAKEFLAGS", /-j\d+/ | 
					
						
							| 
									
										
										
										
											2015-04-25 02:03:00 -07:00
										 |  |  |     if block_given? | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         yield | 
					
						
							|  |  |  |       ensure | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         self["MAKEFLAGS"] = old | 
					
						
							| 
									
										
										
										
											2015-04-25 02:03:00 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     old | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  |   alias_method :j1, :deparallelize | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-12 12:00:18 -06:00
										 |  |  |   # These methods are no-ops for compatibility. | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   %w[fast O4 Og].each { |opt| define_method(opt) {} } | 
					
						
							| 
									
										
										
										
											2013-11-12 12:00:18 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   %w[O3 O2 O1 O0 Os].each do |opt| | 
					
						
							| 
									
										
										
										
											2013-11-12 12:00:18 -06:00
										 |  |  |     define_method opt do | 
					
						
							|  |  |  |       remove_from_cflags(/-O./) | 
					
						
							|  |  |  |       append_to_cflags "-#{opt}" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-11-12 12:00:18 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |   def determine_cc | 
					
						
							|  |  |  |     s = super | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     DevelopmentTools.locate(s) || Pathname.new(s) | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |   def determine_cxx | 
					
						
							| 
									
										
										
										
											2014-06-22 18:35:18 -05:00
										 |  |  |     dir, base = determine_cc.split | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |     dir / base.to_s.sub("gcc", "g++").sub("clang", "clang++") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def gcc_4_0 | 
					
						
							|  |  |  |     super | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     set_cpu_cflags "-march=nocona -mssse3" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |   alias_method :gcc_4_0_1, :gcc_4_0 | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def gcc | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |     super | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     set_cpu_cflags | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   alias_method :gcc_4_2, :gcc | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-28 01:38:09 -05:00
										 |  |  |   GNU_GCC_VERSIONS.each do |n| | 
					
						
							| 
									
										
										
										
											2015-05-07 01:12:24 -07:00
										 |  |  |     define_method(:"gcc-#{n}") do | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |       super() | 
					
						
							| 
									
										
										
										
											2013-06-28 01:38:09 -05:00
										 |  |  |       set_cpu_cflags | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   def clang | 
					
						
							| 
									
										
										
										
											2014-06-18 16:12:32 -04:00
										 |  |  |     super | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     replace_in_cflags(/-Xarch_#{Hardware::CPU.arch_32_bit} (-march=\S*)/, '\1') | 
					
						
							|  |  |  |     # Clang mistakenly enables AES-NI on plain Nehalem | 
					
						
							| 
									
										
										
										
											2014-08-18 16:02:12 -05:00
										 |  |  |     map = Hardware::CPU.optimization_flags | 
					
						
							|  |  |  |     map = map.merge(:nehalem => "-march=native -Xclang -target-feature -Xclang -aes") | 
					
						
							|  |  |  |     set_cpu_cflags "-march=native", map | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def remove_macosxsdk(version = MacOS.version) | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     # Clear all lib and include dirs from CFLAGS, CPPFLAGS, LDFLAGS that were | 
					
						
							|  |  |  |     # previously added by macosxsdk | 
					
						
							|  |  |  |     version = version.to_s | 
					
						
							|  |  |  |     remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/) | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     delete("MACOSX_DEPLOYMENT_TARGET") | 
					
						
							|  |  |  |     delete("CPATH") | 
					
						
							|  |  |  |     remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (sdk = MacOS.sdk_path(version)) && !MacOS::CLT.installed? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       delete("SDKROOT") | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       remove_from_cflags "-isysroot #{sdk}" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       remove "CPPFLAGS", "-isysroot #{sdk}" | 
					
						
							|  |  |  |       remove "LDFLAGS", "-isysroot #{sdk}" | 
					
						
							|  |  |  |       if HOMEBREW_PREFIX.to_s == "/usr/local" | 
					
						
							|  |  |  |         delete("CMAKE_PREFIX_PATH") | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       else | 
					
						
							|  |  |  |         # It was set in setup_build_environment, so we have to restore it here. | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |         self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def macosxsdk(version = MacOS.version) | 
					
						
							| 
									
										
										
										
											2013-10-18 12:56:51 -05:00
										 |  |  |     return unless OS.mac? | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     # Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS. | 
					
						
							|  |  |  |     remove_macosxsdk | 
					
						
							|  |  |  |     version = version.to_s | 
					
						
							|  |  |  |     append_to_cflags("-mmacosx-version-min=#{version}") | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     self["MACOSX_DEPLOYMENT_TARGET"] = version | 
					
						
							|  |  |  |     self["CPATH"] = "#{HOMEBREW_PREFIX}/include" | 
					
						
							|  |  |  |     prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (sdk = MacOS.sdk_path(version)) && !MacOS::CLT.installed? | 
					
						
							|  |  |  |       # Extra setup to support Xcode 4.3+ without CLT. | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       self["SDKROOT"] = sdk | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       # Tell clang/gcc where system include's are: | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append_path "CPATH", "#{sdk}/usr/include" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       # The -isysroot is needed, too, because of the Frameworks | 
					
						
							|  |  |  |       append_to_cflags "-isysroot #{sdk}" | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "CPPFLAGS", "-isysroot #{sdk}" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       # And the linker needs to find sdk/usr/lib | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "LDFLAGS", "-isysroot #{sdk}" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |       # Needed to build cmake itself and perhaps some cmake projects: | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append_path "CMAKE_PREFIX_PATH", "#{sdk}/usr" | 
					
						
							|  |  |  |       append_path "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def minimal_optimization | 
					
						
							| 
									
										
										
										
											2013-08-30 16:44:50 -05:00
										 |  |  |     set_cflags "-Os #{SAFE_CFLAGS_FLAGS}" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     macosxsdk unless MacOS::CLT.installed? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   def no_optimization | 
					
						
							| 
									
										
										
										
											2013-08-30 16:44:50 -05:00
										 |  |  |     set_cflags SAFE_CFLAGS_FLAGS | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     macosxsdk unless MacOS::CLT.installed? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Some configure scripts won't find libxml2 without help | 
					
						
							|  |  |  |   def libxml2 | 
					
						
							|  |  |  |     if MacOS::CLT.installed? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "CPPFLAGS", "-I/usr/include/libxml2" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     else | 
					
						
							|  |  |  |       # Use the includes form the sdk | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "CPPFLAGS", "-I#{MacOS.sdk_path}/usr/include/libxml2" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def x11 | 
					
						
							|  |  |  |     # There are some config scripts here that should go in the PATH | 
					
						
							| 
									
										
										
										
											2014-09-11 16:55:00 -05:00
										 |  |  |     append_path "PATH", MacOS::X11.bin.to_s | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Append these to PKG_CONFIG_LIBDIR so they are searched | 
					
						
							|  |  |  |     # *after* our own pkgconfig directories, as we dupe some of the | 
					
						
							|  |  |  |     # libs in XQuartz. | 
					
						
							| 
									
										
										
										
											2014-09-11 16:55:00 -05:00
										 |  |  |     append_path "PKG_CONFIG_LIBDIR", "#{MacOS::X11.lib}/pkgconfig" | 
					
						
							|  |  |  |     append_path "PKG_CONFIG_LIBDIR", "#{MacOS::X11.share}/pkgconfig" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-11 16:55:00 -05:00
										 |  |  |     append "LDFLAGS", "-L#{MacOS::X11.lib}" | 
					
						
							|  |  |  |     append_path "CMAKE_PREFIX_PATH", MacOS::X11.prefix.to_s | 
					
						
							|  |  |  |     append_path "CMAKE_INCLUDE_PATH", MacOS::X11.include.to_s | 
					
						
							|  |  |  |     append_path "CMAKE_INCLUDE_PATH", "#{MacOS::X11.include}/freetype2" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-11 16:55:00 -05:00
										 |  |  |     append "CPPFLAGS", "-I#{MacOS::X11.include}" | 
					
						
							|  |  |  |     append "CPPFLAGS", "-I#{MacOS::X11.include}/freetype2" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-11 16:55:00 -05:00
										 |  |  |     append_path "ACLOCAL_PATH", "#{MacOS::X11.share}/aclocal" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     if MacOS::XQuartz.provided_by_apple? && !MacOS::CLT.installed? | 
					
						
							| 
									
										
										
										
											2014-09-11 16:55:00 -05:00
										 |  |  |       append_path "CMAKE_PREFIX_PATH", "#{MacOS.sdk_path}/usr/X11" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-10-04 21:06:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-11 16:55:00 -05:00
										 |  |  |     append "CFLAGS", "-I#{MacOS::X11.include}" unless MacOS::CLT.installed? | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  |   alias_method :libpng, :x11 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # we've seen some packages fail to build when warnings are disabled! | 
					
						
							|  |  |  |   def enable_warnings | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     remove_from_cflags "-w" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def m64 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     append_to_cflags "-m64" | 
					
						
							|  |  |  |     append "LDFLAGS", "-arch #{Hardware::CPU.arch_64_bit}" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   def m32 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     append_to_cflags "-m32" | 
					
						
							|  |  |  |     append "LDFLAGS", "-arch #{Hardware::CPU.arch_32_bit}" | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def universal_binary | 
					
						
							| 
									
										
										
										
											2015-12-09 10:37:49 -05:00
										 |  |  |     check_for_compiler_universal_support | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     append_to_cflags Hardware::CPU.universal_archs.as_arch_flags | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     append "LDFLAGS", Hardware::CPU.universal_archs.as_arch_flags | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if compiler != :clang && Hardware.is_32_bit? | 
					
						
							|  |  |  |       # Can't mix "-march" for a 32-bit CPU  with "-arch x86_64" | 
					
						
							|  |  |  |       replace_in_cflags(/-march=\S*/, "-Xarch_#{Hardware::CPU.arch_32_bit} \\0") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-07 00:40:32 -07:00
										 |  |  |   def cxx11 | 
					
						
							|  |  |  |     if compiler == :clang | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "CXX", "-std=c++11" | 
					
						
							|  |  |  |       append "CXX", "-stdlib=libc++" | 
					
						
							| 
									
										
										
										
											2016-06-16 22:15:28 +10:00
										 |  |  |     elsif gcc_with_cxx11_support?(compiler) | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "CXX", "-std=c++11" | 
					
						
							| 
									
										
										
										
											2013-10-07 00:40:32 -07:00
										 |  |  |     else | 
					
						
							|  |  |  |       raise "The selected compiler doesn't support C++11: #{compiler}" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-24 00:26:09 -07:00
										 |  |  |   def libcxx | 
					
						
							|  |  |  |     if compiler == :clang | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "CXX", "-stdlib=libc++" | 
					
						
							| 
									
										
										
										
											2013-10-24 00:26:09 -07:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def libstdcxx | 
					
						
							|  |  |  |     if compiler == :clang | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       append "CXX", "-stdlib=libstdc++" | 
					
						
							| 
									
										
										
										
											2013-10-24 00:26:09 -07:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def replace_in_cflags(before, after) | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     CC_FLAG_VARS.each do |key| | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |       self[key] = self[key].sub(before, after) if key?(key) | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Convenience method to set all C compiler flags in one shot. | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def set_cflags(val) | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     CC_FLAG_VARS.each { |key| self[key] = val } | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Sets architecture-specific flags for every environment variable | 
					
						
							|  |  |  |   # given in the list `flags`. | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def set_cpu_flags(flags, default = DEFAULT_FLAGS, map = Hardware::CPU.optimization_flags) | 
					
						
							|  |  |  |     cflags =~ /(-Xarch_#{Hardware::CPU.arch_32_bit} )-march=/ | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     xarch = $1.to_s | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     remove flags, /(-Xarch_#{Hardware::CPU.arch_32_bit} )?-march=\S*/ | 
					
						
							|  |  |  |     remove flags, /( -Xclang \S+)+/ | 
					
						
							|  |  |  |     remove flags, /-mssse3/ | 
					
						
							|  |  |  |     remove flags, /-msse4(\.\d)?/ | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     append flags, xarch unless xarch.empty? | 
					
						
							| 
									
										
										
										
											2014-08-09 14:57:09 -05:00
										 |  |  |     append flags, map.fetch(effective_arch, default) | 
					
						
							| 
									
										
										
										
											2012-12-08 23:34:22 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Works around a buggy system header on Tiger | 
					
						
							|  |  |  |     append flags, "-faltivec" if MacOS.version == :tiger | 
					
						
							| 
									
										
										
										
											2014-08-09 14:57:09 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2014-08-09 14:57:09 -05:00
										 |  |  |   def effective_arch | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     if ARGV.build_bottle? | 
					
						
							| 
									
										
										
										
											2014-08-09 14:57:09 -05:00
										 |  |  |       ARGV.bottle_arch || Hardware.oldest_cpu | 
					
						
							| 
									
										
										
										
											2013-11-27 17:25:17 -06:00
										 |  |  |     elsif Hardware::CPU.intel? && !Hardware::CPU.sse4? | 
					
						
							|  |  |  |       # If the CPU doesn't support SSE4, we cannot trust -march=native or | 
					
						
							|  |  |  |       # -march=<cpu family> to do the right thing because we might be running | 
					
						
							|  |  |  |       # in a VM or on a Hackintosh. | 
					
						
							| 
									
										
										
										
											2014-08-09 14:57:09 -05:00
										 |  |  |       Hardware.oldest_cpu | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2014-08-09 14:57:09 -05:00
										 |  |  |       Hardware::CPU.family | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def set_cpu_cflags(default = DEFAULT_FLAGS, map = Hardware::CPU.optimization_flags) | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     set_cpu_flags CC_FLAG_VARS, default, map | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def make_jobs | 
					
						
							|  |  |  |     # '-j' requires a positive integral argument | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     if self["HOMEBREW_MAKE_JOBS"].to_i > 0
 | 
					
						
							|  |  |  |       self["HOMEBREW_MAKE_JOBS"].to_i | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     else | 
					
						
							|  |  |  |       Hardware::CPU.cores | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-20 15:20:27 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # This method does nothing in stdenv since there's no arg refurbishment | 
					
						
							| 
									
										
										
										
											2015-08-29 10:56:24 +01:00
										 |  |  |   # @private | 
					
						
							| 
									
										
										
										
											2014-03-20 15:20:27 -07:00
										 |  |  |   def refurbish_args; end | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  | end |