From e91aeafc82edb2b79af67e342009cd019cd1ede5 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 4 Jun 2009 19:21:19 +0100 Subject: Created /Library moved brew tool to /bin Moved Forumla and Cellar/homebrew into Library. This way the homebrew core files are more sensibly placed, Cellar is more internally consistent and only generated. And Homebrew is ready for use straight out of the tarball. --- .gitignore | 6 +- Cellar/homebrew/brew | 251 --------------------------- Cellar/homebrew/brewkit.rb | 351 -------------------------------------- Cellar/homebrew/unittest.rb | 77 --------- Formula/ack.rb | 10 -- Formula/asciidoc.rb | 12 -- Formula/boost.rb | 16 -- Formula/cmake.rb | 13 -- Formula/dmd.rb | 42 ----- Formula/fftw.rb | 21 --- Formula/git.rb | 20 --- Formula/grc.rb | 70 -------- Formula/lame.rb | 12 -- Formula/liblastfm.rb | 19 --- Formula/libogg.rb | 12 -- Formula/libsamplerate.rb | 12 -- Formula/mad.rb | 12 -- Formula/pkg-config.rb | 14 -- Formula/pngcrush.rb | 12 -- Formula/qt.rb | 43 ----- Formula/taglib.rb | 12 -- Formula/term.rb | 10 -- Formula/wget.rb | 13 -- Formula/xmlrpc-c.rb | 16 -- Formula/yajl.rb | 21 --- Library/Formula/ack.rb | 10 ++ Library/Formula/asciidoc.rb | 12 ++ Library/Formula/boost.rb | 16 ++ Library/Formula/cmake.rb | 13 ++ Library/Formula/dmd.rb | 42 +++++ Library/Formula/fftw.rb | 21 +++ Library/Formula/git.rb | 20 +++ Library/Formula/grc.rb | 70 ++++++++ Library/Formula/lame.rb | 12 ++ Library/Formula/liblastfm.rb | 19 +++ Library/Formula/libogg.rb | 12 ++ Library/Formula/libsamplerate.rb | 12 ++ Library/Formula/mad.rb | 12 ++ Library/Formula/pkg-config.rb | 14 ++ Library/Formula/pngcrush.rb | 12 ++ Library/Formula/qt.rb | 43 +++++ Library/Formula/taglib.rb | 12 ++ Library/Formula/term.rb | 10 ++ Library/Formula/wget.rb | 13 ++ Library/Formula/xmlrpc-c.rb | 16 ++ Library/Formula/yajl.rb | 21 +++ Library/Homebrew/brewkit.rb | 359 +++++++++++++++++++++++++++++++++++++++ Library/Homebrew/env.rb | 22 +++ Library/Homebrew/unittest.rb | 72 ++++++++ bin/brew | 245 ++++++++++++++++++++++++++ 50 files changed, 1112 insertions(+), 1095 deletions(-) delete mode 100755 Cellar/homebrew/brew delete mode 100644 Cellar/homebrew/brewkit.rb delete mode 100755 Cellar/homebrew/unittest.rb delete mode 100644 Formula/ack.rb delete mode 100644 Formula/asciidoc.rb delete mode 100644 Formula/boost.rb delete mode 100644 Formula/cmake.rb delete mode 100644 Formula/dmd.rb delete mode 100644 Formula/fftw.rb delete mode 100644 Formula/git.rb delete mode 100644 Formula/grc.rb delete mode 100644 Formula/lame.rb delete mode 100644 Formula/liblastfm.rb delete mode 100644 Formula/libogg.rb delete mode 100644 Formula/libsamplerate.rb delete mode 100644 Formula/mad.rb delete mode 100644 Formula/pkg-config.rb delete mode 100644 Formula/pngcrush.rb delete mode 100644 Formula/qt.rb delete mode 100644 Formula/taglib.rb delete mode 100644 Formula/term.rb delete mode 100644 Formula/wget.rb delete mode 100644 Formula/xmlrpc-c.rb delete mode 100644 Formula/yajl.rb create mode 100644 Library/Formula/ack.rb create mode 100644 Library/Formula/asciidoc.rb create mode 100644 Library/Formula/boost.rb create mode 100644 Library/Formula/cmake.rb create mode 100644 Library/Formula/dmd.rb create mode 100644 Library/Formula/fftw.rb create mode 100644 Library/Formula/git.rb create mode 100644 Library/Formula/grc.rb create mode 100644 Library/Formula/lame.rb create mode 100644 Library/Formula/liblastfm.rb create mode 100644 Library/Formula/libogg.rb create mode 100644 Library/Formula/libsamplerate.rb create mode 100644 Library/Formula/mad.rb create mode 100644 Library/Formula/pkg-config.rb create mode 100644 Library/Formula/pngcrush.rb create mode 100644 Library/Formula/qt.rb create mode 100644 Library/Formula/taglib.rb create mode 100644 Library/Formula/term.rb create mode 100644 Library/Formula/wget.rb create mode 100644 Library/Formula/xmlrpc-c.rb create mode 100644 Library/Formula/yajl.rb create mode 100644 Library/Homebrew/brewkit.rb create mode 100644 Library/Homebrew/env.rb create mode 100755 Library/Homebrew/unittest.rb create mode 100755 bin/brew diff --git a/.gitignore b/.gitignore index 4787e8518..72820f508 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .DS_Store /*/ -!/Cellar/ -!/Formula/ -/Cellar/*/ -!/Cellar/homebrew/ \ No newline at end of file +!/Library/ +!/bin/brew \ No newline at end of file diff --git a/Cellar/homebrew/brew b/Cellar/homebrew/brew deleted file mode 100755 index 9782c4edd..000000000 --- a/Cellar/homebrew/brew +++ /dev/null @@ -1,251 +0,0 @@ -#!/usr/bin/ruby -# Copyright 2009 Max Howell -# Licensed as per the GPL version 3 -require 'find' -require 'pathname' -$:.unshift "#{File.dirname __FILE__}/../Cellar/homebrew" -$root=Pathname.new(__FILE__).realpath.dirname.parent.parent -$formula=$root+'Formula' -$cellar=$root+'Cellar' - -def prune - n=0 - dirs=Array.new - $root.find do |path| - if path.directory? - name=path.relative_path_from($root).to_s - if name == '.git' or name == 'Cellar' or name == 'Formula' - Find.prune - else - dirs< 1 - keg=keg.children.first - raise "#{keg} is not a directory" unless keg.directory? - elsif keg.parent.parent.parent != $root - raise '#{keg} is not a keg' - end - - #TODO consider using hardlinks - - # yeah indeed, you have to force anything you want in the main tree into - # these directories :P - $n=0 - lnd(keg, 'etc') {nil} - lnd(keg, 'include') {nil} - - lnd(keg, 'lib') do |path| - :mkpath if ['pkgconfig','php'].include? path.to_s - end - - lnd(keg, 'bin') do |path| - if path.extname.to_s == '.app' - # no need to put .app bundles in the path, just use spotlight, or the - # open command - :skip - else - :mkpath - end - end - - lnd(keg, 'share') do |path| - path=path.to_s - if ['man','doc','locale','info'].include? path - :mkpath - else - mans=(1..9).collect {|x| "man/man#{x}"} - :mkpath if mans.include? path - end - end - - return $n -end - -def symlink_relative_to from, to - tod=to.dirname - tod.mkpath - Dir.chdir(tod) do - #TODO use ruby function so we get exceptions - `ln -sf "#{from.relative_path_from tod}"` - $n+=1 - end -end - -# symlinks a directory recursively into our FHS tree -def lnd keg, start - start=keg+start - return unless start.directory? - - start.find do |from| - next if from == start - - prune=false - relative_path=from.relative_path_from keg - to=$root+relative_path - - if from.directory? - cmd=yield from.relative_path_from(start) - - if :skip == cmd - Find.prune - elsif :mkpath == cmd - to.mkpath - $n+=1 - else - symlink_relative_to from, to - Find.prune - end - elsif from.file? - symlink_relative_to from, to - end - end -end - -def prefix - # Get the clean path to $prefix/Cellar/homebrew/brew/../../../ - # Don't resolve any symlinks of that final result. - # Rationale: if the user calls /usr/local/bin/brew but that will resolve - # to /Brewery/Cellar/homebrew/brew we should give /usr/local and not - # /Brewery because the user probably has chosen /usr/local as the Homebrew - # to expose to the system. - if File.symlink? __FILE__ - # using pathname as it will handle readlink returning abs or rel paths - d=Pathname.new(__FILE__).dirname - File.expand_path(d+File.readlink(__FILE__)+'../../../') - else - # Dir.pwd resolves the symlink :P #rubysucks - # we use the cwd because __FILE__ can be relative and expand_path - # resolves the symlink for the working directory if fed a relative path - # SIGH - cwd=Pathname.new `pwd`.strip - File.expand_path(cwd+__FILE__+'../../../') - end -end - -def usage - name=File.basename $0 - <<-EOS -Usage: #{name} [abv] [prune] [--prefix] [--cache] -Usage: #{name} [install] [ln] [rm] [info] [list] beverage - EOS -end - -######################################################################### impl -begin - #TODO proper options parsing so --options can go first if necessary - - case ARGV.shift - when 'abv' - `find #{$cellar} -type f | wc -l`.strip+' files, '+`du -hd0 #{$cellar} | cut -d"\t" -f1`.strip - when 'prune' - puts "Pruned #{prune} files" - when '--prefix' - puts prefix - when '--cache' - puts File.expand_path('~/Library/Application Support/Homebrew') - when '-h', '--help', '--usage', '-?' - puts usage - when '-v', '--version' - puts HOMEBREW_VERSION - when 'list' - puts `find #{$cellar+shift_formulae}` - when 'install' - name=shift_formulae - beginning = Time.now - o=__obj(name) - raise "#{o.prefix} already exists!" if o.prefix.exist? - o.brew { o.install } - ln name - puts "#{o.prefix}: "+`find #{o.prefix} -type f | wc -l`.strip+ - ' files, '+ - `du -hd0 #{o.prefix} | cut -d"\t" -f1`.strip+ - ", built in #{Time.now - beginning} seconds" - when 'ln' - puts "Created #{ln shift_formulae} links" - when 'rm' - rm shift_formulae - when 'info' - o=__obj shift_formulae - puts "#{o.name} #{o.version}" - puts o.homepage - else - puts usage - end - -rescue StandardError, Interrupt => e - if ARGV.include? '--verbose' or ENV['HOMEBREW_DEBUG'] - raise - elsif e.kind_of? Interrupt - puts # seeimgly a newline is typical - exit 130 - elsif e.kind_of? StandardError and not e.kind_of? NameError - puts "\033[1;31mError\033[0;0m: #{e}" - exit 1 - else - raise - end -end \ No newline at end of file diff --git a/Cellar/homebrew/brewkit.rb b/Cellar/homebrew/brewkit.rb deleted file mode 100644 index ae6879e73..000000000 --- a/Cellar/homebrew/brewkit.rb +++ /dev/null @@ -1,351 +0,0 @@ -# Copyright 2009 Max Howell -# Licensed as per the GPL version 3 -require 'pathname' -require 'osx/cocoa' # to get number of cores - -HOMEBREW_VERSION='0.1' - -# optimise all the way to eleven, references: -# http://en.gentoo-wiki.com/wiki/Safe_Cflags/Intel -# http://forums.mozillazine.org/viewtopic.php?f=12&t=577299 -# http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/i386-and-x86_002d64-Options.html -ENV['MACOSX_DEPLOYMENT_TARGET']='10.5' -ENV['CFLAGS']=ENV['CXXFLAGS']='-O3 -w -pipe -fomit-frame-pointer -march=prescott' - -# lets use gcc 4.2, it is newer and "better", at least I believe so, mail me -# if I'm wrong -ENV['CC']='gcc-4.2' -ENV['CXX']='g++-4.2' -ENV['MAKEFLAGS']="-j#{OSX::NSProcessInfo.processInfo.processorCount}" - -unless $root.to_s == '/usr/local' - ENV['CPPFLAGS']='-I'+$root+'include' - ENV['LDFLAGS']='-L'+$root+'lib' -end - - -def ohai title - n=`tput cols`.strip.to_i-4 - puts "\033[0;34m==>\033[0;0;1m #{title[0,n]}\033[0;0m" -end - -def appsupport - appsupport = File.expand_path "~/Library/Application Support/Homebrew" - FileUtils.mkpath appsupport unless File.exist? appsupport - return appsupport -end - - -# make our code neater -class Pathname - def mv dst - FileUtils.mv to_s, dst - end - def cp dst - if file? - FileUtils.cp to_s, dst - else - FileUtils.cp_r to_s, dst - end - end -end - - -class Formula - require 'find' - require 'fileutils' - - # fuck knows, ruby is weird - def self.url - @url - end - def url - self.class.url - end - def self.md5 - @md5 - end - def md5 - self.class.md5 - end - def self.homepage - @homepage - end - def homepage - self.class.homepage - end - # end ruby is weird section - - def initialize - # fuck knows, ruby is weird - @url=url if @url.nil? - raise "@url.nil?" if @url.nil? - @md5=md5 if @md5.nil? - # end ruby is weird section - - # pls improve this version extraction crap - filename=File.basename @url - i=filename.index /[-_]\d/ - unless i.nil? - /^((\d+[._])*(\d+-)?\d+[abc]?)/.match filename[i+1,1000] #1000 because rubysucks - @version=$1 - # if there are no dots replace underscores, boost do this, the bastards! - @version.gsub!('_', '.') unless @version.include? '.' - else - # no divisor or a '.' divisor, eg. dmd.1.11.zip - /^[a-zA-Z._-]*((\d+\.)*\d+)/.match filename - @version = $1 - end - end - -private - def maybe_mkpath path - path.mkpath unless path.exist? - return path - end - -public - def prefix - raise "@name.nil!" if @name.nil? - raise "@version.nil?" if @version.nil? - $cellar+@name+@version - end - def bin - maybe_mkpath prefix+'bin' - end - def doc - maybe_mkpath prefix+'share'+'doc'+name - end - def man - maybe_mkpath prefix+'share'+'man' - end - def lib - maybe_mkpath prefix+'lib' - end - def include - maybe_mkpath prefix+'include' - end - - def name=name - raise "Name assigned twice, I'm not letting you do that!" if @name - @name=name - end - -protected - def caveats - nil - end - -public - #yields a Pathname object for the installation prefix - def brew - # disabled until the regexp makes sense :P - #raise "@name does not validate to our regexp" unless /^\w+$/ =~ @name - - ohai "Downloading #{@url}" - - Dir.chdir appsupport do - tgz=Pathname.new(fetch()).realpath - md5=`md5 -q "#{tgz}"`.strip - raise "MD5 mismatch: #{md5}" unless md5 and md5 == @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 #{File.basename @url}`.strip - Dir.chdir tmp do - Dir.chdir uncompress(tgz) do - yield self - if caveats - ohai "Caveats" - puts caveats - end - #TODO copy changelog or CHANGES file to pkg root, - #TODO maybe README, etc. to versioned root - end - end - rescue Interrupt, RuntimeError - if ARGV.include? '--debug' - # debug mode allows the packager to intercept a failed build and - # investigate the problems - puts "Rescued build at: #{tmp}" - exit! 1 - else - FileUtils.rm_rf prefix - raise - end - ensure - FileUtils.rm_rf tmp if tmp - FileUtils.rm tgz if tgz and not self.cache? - end - - ohai 'Finishing up' - - begin - prefix - rescue RuntimeError - # you can have packages that aren't for installing, see git - # this is a HACK though, and dirty, and not right - return - end - - prefix.find do |path| - if path==prefix #rubysucks - next - elsif path.file? - if path.extname == '.la' - path.unlink - else - fo=`file -h #{path}` - args=nil - args='-SxX' if fo =~ /Mach-O dynamically linked shared library/ - args='' if fo =~ /Mach-O executable/ #defaults strip everything - if args - puts "Stripping: #{path}" if ARGV.include? '--verbose' - `strip #{args} #{path}` - end - end - elsif path.directory? and path!=prefix+'bin' and path!=prefix+'lib' - Find.prune - end - end - end - end - - def version - @version - end - def name - @name - end - -protected - def fetch - %r[http://(www.)?github.com/.*/(zip|tar)ball/].match @url - if $2 - # curl doesn't do the redirect magic that we would like, so we get a - # stupidly named file, this is why wget would be beter, but oh well - tgz="#{@name}-#{@version}.#{$2=='tar' ? 'tgz' : $2}" - oarg="-o #{tgz}" - else - oarg='-O' #use the filename that curl gets - tgz=File.expand_path File.basename(@url) - end - - agent="Homebrew #{HOMEBREW_VERSION} (Ruby #{VERSION}; Mac OS X 10.5 Leopard)" - - unless File.exists? tgz - `curl -#LA "#{agent}" #{oarg} "#{@url}"` - raise "Download failed" unless $? == 0 - else - puts "File already downloaded and cached" - end - 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['*'] - if entries.nil? or entries.length == 0 - raise "Empty tarball!" - elsif entries.length == 1 - # if one dir enter it as that will be where the build is - entries.first - else - # if there's more than one dir, then this is the build directory already - Dir.pwd - end - end - - def cache? - true - end - -private - def method_added(method) - raise 'You cannot override Formula.brew' if method == 'brew' - end -end - -# see ack.rb for an example usage -class UncompressedScriptFormula &1") do |f| - until f.eof? - s=f.gets - out+=s - puts s if ARGV.include? '--verbose' - end - end - - unless $? == 0 - puts out unless ARGV.include? '--verbose' #already did that above - raise "Failure during: #{cmd}" - end -end - -########################################################################script -if $0 == __FILE__ - d=$cellar.parent+'bin' - d.mkpath unless d.exist? - Dir.chdir d - Pathname.new('brew').make_symlink Pathname.new('../Cellar')+'homebrew'+'brew' -end \ No newline at end of file diff --git a/Cellar/homebrew/unittest.rb b/Cellar/homebrew/unittest.rb deleted file mode 100755 index 1982faefc..000000000 --- a/Cellar/homebrew/unittest.rb +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/ruby -$:.unshift File.dirname(__FILE__) -require 'pathname' -$root=Pathname.new(__FILE__).realpath.dirname.parent.parent -$cellar=$root+'Cellar' -require 'brewkit' -require 'test/unit' - - -class TestFormula > Homebrew -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 -################################################################## << Homebrew - sput -end - -######################################################################### ARGV -case ARGV[0] - when '--profile' then - puts profile_string - exit 0 -end - -######################################################################### cook -class Grc > ~/.profile - - EOS - end -end \ No newline at end of file diff --git a/Formula/lame.rb b/Formula/lame.rb deleted file mode 100644 index 2c248285c..000000000 --- a/Formula/lame.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'brewkit' - -class Lame > src/#{makefile}` } - end - - configure=<<-EOS - ./configure -prefix '#{prefix}' - -system-sqlite -system-libpng -system-zlib - -nomake demos -nomake examples -no-qt3support - -release -cocoa -arch x86 - -confirm-license -opensource - -I /usr/X11R6/include -L /usr/X11R6/lib - -fast - EOS - - system configure.gsub("\n", ' ').strip.squeeze(' ') - system "make install" - - # fuck weird prl files - `find #{lib} -name \*.prl -delete` - # fuck crazy disk usage - `rm -r #{prefix+'doc'+'html'} #{prefix+'doc'+'src'}` - # wtf are these anyway? - `rm -r #{bin}/Assistant_adp.app #{bin}/pixeltool.app #{bin}/qhelpconverter.app` - # we specified no debug already! :P - `rm #{lib}/libQtUiTools_debug.a` - # meh - `rm #{prefix}/q3porting.xml` - end - - def caveats - "We agreed to the Qt opensource license for you.\nIf this is unacceptable you should uninstall :P" - end -end \ No newline at end of file diff --git a/Formula/taglib.rb b/Formula/taglib.rb deleted file mode 100644 index 2811decec..000000000 --- a/Formula/taglib.rb +++ /dev/null @@ -1,12 +0,0 @@ -require 'brewkit' - -class Taglib > Homebrew +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 +################################################################## << Homebrew + sput +end + +######################################################################### ARGV +case ARGV[0] + when '--profile' then + puts profile_string + exit 0 +end + +######################################################################### cook +class Grc > ~/.profile + + EOS + end +end \ No newline at end of file diff --git a/Library/Formula/lame.rb b/Library/Formula/lame.rb new file mode 100644 index 000000000..2c248285c --- /dev/null +++ b/Library/Formula/lame.rb @@ -0,0 +1,12 @@ +require 'brewkit' + +class Lame > src/#{makefile}` } + end + + configure=<<-EOS + ./configure -prefix '#{prefix}' + -system-sqlite -system-libpng -system-zlib + -nomake demos -nomake examples -no-qt3support + -release -cocoa -arch x86 + -confirm-license -opensource + -I /usr/X11R6/include -L /usr/X11R6/lib + -fast + EOS + + system configure.gsub("\n", ' ').strip.squeeze(' ') + system "make install" + + # fuck weird prl files + `find #{lib} -name \*.prl -delete` + # fuck crazy disk usage + `rm -r #{prefix+'doc'+'html'} #{prefix+'doc'+'src'}` + # wtf are these anyway? + `rm -r #{bin}/Assistant_adp.app #{bin}/pixeltool.app #{bin}/qhelpconverter.app` + # we specified no debug already! :P + `rm #{lib}/libQtUiTools_debug.a` + # meh + `rm #{prefix}/q3porting.xml` + end + + def caveats + "We agreed to the Qt opensource license for you.\nIf this is unacceptable you should uninstall :P" + end +end \ No newline at end of file diff --git a/Library/Formula/taglib.rb b/Library/Formula/taglib.rb new file mode 100644 index 000000000..2811decec --- /dev/null +++ b/Library/Formula/taglib.rb @@ -0,0 +1,12 @@ +require 'brewkit' + +class Taglib +# +# This file is part of Homebrew. +# +# Homebrew is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Homebrew is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Homebrew. If not, see . + +require 'pathname' +require 'osx/cocoa' # to get number of cores +require "#{File.dirname __FILE__}/env" + +HOMEBREW_VERSION='0.1' + +# optimise all the way to eleven, references: +# http://en.gentoo-wiki.com/wiki/Safe_Cflags/Intel +# http://forums.mozillazine.org/viewtopic.php?f=12&t=577299 +# http://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/i386-and-x86_002d64-Options.html +ENV['MACOSX_DEPLOYMENT_TARGET']='10.5' +ENV['CFLAGS']=ENV['CXXFLAGS']='-O3 -w -pipe -fomit-frame-pointer -march=prescott' + +# lets use gcc 4.2, it is newer and "better", at least I believe so, mail me +# if I'm wrong +ENV['CC']='gcc-4.2' +ENV['CXX']='g++-4.2' +ENV['MAKEFLAGS']="-j#{OSX::NSProcessInfo.processInfo.processorCount}" + +unless $root.to_s == '/usr/local' + ENV['CPPFLAGS']='-I'+$root+'include' + ENV['LDFLAGS']='-L'+$root+'lib' +end + + +def ohai title + n=`tput cols`.strip.to_i-4 + puts "\033[0;34m==>\033[0;0;1m #{title[0,n]}\033[0;0m" +end + +def appsupport + appsupport = File.expand_path "~/Library/Application Support/Homebrew" + FileUtils.mkpath appsupport unless File.exist? appsupport + return appsupport +end + + +# make our code neater +class Pathname + def mv dst + FileUtils.mv to_s, dst + end + def cp dst + if file? + FileUtils.cp to_s, dst + else + FileUtils.cp_r to_s, dst + end + end +end + + +class Formula + require 'find' + require 'fileutils' + + # fuck knows, ruby is weird + def self.url + @url + end + def url + self.class.url + end + def self.md5 + @md5 + end + def md5 + self.class.md5 + end + def self.homepage + @homepage + end + def homepage + self.class.homepage + end + # end ruby is weird section + + def initialize + # fuck knows, ruby is weird + @url=url if @url.nil? + raise "@url.nil?" if @url.nil? + @md5=md5 if @md5.nil? + # end ruby is weird section + + # pls improve this version extraction crap + filename=File.basename @url + i=filename.index /[-_]\d/ + unless i.nil? + /^((\d+[._])*(\d+-)?\d+[abc]?)/.match filename[i+1,1000] #1000 because rubysucks + @version=$1 + # if there are no dots replace underscores, boost do this, the bastards! + @version.gsub!('_', '.') unless @version.include? '.' + else + # no divisor or a '.' divisor, eg. dmd.1.11.zip + /^[a-zA-Z._-]*((\d+\.)*\d+)/.match filename + @version = $1 + end + end + +private + def maybe_mkpath path + path.mkpath unless path.exist? + return path + end + +public + def prefix + raise "@name.nil!" if @name.nil? + raise "@version.nil?" if @version.nil? + $cellar+@name+@version + end + def bin + maybe_mkpath prefix+'bin' + end + def doc + maybe_mkpath prefix+'share'+'doc'+name + end + def man + maybe_mkpath prefix+'share'+'man' + end + def lib + maybe_mkpath prefix+'lib' + end + def include + maybe_mkpath prefix+'include' + end + + def name=name + raise "Name assigned twice, I'm not letting you do that!" if @name + @name=name + end + +protected + def caveats + nil + end + +public + #yields a Pathname object for the installation prefix + def brew + # disabled until the regexp makes sense :P + #raise "@name does not validate to our regexp" unless /^\w+$/ =~ @name + + ohai "Downloading #{@url}" + + Dir.chdir appsupport do + tgz=Pathname.new(fetch()).realpath + md5=`md5 -q "#{tgz}"`.strip + raise "MD5 mismatch: #{md5}" unless md5 and md5 == @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 #{File.basename @url}`.strip + Dir.chdir tmp do + Dir.chdir uncompress(tgz) do + yield self + if caveats + ohai "Caveats" + puts caveats + end + #TODO copy changelog or CHANGES file to pkg root, + #TODO maybe README, etc. to versioned root + end + end + rescue Interrupt, RuntimeError + if ARGV.include? '--debug' + # debug mode allows the packager to intercept a failed build and + # investigate the problems + puts "Rescued build at: #{tmp}" + exit! 1 + else + FileUtils.rm_rf prefix + raise + end + ensure + FileUtils.rm_rf tmp if tmp + FileUtils.rm tgz if tgz and not self.cache? + end + end + end + + def clean + prefix.find do |path| + if path==prefix #rubysucks + next + elsif path.file? + if path.extname == '.la' + path.unlink + else + fo=`file -h #{path}` + args=nil + args='-SxX' if fo =~ /Mach-O dynamically linked shared library/ + args='' if fo =~ /Mach-O executable/ #defaults strip everything + if args + puts "Stripping: #{path}" if ARGV.include? '--verbose' + `strip #{args} #{path}` + end + end + elsif path.directory? and path!=prefix+'bin' and path!=prefix+'lib' + Find.prune + end + end + end + + def version + @version + end + def name + @name + end + +protected + def fetch + %r[http://(www.)?github.com/.*/(zip|tar)ball/].match @url + if $2 + # curl doesn't do the redirect magic that we would like, so we get a + # stupidly named file, this is why wget would be beter, but oh well + tgz="#{@name}-#{@version}.#{$2=='tar' ? 'tgz' : $2}" + oarg="-o #{tgz}" + else + oarg='-O' #use the filename that curl gets + tgz=File.expand_path File.basename(@url) + end + + agent="Homebrew #{HOMEBREW_VERSION} (Ruby #{VERSION}; Mac OS X 10.5 Leopard)" + + unless File.exists? tgz + `curl -#LA "#{agent}" #{oarg} "#{@url}"` + raise "Download failed" unless $? == 0 + else + puts "File already downloaded and cached" + end + 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['*'] + if entries.nil? or entries.length == 0 + raise "Empty tarball!" + elsif entries.length == 1 + # if one dir enter it as that will be where the build is + entries.first + else + # if there's more than one dir, then this is the build directory already + Dir.pwd + end + end + + def cache? + true + end + +private + def method_added(method) + raise 'You cannot override Formula.brew' if method == 'brew' + end +end + +# see ack.rb for an example usage +class UncompressedScriptFormula &1") do |f| + until f.eof? + s=f.gets + out+=s + puts s if ARGV.include? '--verbose' + end + end + + unless $? == 0 + puts out unless ARGV.include? '--verbose' #already did that above + raise "Failure during: #{cmd}" + end +end + +########################################################################script +if $0 == __FILE__ + d=$cellar.parent+'bin' + d.mkpath unless d.exist? + Dir.chdir d + Pathname.new('brew').make_symlink Pathname.new('../Cellar')+'homebrew'+'brew' +end \ No newline at end of file diff --git a/Library/Homebrew/env.rb b/Library/Homebrew/env.rb new file mode 100644 index 000000000..e1beac1c1 --- /dev/null +++ b/Library/Homebrew/env.rb @@ -0,0 +1,22 @@ +# Copyright 2009 Max Howell +# +# This file is part of Homebrew. +# +# Homebrew is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Homebrew is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Homebrew. If not, see . + +require 'pathname' + +$root=Pathname.new(__FILE__).dirname.parent.parent.realpath +$formula=$root+'Library'+'Formula' +$cellar=$root+'Cellar' \ No newline at end of file diff --git a/Library/Homebrew/unittest.rb b/Library/Homebrew/unittest.rb new file mode 100755 index 000000000..5ec8f0e5d --- /dev/null +++ b/Library/Homebrew/unittest.rb @@ -0,0 +1,72 @@ +#!/usr/bin/ruby +require 'test/unit' +require "#{__FILE__}/../brewkit" + +class TestFormula 1 + keg=keg.children.first + raise "#{keg} is not a directory" unless keg.directory? + elsif keg.parent.parent.parent != $root + raise '#{keg} is not a keg' + end + + # yeah indeed, you have to force anything you need in the main tree into + # these directories :P + # NOTE that not everything needs to be in the main tree + # TODO consider using hardlinks + $n=0 + lnd(keg, 'etc') {nil} + lnd(keg, 'include') {nil} + + lnd(keg, 'lib') do |path| + :mkpath if ['pkgconfig','php'].include? path.to_s + end + + lnd(keg, 'bin') do |path| + if path.extname.to_s == '.app' + # no need to put .app bundles in the path, just use spotlight, or the + # open command + :skip + else + :mkpath + end + end + + lnd(keg, 'share') do |path| + includes=(1..9).collect {|x| "man/man#{x}"} <<'man'<<'doc'<<'locale'<<'info' + :mkpath if includes.include? path.to_s + end + + return $n +end + +def symlink_relative_to from, to + tod=to.dirname + tod.mkpath + Dir.chdir(tod) do + #TODO use ruby function so we get exceptions + `ln -sf "#{from.relative_path_from tod}"` + $n+=1 + end +end + +# symlinks a directory recursively into our FHS tree +def lnd keg, start + start=keg+start + return unless start.directory? + + start.find do |from| + next if from == start + + prune=false + relative_path=from.relative_path_from keg + to=$root+relative_path + + if from.directory? + cmd=yield from.relative_path_from(start) + + if :skip == cmd + Find.prune + elsif :mkpath == cmd + to.mkpath + $n+=1 + else + symlink_relative_to from, to + Find.prune + end + elsif from.file? + symlink_relative_to from, to + end + end +end + +def prefix + # Get the clean path to $prefix/Cellar/homebrew/brew/../../../ + # Don't resolve any symlinks of that final result. + # Rationale: if the user calls /usr/local/bin/brew but that will resolve + # to /Brewery/Cellar/homebrew/brew we should give /usr/local and not + # /Brewery because the user probably has chosen /usr/local as the Homebrew + # to expose to the system. + if File.symlink? __FILE__ + # using pathname as it will handle readlink returning abs or rel paths + d=Pathname.new(__FILE__).dirname + File.expand_path(d+File.readlink(__FILE__)+'../../../') + else + # Dir.pwd resolves the symlink :P #rubysucks + # we use the cwd because __FILE__ can be relative and expand_path + # resolves the symlink for the working directory if fed a relative path + # SIGH + cwd=Pathname.new `pwd`.strip + File.expand_path(cwd+__FILE__+'../../../') + end +end + +def usage + name=File.basename $0 + <<-EOS +Usage: #{name} [abv] [prune] [--prefix] [--cache] +Usage: #{name} [install] [ln] [rm] [info] [list] beverage + EOS +end + +######################################################################### impl +begin + #TODO proper options parsing so --options can go first if necessary + + case ARGV.shift + when 'abv' + `find #{$cellar} -type f | wc -l`.strip+' files, '+`du -hd0 #{$cellar} | cut -d"\t" -f1`.strip + when 'prune' + puts "Pruned #{prune} files" + when '--prefix' + puts prefix + when '--cache' + puts File.expand_path('~/Library/Application Support/Homebrew') + when '-h', '--help', '--usage', '-?' + puts usage + when '-v', '--version' + puts HOMEBREW_VERSION + when 'list' + puts `find #{$cellar+shift_formulae}` + when 'install' + name=shift_formulae + beginning = Time.now + o=__obj(name) + raise "#{o.prefix} already exists!" if o.prefix.exist? + o.brew { o.install } + ohai 'Finishing up' + o.clean + ln name + puts "#{o.prefix}: "+`find #{o.prefix} -type f | wc -l`.strip+ + ' files, '+ + `du -hd0 #{o.prefix} | cut -d"\t" -f1`.strip+ + ", built in #{Time.now - beginning} seconds" + when 'ln' + puts "Created #{ln shift_formulae} links" + when 'rm' + rm shift_formulae + when 'info' + o=__obj shift_formulae + puts "#{o.name} #{o.version}" + puts o.homepage + else + puts usage + end + +rescue StandardError, Interrupt => e + if ARGV.include? '--verbose' or ENV['HOMEBREW_DEBUG'] + raise + elsif e.kind_of? Interrupt + puts # seeimgly a newline is typical + exit 130 + elsif e.kind_of? StandardError and not e.kind_of? NameError + puts "\033[1;31mError\033[0;0m: #{e}" + exit 1 + else + raise + end +end \ No newline at end of file -- cgit v1.2.3