| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:  * `diy` [`--name=`<name>] [`--version=`<version>]: | 
					
						
							|  |  |  | #:    Automatically determine the installation prefix for non-Homebrew software. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    Using the output from this command, you can install your own software into | 
					
						
							|  |  |  | #:    the Cellar and then link it into Homebrew's prefix with `brew link`. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    The options `--name=`<name> and `--version=`<version> each take an argument | 
					
						
							|  |  |  | #:    and allow you to explicitly set the name and version of the package you are | 
					
						
							|  |  |  | #:    installing. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-15 12:55:14 -05:00
										 |  |  | require "formula" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def diy | 
					
						
							|  |  |  |     path = Pathname.getwd | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-17 12:24:03 -05:00
										 |  |  |     version = ARGV.value("version") || detect_version(path) | 
					
						
							|  |  |  |     name = ARGV.value("name") || detect_name(path, version) | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 16:01:02 -05:00
										 |  |  |     prefix = HOMEBREW_CELLAR/name/version | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-15 12:55:14 -05:00
										 |  |  |     if File.file? "CMakeLists.txt" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       puts "-DCMAKE_INSTALL_PREFIX=#{prefix}" | 
					
						
							| 
									
										
										
										
											2014-07-17 12:14:16 -05:00
										 |  |  |     elsif File.file? "configure" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       puts "--prefix=#{prefix}" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       raise "Couldn't determine build system" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-15 12:55:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-17 12:24:03 -05:00
										 |  |  |   def detect_version(path) | 
					
						
							|  |  |  |     version = path.version.to_s | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-22 20:12:28 +02:00
										 |  |  |     raise "Couldn't determine version, set it with --version=<version>" if version.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     version | 
					
						
							| 
									
										
										
										
											2014-07-17 12:24:03 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def detect_name(path, version) | 
					
						
							| 
									
										
										
										
											2014-03-15 12:55:14 -05:00
										 |  |  |     basename = path.basename.to_s | 
					
						
							|  |  |  |     detected_name = basename[/(.*?)-?#{Regexp.escape(version)}/, 1] || basename | 
					
						
							| 
									
										
										
										
											2014-06-22 15:00:15 -05:00
										 |  |  |     canonical_name = Formulary.canonical_name(detected_name) | 
					
						
							| 
									
										
										
										
											2014-03-15 12:55:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     odie <<~EOS if detected_name != canonical_name | 
					
						
							| 
									
										
										
										
											2014-03-15 12:55:14 -05:00
										 |  |  |       The detected name #{detected_name.inspect} exists in Homebrew as an alias | 
					
						
							|  |  |  |       of #{canonical_name.inspect}. Consider using the canonical name instead: | 
					
						
							|  |  |  |         brew diy --name=#{canonical_name} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       To continue using the detected name, pass it explicitly: | 
					
						
							|  |  |  |         brew diy --name=#{detected_name} | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     detected_name | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |