Created
September 28, 2012 16:34
-
-
Save pathsny/3800818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'formula' | |
class Php52 <Formula | |
url 'http://www.php.net/get/php-5.2.17.tar.bz2/from/www.php.net/mirror' | |
version '5.2.17' | |
homepage 'http://php.net/' | |
md5 'b27947f3045220faf16e4d9158cbfe13' | |
depends_on 'jpeg' | |
depends_on :freetype | |
depends_on :libpng | |
depends_on 'libmcrypt' | |
if ARGV.include? '--with-mysql' | |
depends_on 'mysql' | |
end | |
if ARGV.include? '--fpm' | |
exit if ARGV.include? '--with-apache' | |
depends_on 'libevent' | |
end | |
def options | |
[ | |
['--with-apache', "Install the Apache module"], | |
['--with-mysql', "Build with MySQL (PDO) support"], | |
['--fpm', "Build with 'FastCGI Process Manager' patch"] | |
] | |
end | |
def patches | |
# PHP-FPM patch (http://php-fpm.org) | |
return DATA if ARGV.include? '--fpm' | |
end | |
def caveats | |
<<-END_CAVEATS | |
Pass --with-apache to build with the Apache SAPI | |
Pass --with-mysql to build with MySQL (PDO) support | |
Pass --fpm to build with FastCGI Process Manager support | |
END_CAVEATS | |
end | |
# def skip_clean? path | |
# path == bin+'php' | |
# end | |
skip_clean ['bin', 'sbin'] | |
def install | |
configure_args = [ | |
"--prefix=#{prefix}", "--disable-debug", "--disable-dependency-tracking", | |
"--with-ldap=/usr", | |
"--with-kerberos=/usr", | |
"--enable-cli", | |
"--with-zlib-dir=/usr", | |
"--enable-exif", | |
"--enable-ftp", | |
"--enable-mbstring", | |
"--enable-mbregex", | |
"--enable-sockets", | |
"--with-iodbc=/usr", | |
"--with-curl=/usr", | |
"--with-config-file-path=#{prefix}/etc", | |
"--sysconfdir=/private/etc", | |
"--with-openssl=/usr", | |
"--with-xmlrpc", | |
"--with-xsl=/usr", | |
"--without-pear", | |
"--with-libxml-dir=/usr", | |
"--with-iconv=#{Formula.factory('libiconv').prefix}", | |
"--with-gd", | |
"--with-jpeg-dir=#{HOMEBREW_PREFIX}", | |
"--with-png-dir=#{Formula.factory('libpng').prefix}", | |
"--with-freetype-dir=#{HOMEBREW_PREFIX}", | |
"--with-mcrypt=#{HOMEBREW_PREFIX}", | |
"--mandir=#{man}"] | |
if ARGV.include? '--with-apache' | |
puts "Building with the Apache SAPI" | |
configure_args.push("--with-apxs2=/usr/sbin/apxs") | |
configure_args.push("--libexecdir=#{prefix}/libexec") | |
else | |
puts "Not building the Apache SAPI. Pass --with-apache if needed." | |
end | |
if ARGV.include? '--with-mysql' | |
configure_args.push("--with-mysql-sock=/tmp/mysql", | |
"--with-mysqli=#{HOMEBREW_PREFIX}/bin/mysql_config", | |
"--with-mysql=#{HOMEBREW_PREFIX}/lib/mysql", | |
"--with-pdo-mysql=#{HOMEBREW_PREFIX}/bin/mysql_config") | |
else | |
puts "Not building MySQL (PDO) support. Pass --with-mysql if needed." | |
end | |
if ARGV.include? '--fpm' | |
system "./buildconf --force" | |
configure_args.push( | |
"--enable-fastcgi", | |
"--enable-fpm", | |
"--with-libevent=#{Formula.factory('libevent').prefix}" | |
) | |
end | |
system "./configure", *configure_args | |
if ARGV.include? '--with-apache' | |
mkfile = File.open("Makefile") | |
newmk = File.new("Makefile.fix", "w") | |
mkfile.each do |line| | |
if /^EXTRA_LIBS =(.*)$/ =~ line | |
newmk.print "EXTRA_LIBS =", $1, " -lresolv\n" | |
elsif /^MH_BUNDLE_FLAGS =(.*)$/ =~ line | |
newmk.print "MH_BUNDLE_FLAGS =", $1, " -lresolv\n" | |
elsif /\$\(CC\) \$\(MH_BUNDLE_FLAGS\)/ =~ line | |
newmk.print "\t", '$(CC) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) $(MH_BUNDLE_FLAGS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so', "\n" | |
elsif /^INSTALL_IT =(.*)$/ =~ line | |
if ARGV.include? '--with-apache' | |
newmk.print "INSTALL_IT = $(mkinstalldirs) '#{prefix}/libexec/apache2' && $(mkinstalldirs) '$(INSTALL_ROOT)/private/etc/apache2' && /usr/sbin/apxs -S LIBEXECDIR='#{prefix}/libexec/apache2' -S SYSCONFDIR='$(INSTALL_ROOT)/private/etc/apache2' -i -a -n php5 libs/libphp5.so", "\n" | |
else | |
newmk.print line | |
end | |
else | |
newmk.print line | |
end | |
end | |
newmk.close | |
system "cp Makefile.fix Makefile" | |
end | |
if ARGV.include? '--with-apache' | |
system "make install" | |
puts "Apache module installed at #{prefix}/libexec/apache2/libphp.so" | |
puts "You can symlink to it in /usr/libexec/apache2, edit httpd.conf and restart your webserver" | |
else | |
system "make" | |
system "make install" | |
end | |
system "mkdir #{prefix}/etc" unless ARGV.include? "--fpm" | |
system "cp ./php.ini-recommended #{prefix}/etc/php.ini" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment