pkgname=php
pkgver=5.2.6
pkgrel=23
_suhosinver=0.9.6.2
pkgdesc='A high-level scripting language'
arch=('i686' 'x86_64')
license=('PHP')
url='http://www.php.net'
backup=('etc/php/php.ini')
install=php.install
depends=('glibc' 'readline' 'ncurses' 'libxml2' 'pcre')
#makedepends=('apache' 'imap' 'postgresql-libs' 'mysql' 'libldap' \
#             'libpng' 'libjpeg' 'sqlite3' 'unixodbc' 'net-snmp' \
#       	'libmcrypt' 'tidyhtml' 'aspell' 'libtool' 'freetype2' 'libjpeg' \
#             'curl' 'libxslt' 'pam' 'openssl' 'bzip2' 'gdbm' 'db>=4.7')

makedepends=('mysql' 'libpng' 'libjpeg' 'sqlite3' \
       	'libmcrypt' 'libtool' 'freetype2' 'libjpeg' \
             'curl' 'libxslt' 'pam' 'openssl' 'bzip2' 'gdbm' 'db>=4.7')

optdepends=('bzip2: bz2' \
            'curl: curl' \
            'gdbm: dba' \
            'libpng: gd' \
            'libjpeg: gd' \
            'freetype2: gd' \
            'pam: imap' \
            'libldap: ldap' \
            'mcrypt: mcrypt' \
            'libtool: mcrypt' \
            'libmysqlclient: mysql/mysqli' \
            'unixodbc: odbc/pdo_odbc' \
            'openssl: openssl' \
            'postgresql-libs: pgsql/pdo_pgsql' \
            'aspell: pspell' \
            'net-snmp: snmp' \
            'sqlite3: sqlite' \
            'tidyhtml: tidy' \
            'libxslt: xsl' \
            )
options=('emptydirs')
source=("http://museum.php.net/php5/${pkgname}-${pkgver}.tar.bz2" \
        "http://download.suhosin.org/suhosin-patch-${pkgver}-${_suhosinver}.patch.gz" \
        'php.ini' 'apache.conf' 'db-configure.patch')
md5sums=('7380ffecebd95c6edb317ef861229ebd'
         'f2ec986341a314c271259dbe4d940858'
         'fda535c2b333297972aad48ee9285b45'
         '96ca078be6729b665be8a865535a97bf'
         '74e5ce5a02488ec91b1c59f539e42936')

build() {
	phpconfig="--prefix=/usr \
	--sysconfdir=/etc/php \
	--with-layout=GNU \
	--with-config-file-path=/etc/php \
	--with-config-file-scan-dir=/etc/php/conf.d \
	--enable-inline-optimization \
	--disable-debug \
	--disable-rpath \
	--disable-static \
	--enable-shared \
	"

	phpextensions="--with-openssl=shared \
	--with-zlib=shared \
	--enable-bcmath=shared \
	--with-bz2=shared \
	--enable-calendar=shared \
	--with-curl=shared \
	--enable-dba=shared \
	--without-db2 \
	--without-db3 \
	--with-db4=shared \
	--with-gdbm=shared \
	--enable-dbase=shared \
	--enable-exif=shared \
	--enable-ftp=shared \
	--with-gd=shared \
	--enable-gd-native-ttf \
	--with-jpeg-dir=shared,/usr \
	--with-png-dir=shared,/usr \
	--with-gettext=shared \
	--without-imap \
	--without-imap-ssl \
	--without-ldap \
	--enable-mbstring=shared \
	--with-mcrypt=shared \
	--with-mysql=shared \
	--with-mysql-sock=/tmp/mysql.sock \
	--with-mysql=shared \
	--with-mysqli=shared \
	--with-ncurses=shared \
	--without-unixODBC \
	--enable-pdo=shared \
	--with-pdo-mysql=shared \
	--with-pdo-sqlite=shared \
	--without-pdo-odbc \
	--without-pdo-pgsql \
	--with-sqlite=shared \
	--without-pgsql \
	--enable-shmop=shared \
	--without-snmp \
	--enable-soap=shared \
	--enable-sqlite-utf8=shared \
	--enable-sysvmsg=shared \
	--enable-sysvsem=shared \
	--enable-sysvshm=shared \
	--without-tidy \
	--with-xsl=shared \
	--enable-zip=shared \
	--enable-posix=shared \
	--enable-sockets=shared \
	--enable-xml \
	--with-ttf=shared \
	--enable-session=shared \
	--with-regex=php \
	--with-pcre-regex=/usr \
	--enable-mbstring=all \
	--enable-mbregex \
	--enable-json=shared \
	--with-iconv=shared \
	--with-xmlrpc=shared \
	--without-pspell \
	--with-freetype-dir=shared,/usr \
	--with-mime-magic=shared \
	"

	cd ${srcdir}/${pkgname}-${pkgver}

	# avoid linking against old db version
	patch -p0 -i ${srcdir}/db-configure.patch || return 1

	# apply suhosin patch
	patch -p1 -i ${srcdir}/suhosin-patch-${pkgver}-${_suhosinver}.patch || return 1

	# cli
	./configure ${phpconfig} \
		--disable-cgi \
		--with-readline \
		--enable-pcntl \
		--with-pear=/usr/share/pear \
		${phpextensions} || return 1
	make || return 1
	# make test
	make INSTALL_ROOT=${pkgdir} install || return 1

	# fix pear path
	sed "s|$PWD||g" -i ${pkgdir}/usr/{bin/pear,share/pear/pearcmd.php}
	# cleanup
	rm -f ${pkgdir}`${pkgdir}/usr/bin/php-config --extension-dir`/*.a
	rm -rf ${pkgdir}/{.registry,.channels,.depdb*,.lock,.filemap}
	rmdir ${pkgdir}/usr/include/php/include
	# install php.ini
	install -D -m644 ${srcdir}/php.ini ${pkgdir}/etc/php/php.ini
	install -d -m755 ${pkgdir}/etc/php/conf.d/

	# cgi and fcgi
	./configure ${phpconfig} \
		--enable-fastcgi \
		--enable-cgi \
		--enable-discard-path \
		--enable-force-cgi-redirect \
		--disable-cli \
		${phpextensions} || return 1
	make || return 1
	install -D -m755 sapi/cgi/php-cgi ${pkgdir}/usr/bin/php-cgi || return 1

	# mod_php
#	./configure ${phpconfig} \
#		--with-apxs2 \
#		--disable-cli \
#		${phpextensions} || return 1
#	make || return 1
#	install -D -m644 libs/libphp5.so ${pkgdir}/usr/lib/httpd/modules/libphp5.so || return 1
#	install -D -m644 ${srcdir}/apache.conf ${pkgdir}/etc/httpd/conf/extra/php5_module.conf || return 1
}