# -*- 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

PortSystem          1.0
PortGroup           perl5 1.0
PortGroup           active_variants 1.1

perl5.branches      5.28 5.30 5.32 5.34
perl5.setup         libapreq2 2.13 Apache2
revision            6
license             Apache-2
maintainers         nomaintainer
description         Methods for dealing with client request data
long_description    Apache::Request is a subclass of the Apache class, \
                    which adds methods for parsing GET requests and POST \
                    requests where Content-type is one of \
                    application/x-www-form-urlencoded or \
                    multipart/form-data.

homepage            https://metacpan.org/release/${perl5.module}
platforms           darwin

checksums           rmd160  8d7d2573624193b6dfbbe354b3771012257c1578 \
                    sha256  5731e6833b32d88e4a5c690e45ddf20fcf969ce3da666c5627d775e92da0cf6e

set apachectl       ${prefix}/sbin/apachectl
set apxs            ${prefix}/bin/apxs
set mdir            ${prefix}/lib/apache2/modules/

if {${perl5.major} != ""} {
depends_lib-append  port:apache2 \
                    port:mod_perl2 \
                    port:p${perl5.major}-extutils-xsbuilder

patchfiles-append   patch-apache24-use-mutex-not-lockfile.diff \
                    dynamic_lookup-11.patch

set required_variant [string map {. _} "perl${perl5.major}"]

require_active_variants \
                    mod_perl2 $required_variant

configure.args      --with-apache2-apxs=${apxs} \
                    --with-mm-opts="${configure.args}"

destroot.pre_args   install

## stolen from perl5 group code
post-destroot {
    foreach packlist [exec find ${destroot} -name .packlist] {
        ui_info "Fixing packlist ${packlist}"
        reinplace "s|${destroot}||" ${packlist}
    }
    foreach badfile [exec find ${destroot} -name perllocal.pod] {
        ui_info "Removing ${badfile}"
        file delete ${badfile}
    }
}

# the subports conflict with each other
# deactivate any active conflicting subport prior to activation
# https://trac.macports.org/ticket/42582
pre-activate {
    foreach major ${perl5.branches} {
        if {$major != ${perl5.major}} {
            set pname p${major}-libapreq2
            if {![catch {set installed [lindex [registry_active $pname] 0]}]} {
                registry_deactivate_composite $pname "" [list ports_nodepcheck 1]
            }
        }
    }
}

notes "
If this your first install, you might want to enable apreq in apache:

    cd $mdir
    sudo ${apxs} -a -e -n \"apreq\" mod_apreq2.so

And then relaunch apache:

    ${apachectl} restart
"
}
