Skip to content

Instantly share code, notes, and snippets.

@dyve
Created February 14, 2012 18:29
Show Gist options
  • Save dyve/1828854 to your computer and use it in GitHub Desktop.
Save dyve/1828854 to your computer and use it in GitHub Desktop.
require 'formula'
require 'net/http'
<<-COMMENTS
This is the Homebrew formula for PHP's PostgreSQL modules.
COMMENTS
class PhpPostgresql <Formula
homepage 'http://www.php.net/'
depends_on 'postgresql'
def filename; "php-#{@version}.tar.bz2"; end
def url; "http://www.php.net/distributions/" + filename; end
@@md5s = {
# Included with Mac OS 10.6, included to optimize for common case
'php-5.3.1.tar.bz2' => '63e97ad450f0f7259e785100b634c797',
}
def self.release_md5_for filename
# Look for a link to the file closely followed by "md5: ..." on the PHP releases page
/<a\s+href="[^"]*\/#{Regexp.quote filename}(?:\/[^"]+)?"[^>]*>[^<]*<\/a>\s*<br\s*\/?>\s*<span[^>]*>md5:\s*([a-zA-Z0-9]+)/mi.match(@@release_html ||= %x[curl -s #{'http://www.php.net/releases/'}]) && $1 || false
end
def self.md5_for filename
@@md5s[filename] ||= release_md5_for(filename)
end
def md5
@md5 ||= PhpPostgresql.md5_for(filename)
end
def initialize *args, &block
# We need to figure out which version of PHP this mac is running
@version = %x[php -v].split(' ', 3)[1]
# .. so we can set the URL
@url = url
# .. and we can try to get the md5
@md5 = md5
super *args, &block
end
def php_extensions; lib+'php/extensions'; end
def install
extensions = ['pgsql']
extensions << 'pdo_pgsql' if File.directory? 'ext/pdo_pgsql'
args = ["--prefix=#{prefix}"]
extensions.each do |extension|
ohai "Compiling #{extension} extension"
Dir.chdir "ext/#{extension}" do
system '/usr/bin/phpize'
system './configure', *args
system '/usr/bin/make'
end
end
php_extensions.mkpath
extensions.each do |extension|
php_extensions.install Dir["ext/#{extension}/modules/#{extension}.so"]
end
end
def caveats
<<-CAVEATS.undent
The extensions are installed into:
#{php_extensions}
To use the module you'll need to include it in your php.ini:
extension=#{php_extensions}/pgsql.so
or use dl in your code:
dl('#{php_extensions}/pgsql.so');
By default, OS X doesn't include a php.ini so you can create one at:
/etc/php.ini.
This compiles the PostgreSQL extension from the PHP source, attempting to use Mac OS X's version of PHP (currently #{@version}). If you update Mac OS X and this changes the PHP version you may need to uninstall and re-install this forumula.
CAVEATS
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment