# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 94400 2012-06-17 23:10:24Z ryandesign@macports.org $

PortSystem 1.0

name				mod_perl2
version				2.0.7
revision			1
maintainers			cyberscript.net:ryan
categories			www
license				Apache-2
platforms			darwin
description			Embeds a Perl interpreter in the Apache2 server
long_description	mod_perl brings together the full power of the Perl programming language \
					and the Apache HTTP server. You can use Perl to manage Apache, respond to \
					requests for web pages and much more. \
					\
					mod_perl gives you a persistent Perl interpreter embedded in your web \
					server. This lets you avoid the overhead of starting an external interpreter \
					and avoids the penalty of Perl start-up time, giving you super-fast \
					dynamic content. \
					\
					As you'd expect from the Perl community, there are hundreds of modules \
					written for mod_perl, everything from persistent database connections, to \
					templating sytems, to complete XML content delivery systems. Web sites like \
					Slashdot and Wired Magazine use mod_perl.
homepage			http://perl.apache.org/
master_sites		http://perl.apache.org/dist/
distname			mod_perl-${version}

checksums           rmd160  14505fd08f6915c8a260c9068608bde6ebcbac24 \
                    sha256  53414be9db843054b927f23a35edb7b82d99e32e031b3cd81d5ff2473f51e3c6

depends_lib			path:bin/perl:perl5 port:apache2
worksrcdir			mod_perl-${version}

if {${configure.compiler} == "clang"} {
    patchfiles-append clang-compatibility_src-modules-perl-modperl_common_util.h.patch
}

pre-configure {
    set perl5bin "${prefix}/bin/perl5"
    if {[string first "true" [exec ${perl5bin} -V:useshrplib]] == -1} {
        ui_error "${name} requires perl5 to be installed with the +shared variant."
        return -code error "perl5 must be +shared"
    }
    if {[string first "define" [exec ${perl5bin} -V:usethreads]] == -1} {
        ui_error "${name} requires perl5 to be installed with the +threads variant."
        return -code error "perl5 must be +threads"
    }
}

configure {
	set APXS ${prefix}/apache2/bin/apxs
	system "cd ${workpath}/${worksrcdir} && \
		${prefix}/bin/perl Makefile.PL MP_APXS=${APXS}"
}

destroot.violate_mtree yes

post-destroot {
		xinstall -m 755 -d ${destroot}${prefix}/apache2/include/modules/perl \
			${destroot}${prefix}/apache2/libexec
		system "install -m 755 ${worksrcpath}/src/modules/perl/*.h \
    	        ${destroot}${prefix}/apache2/include/modules/perl"

		xinstall -m 755 ${worksrcpath}/src/modules/perl/mod_perl.so \
			${destroot}${prefix}/apache2/libexec/

		fs-traverse f ${destroot}${prefix} {
			if {[file isfile ${f}]} {
				switch [file tail ${f}] {
					.packlist -
					perllocal.pod {
						delete ${f}
					}
				}
			}
		}
}

post-install {
	ui_msg "\nIf this your first install, you might want to"
	ui_msg " * enable mod_perl in apache :\n"
	ui_msg "cd ${prefix}/apache2/libexec"
	ui_msg "${prefix}/apache2/bin/apxs -a -e -n \"perl\" mod_perl.so\n"
	ui_msg " * And then relaunch apache \n"
	ui_msg "${prefix}/apache2/bin/apachectl restart\n"
}

livecheck.url       [lindex ${master_sites} 0]
livecheck.type      regex
livecheck.regex     "mod_perl-(\\d+\\.\\d+(\[0-9rc.\]+)?).tar.gz"
