# $Id$

# Besides having a Port for the Apache 2.0.x line, this Port was built
# to allow Apache 2.x.y on Mac OS X 10.3 to serve PHP Zend encoded
# files using the Zend Optimizer.  The Zend Optimizer is distributed
# only in binary form as an Apache module that enables the server to
# serve optimized and obfuscated PHP code from third party vendors.
# Since the Optimizer is a binary module, it must run in a binary
# compatible OS and Apache environment.
#
# While newer versions of the Zend Optimizer do work with Apache
# 2.2.x, it appears that these binary modules are compiled on 10.4 and
# trying to load the module into Apache on 10.3 results in missing
# symbol errors.  When older versions of the Zend Optimizer that work
# on 10.3 are loaded into Apache 2.2.x, then the error_log will have
# messages about double free memory errors.  So the only combination
# that works on 10.3 is with Apache 2.0.x.

PortSystem 1.0

name             apache20
version          2.0.64

categories       www
maintainers      blair
description      The extremely popular second version of the Apache http \
			server
long_description Apache is an HTTP server designed as a plug-in replacement \
			for the NCSA server version 1.3 (or 1.4).  It fixes \
			numerous bugs in the NCSA server and includes many \
			frequently requested new features, and has an API \
			which allows it to be extended to meet users' needs \
			more easily.  This Portfile is not the latest version \
			of the Apache web server, see the apache2 port.  \
			Besides having a Port for the Apache 2.0.x line, this \
			Port was built to allow Apache 2.x.y on Mac OS X 10.3 \
			to serve PHP Zend encoded files using the Zend \
			Optimizer.  The Zend Optimizer is distributed only in \
			binary form as an Apache module that enables the \
			server to serve optimized and obfuscated PHP code \
			from third party vendors.   Since the Optimizer is a \
			binary module, it must run in a binary compatible OS \
			and Apache environment.   While newer versions of the \
			Zend Optimizer do work with Apache 2.2.x, it appears \
			that these binary modules are compiled on 10.4 and \
			trying to load the module into Apache on 10.3 results \
			in missing symbol errors.  When older versions of the \
			Zend Optimizer that work on 10.3 are loaded into \
			Apache 2.2.x, then the error_log will contain \
			messages about double free memory errors.  So the \
			only combination that works on 10.3 is with Apache \
			2.0.x.

homepage         http://httpd.apache.org/
platforms        darwin freebsd openbsd

master_sites     apache:httpd
distname         httpd-${version}
use_bzip2        yes

checksums        sha1    eeabe0fb428d9f11ce00559ff163740c6ceabf1c \
                 rmd160  6a4bfe4dfc4119a70cabbec2e0865dc2f12e8ec4

depends_lib      port:apr0 \
                 port:apr-util0 \
                 port:expat \
		 port:openssl \
                 port:pcre \
                 port:perl5

patchfiles       patch-httpd-std.conf.in \
                 patch-docs-cgi-examples-printenv.diff \
                 patch-openssl-1.0.0.diff

platform darwin {
	post-patch {
		reinplace "s|@PREFIX@|${prefix}|g" ${worksrcpath}/docs/cgi-examples/printenv
		# Customize userdir naming to match darwin
		reinplace "s|/home/|/Users/|g" ${worksrcpath}/docs/conf/httpd-std.conf.in
		reinplace "s|public_html|Sites|g" ${worksrcpath}/docs/conf/httpd-std.conf.in
	}
}

configure.pre_args --prefix=${prefix}/${name}
configure.args     --with-apr=${prefix}/bin/apr-config \
                   --with-apr-util=${prefix}/bin/apu-config \
                   --libdir=${prefix}/lib \
		   --with-pcre=${prefix} \
                   --mandir=${prefix}/share/man \
                   --enable-mods-shared=all \
                   --enable-ssl \
                   --with-ssl=${prefix} \
                   --enable-cache \
                   --enable-disk_cache \
                   --enable-file_cache \
                   --enable-mem_cache \
                   --enable-deflate \
                   --enable-proxy \
                   --enable-proxy-connect \
                   --enable-proxy-http \
                   --enable-proxy-ftp
                   
post-configure {
	# Setting DYLD_FALLBACK_LIBRARY_PATH instead of DYLD_LIBRARY_PATH
	# avoids issues with library collisions (bug #3013)
	reinplace "s|DYLD_LIBRARY_PATH|DYLD_FALLBACK_LIBRARY_PATH|g" \
		${worksrcpath}/support/envvars-std
}

destroot.violate_mtree yes

post-destroot {
	set confDir ${destroot}${prefix}/apache20/conf
	file rename -force ${confDir}/httpd.conf ${confDir}/httpd.conf.sample

	destroot.keepdirs ${destroot}${prefix}/apache20/logs

	# fix libtool path
	reinplace "s|/apache20/build/libtool|/share/apr-0/build/libtool|g" \
		${destroot}${prefix}/apache20/build/config_vars.mk

	set mandir ${destroot}${prefix}/share/man/man1
	file rename -force ${mandir}/dbmmanage.1 ${mandir}/dbmmanage20.1
	file rename -force ${mandir}/htdbm.1 ${mandir}/htdbm20.1
	file rename -force ${mandir}/htdigest.1 ${mandir}/htdigest20.1
	file rename -force ${mandir}/htpasswd.1 ${mandir}/htpasswd20.1

	set mandir ${destroot}${prefix}/share/man/man8
	file rename -force ${mandir}/ab.8 ${mandir}/ab20.8
	file rename -force ${mandir}/apachectl.8 ${mandir}/apachectl20.8
	file rename -force ${mandir}/apxs.8 ${mandir}/apxs20.8
	file rename -force ${mandir}/httpd.8 ${mandir}/httpd20.8
	file rename -force ${mandir}/logresolve.8 ${mandir}/logresolve20.8
	file rename -force ${mandir}/rotatelogs.8 ${mandir}/rotatelog20.8
	file rename -force ${mandir}/suexec.8 ${mandir}/suexec20.8
}

platform openbsd {
	build.env-append "LD_LIBRARY_PATH=${prefix}/lib"
}

variant openldap description {Enable LDAP support through OpenLDAP} {
	configure.args-append --enable-ldap --enable-authnz-ldap
	depends_lib-append port:openldap
	pre-configure {
		if {-1 == [string first -lldap [exec ${prefix}/bin/apu-config --libs]]} {
			ui_error "To install ${name} with the +openldap variant, apr-util0 must be installed"
			ui_error "with the +openldap variant. Rebuild apr-util0 using:"
			ui_error
			ui_error "    sudo port upgrade --enforce-variants apr-util0 +openldap"
			ui_error
			return -code error "incompatible apr-util0 installation"
		}
	}
}

variant preforkmpm conflicts workermpm description {Use prefork MPM} {
	configure.args-append --with-mpm=prefork
}

variant workermpm conflicts preforkmpm description {Use worker MPM} {
	configure.args-append --with-mpm=worker
}

if {![variant_isset workermpm] && ![variant_isset eventmpm]} {
	default_variants +preforkmpm
}

variant no_startupitem description {Do not create a startup item} {
	startupitem.create	no
}

startupitem.create	yes
startupitem.start	\
"\[ -x ${prefix}/apache20/bin/apachectl \] && ${prefix}/apache20/bin/apachectl start > /dev/null"
startupitem.stop	\
"\[ -r ${prefix}/apache20/logs/httpd.pid \] && ${prefix}/apache20/bin/apachectl stop > /dev/null"
startupitem.restart	\
"\[ -r ${prefix}/apache20/logs/httpd.pid \] && ${prefix}/apache20/bin/apachectl restart > /dev/null"

notes "
Apache 2.0 is obsolete. Please update to Apache 2.2 (the apache2 port).\
For information on how to update your web server configuration, please see\
http://httpd.apache.org/docs/2.2/upgrading.html
"

livecheck.type	regex
livecheck.url	${homepage}
livecheck.regex	{Apache (2\.0(?:\.\d+)*) Released}