Skip to content
Browse files

The core tree, and some formulae

  • Loading branch information...
1 parent 29d8557 commit 84c5c3e5c301382ede5b1f04c7440ee9055589af @mxcl mxcl committed May 21, 2009
Showing with 365 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +47 −0 Cellar/homebrew/brew
  3. +116 −0 Cellar/homebrew/brewkit.rb
  4. +59 −0 Cellar/homebrew/unittest.rb
  5. +11 −0 Formula/cmake.rb
  6. +23 −0 Formula/dmd.rb
  7. +12 −0 Formula/git.rb
  8. +71 −0 Formula/grc.rb
  9. +12 −0 Formula/mad.rb
  10. +12 −0 Formula/wget.rb
View
2 .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+/*/
View
47 Cellar/homebrew/brew
@@ -0,0 +1,47 @@
+#!/usr/bin/ruby
+# Copyright 2009 Max Howell <max@methylblue.com>
+# Licensed as per the GPL version 3
+require 'Find'
+require 'Pathname'
+$root = Pathname.new(__FILE__).realpath.dirname.parent.parent
+
+case ARGV[0]
+ when 'brew', 'install' then
+ file="#{$root}/Formula/#{ARGV[1]}"
+ file+='.rb' unless File.exist? file
+ system "ruby #{file}"
+
+ when 'ln' then
+ abort "#{ARGV[1]} is not a directory" unless File.directory? ARGV[1]
+
+ #TODO check is under +/ with name AND version
+ #TODO you should mkdirs as you find them and symlink files otherwise
+ #TODO consider using hardlinks
+
+ Find.find ARGV[1] do |from|
+ next if from == ARGV[1] #rubysucks
+
+ from=Pathname.new from
+ relto=from.relative_path_from(Pathname.new(ARGV[1]))
+ to=$root+relto;
+
+ if from.directory?
+ to.mkpath unless to.exist? and relto.to_s.include? '/'
+ elsif from.file?
+ to.make_symlink from
+ end
+ end
+
+ when 'prune', 'pasteurize' then
+ $root.find do |path|
+ if path.directory?
+ name=path.basename
+ Find.prune if name == 'brews' or name == 'yeasts'
+ elsif path.symlink?
+ path.unlink unless path.readlink.exist?
+ end
+ end
+
+ else
+ puts "usage: #{$0} [prune] [ln path]"
+end
View
116 Cellar/homebrew/brewkit.rb
@@ -0,0 +1,116 @@
+# Copyright 2009 Max Howell <max@methylblue.com>
+# Licensed as per the GPL version 3
+require 'FileUtils'
+require 'Find'
+require 'Pathname'
+$agent = "Homebrew 0.1 (Ruby; Mac OS X 10.5 Leopard)"
+$cellar = Pathname.new(__FILE__).dirname.parent.realpath
+
+class Formula
+ # if you reimplement, assign @name, @version, @url and @md5
+ def initialize(url, md5)
+ @name = File.basename $0, '.rb' #original script that the interpreter started
+ @url = url
+ @md5 = md5
+
+ # pls improve this version extraction crap
+ filename=File.basename url
+ i=filename.index /[-_]\d/
+ unless i.nil?
+ /^((\d+[.-])*\d+)/.match filename[i+1,1000] #1000 because rubysucks
+ @version = $1
+ else
+ # no divisor or a '.' divisor, eg. dmd.1.11.zip
+ /^[a-zA-Z._-]*((\d+\.)*\d+)/.match filename
+ @version = $1
+ end
+ end
+
+ #yields a Pathname object for the installation prefix
+ def brew
+ raise "@name.nil?" if @name.nil?
+ raise "@version.nil?" if @version.nil?
+ raise "@name does not validate to our regexp" unless /^\w+$/ =~ @name
+
+ prefix=$cellar+@name+@version
+ raise "#{prefix} already exists!" if prefix.exist?
+
+ appsupport = File.expand_path "~/Library/Application Support/Homebrew"
+ FileUtils.mkpath appsupport unless File.exist? appsupport
+ Dir.chdir appsupport do
+ tgz=Pathname.new self.fetch
+ raise "MD5 mismatch" unless `md5 -q "#{tgz}"`.strip == @md5.downcase
+
+ # we make an additional subdirectory so know exactly what we are
+ # recursively deleting later
+ # we use mktemp rather than appsupport/blah because some build scripts
+ # can't handle being built in a directory with spaces in it :P
+ tmp=nil
+ begin
+ tmp=`mktemp -dt #{@name}-#{@version}`.strip
+ Dir.chdir tmp do
+ Dir.chdir uncompress(tgz) do
+ yield prefix
+ #TODO copy changelog or CHANGES file to pkg root,
+ #TODO maybe README, etc. to versioned root
+ end
+ end
+ ensure
+ FileUtils.rm_rf tmp
+ end
+
+ # stay in appsupport in case any odd files gets created etc.
+ `#{$cellar}/homebrew/brew ln #{prefix}` if prefix.exist?
+
+ puts "#{prefix}: "+`find #{prefix} | wc -l`.strip+' files, '+`du -hd0 #{prefix} | cut -d"\t" -f1`.strip
+ end
+ end
+
+ def version
+ @version
+ end
+ def name
+ @name
+ end
+
+protected
+ def fetch
+ tgz=File.expand_path File.basename(@url)
+ `curl -LOA "#{$agent}" "#{@url}"` unless File.exists? tgz
+ return tgz
+ end
+
+ def uncompress(path)
+ if path.extname == '.zip'
+ `unzip -qq "#{path}"`
+ else
+ `tar xf "#{path}"`
+ end
+
+ raise "Compression tool failed" if $? != 0
+
+ entries=Dir['*']
+ raise "Empty tar!" if entries.nil? or entries.length == 0
+ raise "Too many folders in uncompressed result. You need to reimplement the Recipe.uncompress function." if entries.length > 1
+ return entries.first
+ end
+
+private
+ def method_added(method)
+ raise 'You cannot override Formula.brew' if method == 'brew'
+ end
+end
+
+
+def inreplace(path, before, after)
+ # we're not using Ruby because the perl script is more concise
+ `perl -pi -e "s|#{before}|#{after}|g" "#{path}"`
+end
+
+
+########################################################################script
+if $0 == __FILE__
+ d=$cellar.parent+'bin'
+ d.mkpath unless d.exist?
+ (d+'brew').make_symlink $cellar+'homebrew'+'brew'
+end
View
59 Cellar/homebrew/unittest.rb
@@ -0,0 +1,59 @@
+#!/usr/bin/ruby
+cwd=File.dirname(__FILE__)
+$:.unshift cwd #rubysucks
+require 'brewkit'
+require 'test/unit'
+$cellar=Pathname.new(cwd).parent.realpath
+
+class BeerTasting < Test::Unit::TestCase
+ def test_version_all_dots
+ r=Formula.new "http://example.com/foo.bar.la.1.14.zip", 'nomd5'
+ assert_equal '1.14', r.version
+ end
+
+ def test_version_underscore_separator
+ r=Formula.new "http://example.com/grc_1.1.tar.gz", 'nomd5'
+ assert_equal '1.1', r.version
+ end
+
+ def test_version_internal_dash
+ r=Formula.new "http://example.com/foo-arse-1.1-2.tar.gz", 'nomd5'
+ assert_equal '1.1-2', r.version
+ end
+
+ def test_version_single_digit
+ r=Formula.new "http://example.com/foo_bar.45.tar.gz", 'nomd5'
+ assert_equal '45', r.version
+ end
+
+ def test_noseparator_single_digit
+ r=Formula.new "http://example.com/foo_bar45.tar.gz", 'nomd5'
+ assert_equal '45', r.version
+ end
+
+ def test_version_developer_that_hates_us_format
+ r=Formula.new "http://example.com/foo-bar-la.1.2.3.tar.gz", 'nomd5'
+ assert_equal '1.2.3', r.version
+ end
+
+ def test_version_regular
+ r=Formula.new "http://example.com/foo_bar-1.21.tar.gz", 'nomd5'
+ assert_equal '1.21', r.version
+ end
+
+ def test_prefix
+ url='http://www.methylblue.com/test-0.1.tar.gz'
+ md5='d496ea538a21dc4bb8524a8888baf88c'
+
+ begin #rubysyntaxFAIL
+ Formula.new(url, md5).brew do |prefix|
+ # we test for +/unittest/0.1 because we derive @name from $0
+ assert_equal File.expand_path(prefix), ($cellar+'unittest'+'0.1').to_s
+ assert_kind_of Pathname, prefix
+ end
+ rescue IOError => e
+ # this is not an error, cook will throw as nothing was installed
+ raise unless e.errno == Errno::ENOENT
+ end
+ end
+end
View
11 Formula/cmake.rb
@@ -0,0 +1,11 @@
+$:.unshift "#{File.dirname __FILE__}/../Cellar/homebrew" #rubysucks
+require 'brewkit'
+
+url='http://www.cmake.org/files/v2.6/cmake-2.6.3.tar.gz'
+md5='5ba47a94ce276f326abca1fd72a7e7c6'
+
+Formula.new(url, md5).brew do |prefix|
+ system "./bootstrap --prefix=#{prefix} --system-libs"
+ system "make"
+ system "make install"
+end
View
23 Formula/dmd.rb
@@ -0,0 +1,23 @@
+$:.unshift "#{File.dirname __FILE__}/../Cellar/homebrew" #rubysucks
+require 'brewkit'
+
+homepage='http://www.digitalmars.com/d/'
+url='http://ftp.digitalmars.com/dmd.1.043.zip'
+md5='6c83b7296cb84090a9ebc11ab0fb94a2'
+
+Formula.new(url, md5).brew do |prefix|
+ prefix.mkpath
+ FileUtils.cp_r 'osx/bin', prefix
+ FileUtils.cp_r 'osx/lib', prefix
+ FileUtils.cp_r 'man', prefix
+ FileUtils.cp_r 'man', prefix
+
+ share=prefix+'share'+'doc'+'d'
+ html=share+'html'
+ samples=share+'examples' #examples is the more typical directory name
+ html.mkpath
+ samples.mkpath
+
+ FileUtils.cp_r Dir['html/d/*'], html unless ARGV.include? '--no-html'
+ FileUtils.cp_r Dir['samples/d/*'], samples unless ARGV.include? '--no-samples'
+end
View
12 Formula/git.rb
@@ -0,0 +1,12 @@
+$:.unshift "#{File.dirname __FILE__}/../Cellar/homebrew" #rubysucks
+require 'brewkit'
+
+homepage='http://git-scm.com'
+url='http://kernel.org/pub/software/scm/git/git-1.6.3.1.tar.bz2'
+md5='c1f4aab741359c29f0fbf28563ac7387'
+
+Formula.new(url, md5).brew do |prefix|
+ `./configure --disable-debug --prefix="#{prefix}"`
+ `make`
+ `make install`
+end
View
71 Formula/grc.rb
@@ -0,0 +1,71 @@
+$:.unshift "#{File.dirname __FILE__}/../Cellar/homebrew" #rubysucks
+require 'brewkit'
+require 'FileUtils'
+
+def profile_string
+ <<-sput
+GRC=`which grc`
+if [ "$TERM" != dumb ] && [ -n GRC ]
+then
+ alias colourify="$GRC -es --colour=auto"
+ alias configure='colourify ./configure'
+ alias diff='colourify diff'
+ alias make='colourify make'
+ alias gcc='colourify gcc'
+ alias g++='colourify g++'
+ alias as='colourify as'
+ alias gas='colourify gas'
+ alias ld='colourify ld'
+ alias netstat='colourify netstat'
+ alias ping='colourify ping'
+ alias traceroute='colourify /usr/sbin/traceroute'
+fi
+ sput
+end
+
+######################################################################### ARGV
+case ARGV[0]
+ when '--profile' then
+ puts
+ puts '################################################################## >> yumports'
+ puts profile_string
+ puts '################################################################## << yumports'
+ exit 0
+end
+
+######################################################################### cook
+homepage='http://korpus.juls.savba.sk/~garabik/software/grc.html'
+url='http://korpus.juls.savba.sk/~garabik/software/grc/grc_1.1.tar.gz'
+md5='eeb612aba2fff14cbaf1f3bec7e1eb60'
+
+Formula.new(url, md5).brew do |prefix|
+ #TODO we should deprefixify since it's python and thus possible
+ inreplace 'grc', '/etc', prefix+'/etc'
+ inreplace 'grc.1', '/etc', prefix+'/etc'
+ inreplace 'grcat', '/usr/local', prefix
+ inreplace 'grcat.1', '/usr/local', prefix
+
+ FileUtils.mkpath prefix
+ Dir.chdir prefix do
+ FileUtils.mkpath 'bin'
+ FileUtils.mkpath 'share/grc'
+ FileUtils.mkpath 'share/man/man1'
+ FileUtils.mkpath 'etc'
+ end
+
+ `cp -fv grc grcat #{prefix}/bin`
+ `cp -fv conf.* #{prefix}/share/grc`
+ `cp -fv grc.conf #{prefix}/etc`
+ `cp -fv grc.1 grcat.1 #{prefix}/share/man/man1`
+
+ puts <<-sput
+We suggest you add this to your .profile in order to make grc work! :P
+
+#{profile_string}
+
+We can do this for you:
+
+ #{$0} --profile >> ~/.profile
+
+sput
+end
View
12 Formula/mad.rb
@@ -0,0 +1,12 @@
+$:.unshift "#{File.dirname __FILE__}/../Cellar/homebrew" #rubysucks
+require 'brewkit'
+
+homepage='http://www.underbit.com/products/mad/'
+url='http://kent.dl.sourceforge.net/sourceforge/mad/libmad-0.15.1b.tar.gz'
+md5='1be543bc30c56fb6bea1d7bf6a64e66c'
+
+Formula.new(url, md5).brew do |prefix|
+ `./configure --disable-debugging --enable-fpm=intel --prefix="#{prefix}"`
+ `make`
+ `make install`
+end
View
12 Formula/wget.rb
@@ -0,0 +1,12 @@
+$:.unshift "#{File.dirname __FILE__}/../Cellar/homebrew" #rubysucks
+require 'brewkit'
+
+homepage='http://www.gnu.org/software/wget/'
+url='http://ftp.gnu.org/gnu/wget/wget-1.11.4.tar.bz2'
+md5='f5076a8c2ec2b7f334cb6e3059820f9c'
+
+Formula.new(url, md5).brew do |prefix|
+ `./configure --disable-debug --prefix="#{prefix}"`
+ `make`
+ `make install`
+end

0 comments on commit 84c5c3e

Please sign in to comment.
Something went wrong with that request. Please try again.