# $Id: Portfile,v 1.34 2006/05/08 15:15:01 jberry Exp $

PortSystem 1.0
name             apache2
version          2.2.2
revision         1

categories       www
maintainers      james@imajes.info
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.
homepage         http://httpd.apache.org/
platforms        darwin freebsd openbsd

master_sites     apache:httpd
distname         httpd-${version}
checksums        md5 9c759a9744436de6a6aa2ddbc49d6e81
use_bzip2        yes

depends_lib      port:apr \
                 port:apr-util \
                 port:expat \
		 port:openssl \
		 port:pcre

patchfiles       patch-httpd-std.conf.in 

platform darwin {
	post-patch {
		# Customize userdir naming to match darwin
		reinplace "s|/home/|/Users/|g" ${worksrcpath}/docs/conf/extra/httpd-userdir.conf.in
		reinplace "s|public_html|Sites|g" ${worksrcpath}/docs/conf/extra/httpd-userdir.conf.in
	}
}

platform darwin 7 {
	pre-configure {
		system "cd ${worksrcpath} && glibtoolize --force"
	}
}

configure.pre_args --prefix=${prefix}/${name}
configure.args     --with-apr=${prefix}/bin/apr-1-config \
                   --with-apr-util=${prefix}/bin/apu-1-config \
                   --libdir=${prefix}/lib \
                   --with-expat=${prefix} \
		   --with-pcre=${prefix} \
                   --mandir=${prefix}/share/man \
                   --enable-mods-shared=all \
                   --enable-ssl \
                   --with-ssl=${prefix} \
                   --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
}

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

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

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

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

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

