# $Id: Portfile 50980 2009-05-14 19:41:55Z and.damore@macports.org $

PortSystem       1.0

name             apache2
version          2.2.11
categories       www
maintainers      imajes
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}
use_bzip2        yes
use_parallel_build  yes

checksums        md5     3e98bcb14a7122c274d62419566431bb \
                 sha1    7af256d53b79342f82222bd7b86eedbd9ac21d9a \
                 rmd160  b2012af716a459f666e0e41eb04808bd0f7fc28d

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

post-patch {
    reinplace -E "s/(User|Group) daemon/\\1 www/" ${worksrcpath}/docs/conf/httpd.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
	}

	# HFS can be case insensitive, so protect for this as in 
	# http://docs.info.apple.com/article.html?artnum=300422
	patchfiles-append   patch-httpd.conf.in-sensitive-files.diff
}

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

platform darwin 9 {
	post-extract {
		reinplace "s|-export-symbols-regex ssl_module||g" ${worksrcpath}/configure
	}
}

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-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}/apache2/conf
    eval delete ${confDir}/httpd.conf [glob -directory ${confDir}/extra *.conf]

	destroot.keepdirs ${destroot}${prefix}/apache2/logs \
	                  ${confDir}/extra

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

    set docdir ${prefix}/share/doc/apache-${version}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} ABOUT_APACHE CHANGES LICENSE NOTICE README \
        README.platforms ROADMAP VERSIONING ${destroot}${docdir}
}

post-activate {
    set confDir ${prefix}/apache2/conf
    # Make sure initial conf files are present and set up correctly
    if {![file exists ${confDir}/httpd.conf]} {
        file copy ${confDir}/original/httpd.conf \
             ${confDir}/httpd.conf
    }
    foreach f [glob -tails -directory ${confDir}/original/extra *.conf] {
        if {![file exists ${confDir}/extra/${f}]} {
            file copy ${confDir}/original/extra/${f} \
                 ${confDir}/extra/${f}
        }
    }
}

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

variant openldap {
	configure.args-append --enable-ldap --enable-authnz-ldap
	depends_lib-append port:openldap
}

# This ends up being the default mpm if no other is chosen
variant preforkmpm {
	configure.args-append --with-mpm=prefork
}

# This mpm is probably preferred (maybe we should make it a default variant?)
variant workermpm {
	configure.args-append --with-mpm=worker
}

# This mpm is experimental
variant eventmpm {
	configure.args-append --with-mpm=event
}

variant no_startupitem {
	startupitem.create	no
}

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	\
"${prefix}/apache2/bin/apachectl restart > /dev/null"

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

