--- Portfile-orig	Mon Aug 11 23:30:28 2003
+++ Portfile	Wed Aug 13 09:28:06 2003
@@ -3,7 +3,7 @@
 PortSystem 1.0
 name            php4
 version         4.3.2
-categories      www
+categories      lang,www
 maintainers    	bchesneau@mac.com
 description     PHP: Hypertext Preprocessor
 long_description 	PHP is a widely-used general-purpose scripting language \
@@ -16,43 +16,83 @@
 		http://www.php.net/distributions/
 checksums	php-4.3.2.tar.gz md5 8433a1d0ce679780990d4813ae094590
 
-depends_lib	lib:libcurl.2:curl \
-		lib:libiconv.2:libiconv \
+depends_lib	lib:libiconv.2:libiconv \
 		lib:libexpat.0.4:expat  \
 		lib:libintl:gettext \
-		lib:libjpeg.9:jpeg \
-		lib:libpng3:libpng \
-		lib:libmhash:mhash \
 		lib:libz.1:zlib
 
-set imapversion 2002d
+set PHP_INSTALLTARGETS "install-cli install-modules install-pear install-build install-headers install-programs"
 				
-configure.env	LDFLAGS=-L${prefix}/lib CPPFLAGS=-I${prefix}/include
+configure.env	LDFLAGS=-L${prefix}/lib \
+				CPPFLAGS=-I${prefix}/include
+
+
+if { ![variant_isset apache] } {
+	configure.args-append	--enable-discard-path
+}
+
+if { ![variant_isset cli] } {
+	configure.args-append	--disable-cli
+}
 
 configure.args	--mandir=${prefix}/share/man --infodir=${prefix}/share/info \
 		--with-config-file-path=${prefix}/etc --enable-calendar \
 		--with-iconv=${prefix} --enable-exif --enable-ftp --enable-wddx\
-		--with-zlib --with-curl=${prefix} --with-gd --with-jpeg-dir=${prefix} \
-		--with-png-dir=${prefix} --without-mysql --with-gettext=${prefix} \
-		--with-mhash=${prefix} --with-expat-dir=${prefix} --with-iconv-dir=${prefix} \
+		--with-zlib --without-mysql --with-gettext=${prefix} \
+		--with-expat-dir=${prefix} --with-iconv-dir=${prefix} \
 		--with-xmlrpc --enable-filepro --enable-bcmath
-
+		
 variant darwin {
 	depends_lib-append	lib:libdl.1:dlcompat
 }
 
+variant cli {}
+
 variant apache {
-	depends_lib-append	path:${prefix}/apache-1.3.27/sbin/apxs:apache
-	configure.args-append --with-apxs=${prefix}/apache-1.3.27/sbin/apxs
+	global APACHE_VER
+	
+	if { [file readable ${prefix}/sbin/apxs] } {
+		configure.args-append 	--with-apxs=${prefix}/sbin/apxs
+		set APACHE_VER ""
+	} elseif { [file readable ${prefix}/include/apache2/apr.h] } {
+		configure.args-append 	--with-apxs2=${prefix}/sbin/apxs
+		set APACHE_VER 2
+	} else {					
+		depends_lib-append	path:${prefix}/sbin/apxs:apache
+		configure.args-append 	--with-apxs=${prefix}/sbin/apxs
+		set APACHE_VER ""
+	}
 }
 
-variant apache2 {
-        depends_lib-append      path:${prefix}/apache2/bin/apxs:apache2
-	configure.args-append --with-apxs2=${prefix}/apache2/bin/apxs
+variant crypt {
+
+	depends_lib-append	lib:libmhash:mhash \
+						lib:libmcrypt:libmcrypt
+	configure.args-append	--with-mhash=${prefix} --with-mcrypt=${prefix}
+}	
+
+variant curl {
+	depends_lib-append	lib:libcurl.2:curl
+	configure.args-append	--with-curl=${prefix}
+}
+
+variant gd {
+	depends_lib-append	lib:libjpeg.9:jpeg \
+						lib:libpng3:libpng
+						
+	
+	configure.args-append	--with-gd \
+							--with-jpeg-dir=${prefix} \
+							--with-png-dir=${prefix}
 }
 
 variant mysql {
-	depends_lib-append	lib:libmysqlclient:mysql
+
+	if [file readable ${prefix}/lib/mysql/libmysqlclient.so.10 ] {
+		depends_lib-append	lib:libmysqlclient.10:mysql
+	} elseif [file  readable ${prefix}/lib/mysql/libmysqlclient.so.12 ] {
+		depends_lib-append	lib:libmysqlclient.12:mysql4
+	}
 	configure.args-append	--with-mysql=${prefix}
 }
 
@@ -63,27 +103,54 @@
 	configure.args-append	--with-pgsql=${prefix}/pgsql 
 }
 
-variant imap {
-	master_sites-append 	ftp://ftp.cac.washington.edu/imap/:imap\
-				http://distfiles.opendarwin.org/:imap
-	distfiles-append	imap-${imapversion}.tar.Z:imap
-	checksums-append	imap-2002d.tar.Z md5 64e82a195d21481fc4c54c4ed9fe0527
-
-	extract.only		php-${version}.tar.gz imap-${imapversion}.tar.Z
-	configure.args-append 	--with-imap=../imap-${imapversion} --with-imap-ssl=/usr
+variant ssl {
+	configure.args-append	--with-openssl=/usr
 }
 
-pre-configure {
-	if { [variant_isset imap] } {
-		system "cd ${workpath}/imap-${imapversion} && \
-						make osx SSLTYPE=nopwd"
-		system "cd ${workpath}/${worksrcdir}"
+variant imap {
+	depends_lib-append		lib:c-client:cclient
+	configure.env-append	 CFLAGS=-I${prefix}/include/c-client
+	
+		
+	if { [variant_isset ssl] } {
+		configure.args-append 	--with-imap=${prefix} --with-imap-ssl=/usr
+	} else {
+		configure.args-append	--with-imap=${prefix}
 	}
 }
 
-destroot.args	prefix=${destroot}${prefix}
+variant xslt {
+	depends_lib-append	lib:libsablot:sablotron
+	
+	configure.args-append	--enable-xslt --with-xslt-sablot=${prefix} \
+							--with-iconv-dir=${prefix}  --with-expat-dir=${prefix}
+ }
+
+
+destroot.args	INSTALL_ROOT=${destroot}${prefix} PHP_PEAR_INSTALL_DIR=${prefix}/lib/php
+
+destroot.target		${PHP_INSTALLTARGETS}
+
 	
 post-destroot	{
+
+	#copy module
+	if { [variant_isset apache] } {
+		file mkdir ${destroot}${prefix}/libexec/apache${APACHE_VER}
+		system "install -m 755 ${worksrcpath}/libs/libphp4.so ${destroot}${prefix}/libexec/apache${APACHE_VER}/"
+	}
+
+	#copy php.ini
 	file mkdir ${destroot}${prefix}/etc
-	system "cp ${workpath}/${worksrcdir}/php.ini-dist ${destroot}${prefix}/etc/php.ini"
+	system "install -m 755 ${workpath}/${worksrcdir}/php.ini-dist ${destroot}${prefix}/etc/php.ini-dist"
+	system "install -m 755 ${workpath}/${worksrcdir}/php.ini-recommended ${destroot}${prefix}/etc/php.ini-recommended"
+
+	
+	#copy conffiles
+	file mkdir ${destroot}${prefix}/etc/apache${APACHE_VER}
+	file mkdir ${destroot}${prefix}/etc/apache${APACHE_VER}/modules.d
+	file mkdir ${destroot}${prefix}/etc/apache${APACHE_VER}/extras-conf
+	system "install -o root -m 755 -c  ${portpath}/files/mod_php ${destroot}${prefix}/etc/apache${APACHE_VER}/modules.d"
+	system "install -o root -m 755 -c  ${portpath}/files/mod_php.conf ${destroot}${prefix}/etc/apache${APACHE_VER}/extras-conf"
+	
 }
