# -*- 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       github 1.0
PortGroup       php 1.1

name            php-mailparse
license         PHP
categories-append       mail devel
maintainers     {ryandesign @ryandesign} {mathiesen.info:macintosh @BjarneDMat} openmaintainer

# Compatible with PHP 8.4 as of 3.1.8
php.branches    5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4 8.5 8.6

# This extension must load after the mbstring extension.
php.extension_ini       ~${php.extension_ini}

if {[vercmp ${php.branch} >= 7.3]} {
    version             3.2.2
    revision            0
    checksums           rmd160  0f247a2743f10a314cfa2c803e7fa1ee94ef80f0 \
                        sha256  a1b7c759efdd43a68471f76c9a9c5920e3333195177341b41c9f025f77161745 \
                        size    959820
} elseif {[vercmp ${php.branch} >= 7.0]} {
    version             3.1.3
    revision            1
    checksums           rmd160  c9d0cdcd4c7e20672c46d5ef4da27333ca7d67e7 \
                        sha256  57f35ee52ad59e0d5bd751d6aab7ca23e612d9c2725909eb5e9b4c4be452063c \
                        size    944871
} else {
    version             2.1.6
    revision            2
    checksums           rmd160  f6de6dceba3c00ee07108510c88a337f87052131 \
                        sha256  895fe1771a3dd664e98919911b1595169753a4906d0bd2f9c54795017166f2e5 \
                        size    34867
}

description     Email message manipulation

long_description \
    Mailparse is an extension for parsing and working with email messages. \
    It can deal with rfc822 and rfc2045 (MIME) compliant messages.

if {${name} ne ${subport}} {
    # remove w/ next update
    dist_subdir                 ${name}/${version}_1

    if {[vercmp ${php.branch} >= 7.0]} {
        set add_prefix  v
    } else {
        set add_prefix  mailparse-
    }
    github.tarball_from         archive
    github.setup                php pecl-mail-mailparse ${version} ${add_prefix}

    depends_build       port:autoconf port:${php}-mbstring
    depends_run         port:${php}-mbstring

    configure.cppflags-append -DHAVE_MBSTRING

    test.run            yes

    post-destroot {
        set docdir ${prefix}/share/doc/${subport}
        xinstall -d ${destroot}${docdir}
        xinstall -m 0644 -W ${worksrcpath} CREDITS ${destroot}${docdir}
        if {[vercmp ${version} >= 3.0.3]} {
            xinstall -m 0644 -W ${worksrcpath} README.md ${destroot}${docdir}
        } else {
            xinstall -m 0644 -W ${worksrcpath} README ${destroot}${docdir}
        }
    }
}
