| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  | # @private | 
					
						
							|  |  |  | class DevelopmentTools | 
					
						
							|  |  |  |   class << self | 
					
						
							|  |  |  |     def locate(tool) | 
					
						
							|  |  |  |       # Don't call tools (cc, make, strip, etc.) directly! | 
					
						
							|  |  |  |       # Give the name of the binary you look for as a string to this method | 
					
						
							|  |  |  |       # in order to get the full path back as a Pathname. | 
					
						
							|  |  |  |       (@locate ||= {}).fetch(tool) do |key| | 
					
						
							|  |  |  |         @locate[key] = if File.executable?(path = "/usr/bin/#{tool}") | 
					
						
							|  |  |  |           Pathname.new path | 
					
						
							|  |  |  |         # Homebrew GCCs most frequently; much faster to check this before xcrun | 
					
						
							|  |  |  |         elsif (path = HOMEBREW_PREFIX/"bin/#{tool}").executable? | 
					
						
							|  |  |  |           path | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def installed? | 
					
						
							|  |  |  |       which("clang") || which("gcc") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  |     def installation_instructions | 
					
						
							|  |  |  |       "Install Clang or brew install gcc" | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |     alias custom_installation_instructions installation_instructions | 
					
						
							| 
									
										
										
										
											2016-07-16 21:01:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     def default_cc | 
					
						
							|  |  |  |       cc = DevelopmentTools.locate "cc" | 
					
						
							| 
									
										
										
										
											2016-09-17 15:17:27 +01:00
										 |  |  |       begin | 
					
						
							|  |  |  |         cc.realpath.basename.to_s | 
					
						
							|  |  |  |       rescue | 
					
						
							|  |  |  |         nil | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def default_compiler | 
					
						
							| 
									
										
										
										
											2016-07-29 15:52:41 -06:00
										 |  |  |       if default_cc =~ /^gcc/ | 
					
						
							|  |  |  |         :gcc | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         :clang | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def gcc_40_build_version | 
					
						
							|  |  |  |       @gcc_40_build_version ||= | 
					
						
							|  |  |  |         if (path = locate("gcc-4.0")) | 
					
						
							|  |  |  |           `#{path} --version 2>/dev/null`[/build (\d{4,})/, 1].to_i | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |     alias gcc_4_0_build_version gcc_40_build_version | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def gcc_42_build_version | 
					
						
							|  |  |  |       @gcc_42_build_version ||= | 
					
						
							|  |  |  |         begin | 
					
						
							|  |  |  |           gcc = locate("gcc-4.2") || HOMEBREW_PREFIX.join("opt/apple-gcc42/bin/gcc-4.2") | 
					
						
							|  |  |  |           if gcc.exist? && !gcc.realpath.basename.to_s.start_with?("llvm") | 
					
						
							|  |  |  |             `#{gcc} --version 2>/dev/null`[/build (\d{4,})/, 1].to_i | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-23 18:13:48 +02:00
										 |  |  |     alias gcc_build_version gcc_42_build_version | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def clang_version | 
					
						
							|  |  |  |       @clang_version ||= | 
					
						
							|  |  |  |         if (path = locate("clang")) | 
					
						
							|  |  |  |           `#{path} --version`[/(?:clang|LLVM) version (\d\.\d)/, 1] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def clang_build_version | 
					
						
							|  |  |  |       @clang_build_version ||= | 
					
						
							|  |  |  |         if (path = locate("clang")) | 
					
						
							|  |  |  |           `#{path} --version`[/clang-(\d{2,})/, 1].to_i | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-05-10 08:19:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def non_apple_gcc_version(cc) | 
					
						
							|  |  |  |       (@non_apple_gcc_version ||= {}).fetch(cc) do | 
					
						
							|  |  |  |         path = HOMEBREW_PREFIX.join("opt", "gcc", "bin", cc) | 
					
						
							|  |  |  |         path = locate(cc) unless path.exist? | 
					
						
							|  |  |  |         version = `#{path} --version`[/gcc(?:-\d(?:\.\d)? \(.+\))? (\d\.\d\.\d)/, 1] if path | 
					
						
							|  |  |  |         @non_apple_gcc_version[cc] = version | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def clear_version_cache | 
					
						
							| 
									
										
										
										
											2016-05-22 09:40:08 +01:00
										 |  |  |       @gcc_40_build_version = @gcc_42_build_version = nil | 
					
						
							| 
									
										
										
										
											2016-05-10 08:19:48 +01:00
										 |  |  |       @clang_version = @clang_build_version = nil | 
					
						
							|  |  |  |       @non_apple_gcc_version = {} | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-04-25 18:01:03 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "extend/os/development_tools" |