2010-09-11 20:22:54 +01:00
|
|
|
require 'formula'
|
2010-11-14 03:52:59 +00:00
|
|
|
require 'blacklist'
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
module Homebrew extend self
|
|
|
|
def create
|
|
|
|
if ARGV.include? '--macports'
|
|
|
|
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
|
|
|
|
elsif ARGV.include? '--fink'
|
|
|
|
exec "open", "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}"
|
|
|
|
elsif ARGV.named.empty?
|
|
|
|
raise UsageError
|
|
|
|
else
|
2011-04-05 08:31:05 -07:00
|
|
|
HOMEBREW_CACHE.mkpath
|
2010-09-11 20:22:54 +01:00
|
|
|
paths = ARGV.named.map do |url|
|
|
|
|
fc = FormulaCreator.new
|
|
|
|
fc.url = url
|
|
|
|
fc.mode = if ARGV.include? '--cmake'
|
|
|
|
:cmake
|
|
|
|
elsif ARGV.include? '--autotools'
|
|
|
|
:autotools
|
|
|
|
end
|
|
|
|
|
|
|
|
if fc.name.to_s.strip.empty?
|
|
|
|
path = Pathname.new url
|
|
|
|
print "Formula name [#{path.stem}]: "
|
|
|
|
fc.name = __gets || path.stem
|
|
|
|
end
|
|
|
|
|
|
|
|
unless ARGV.force?
|
|
|
|
if msg = blacklisted?(fc.name)
|
2010-11-14 03:52:59 +00:00
|
|
|
raise "#{fc.name} is blacklisted for creation.\n#{msg}\nIf you really want to create this formula use --force."
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if Formula.aliases.include? fc.name
|
|
|
|
realname = Formula.caniconical_name fc.name
|
|
|
|
raise <<-EOS.undent
|
|
|
|
The formula #{realname} is already aliased to #{fc.name}
|
|
|
|
Please check that you are not creating a duplicate.
|
|
|
|
To force creation use --force.
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
fc.generate
|
|
|
|
fc.path
|
|
|
|
end
|
2011-04-05 08:37:59 -07:00
|
|
|
puts "Please `brew audit "+paths.collect{|p|p.basename(".rb")}*" "+"` before submitting, thanks."
|
2010-09-11 20:22:54 +01:00
|
|
|
exec_editor *paths
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def __gets
|
|
|
|
gots = $stdin.gets.chomp
|
|
|
|
if gots.empty? then nil else gots end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class FormulaCreator
|
|
|
|
attr :url
|
|
|
|
attr :md5
|
|
|
|
attr :name, true
|
|
|
|
attr :path
|
|
|
|
attr :mode, true
|
|
|
|
|
|
|
|
def url= url
|
|
|
|
@url = url
|
|
|
|
path = Pathname.new url
|
|
|
|
/(.*?)[-_.]?#{path.version}/.match path.basename
|
|
|
|
@name = $1
|
|
|
|
@path = Formula.path $1
|
|
|
|
end
|
|
|
|
|
|
|
|
def version
|
|
|
|
Pathname.new(url).version
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate
|
|
|
|
raise "#{path} already exists" if path.exist?
|
|
|
|
|
|
|
|
require 'digest'
|
|
|
|
require 'erb'
|
|
|
|
|
|
|
|
if version.nil?
|
|
|
|
opoo "Version cannot be determined from URL."
|
|
|
|
puts "You'll need to add an explicit 'version' to the formula."
|
|
|
|
else
|
|
|
|
puts "Version detected as #{version}."
|
|
|
|
end
|
|
|
|
|
2011-03-13 12:52:41 +00:00
|
|
|
unless ARGV.include? "--no-fetch" and version
|
2010-09-11 20:22:54 +01:00
|
|
|
strategy = detect_download_strategy url
|
|
|
|
@md5 = strategy.new(url, name, version, nil).fetch.md5 if strategy == CurlDownloadStrategy
|
|
|
|
end
|
|
|
|
|
|
|
|
path.write ERB.new(template, nil, '>').result(binding)
|
|
|
|
end
|
|
|
|
|
|
|
|
def template; <<-EOS.undent
|
|
|
|
require 'formula'
|
|
|
|
|
2011-03-09 21:11:03 -08:00
|
|
|
class #{Formula.class_s name} < Formula
|
2010-09-11 20:22:54 +01:00
|
|
|
url '#{url}'
|
|
|
|
homepage ''
|
|
|
|
md5 '#{md5}'
|
|
|
|
|
|
|
|
<% if mode == :cmake %>
|
|
|
|
depends_on 'cmake'
|
|
|
|
<% elsif mode == nil %>
|
|
|
|
# depends_on 'cmake'
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
def install
|
|
|
|
<% if mode == :cmake %>
|
|
|
|
system "cmake . \#{std_cmake_parameters}"
|
|
|
|
<% elsif mode == :autotools %>
|
|
|
|
system "./configure", "--disable-debug", "--disable-dependency-tracking",
|
|
|
|
"--prefix=\#{prefix}"
|
|
|
|
<% else %>
|
|
|
|
system "./configure", "--disable-debug", "--disable-dependency-tracking",
|
|
|
|
"--prefix=\#{prefix}"
|
|
|
|
# system "cmake . \#{std_cmake_parameters}"
|
|
|
|
<% end %>
|
|
|
|
system "make install"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|