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

epoch               1
github.setup        rockdaboot libpsl 0.21.5
# When increasing the version or revision please check
# that psl_data_commit and psl_data_date refer to latest
# https://github.com/publicsuffix/list git master commit

license             MIT
description         A C library and utility to handle the Public Suffix List
long_description    {*}${description}
maintainers         nomaintainer
categories          net

github.tarball_from releases
set main_distfile   ${distfiles}

set psl_data_commit     9094af5c6cb260e69137c043c01be18fee01a540
set psl_data_date       20240306
set psl_data_worksrcdir list-${psl_data_commit}
set psl_data_distname   publicsuffix-list-[string range ${psl_data_commit} 0 6]
set psl_data_distfile   ${psl_data_distname}${extract.suffix}

version             ${version}-${psl_data_date}

distfiles           ${main_distfile}:main \
                    ${psl_data_distfile}:list

master_sites        ${github.master_sites}:main \
                    https://github.com/publicsuffix/list/archive/${psl_data_commit}:list

checksums           ${main_distfile} \
                    rmd160  31dda77d700a85ef9249a97297191f73d73f0b28 \
                    sha256  1dcc9ceae8b128f3c0b3f654decd0e1e891afc6ff81098f227ef260449dae208 \
                    size    7624251 \
                    ${psl_data_distfile} \
                    rmd160  6fd5daec1e96318fef28c2d8f98bd8e4590df0da \
                    sha256  bcfa49fc92c5d5231492b1f1c6fd30d5e8e5293a2607a60a1e5c69098755b8f6 \
                    size    117933

# Please note this port is (indirectly, via cmake) a dependency of the
# various clang-X ports. When updating the port versions (e.g. python)
# used here make sure to ensure that the new port being used uses the
# clang_dependency PortGroup to avoid circular dependencies whilst building.
# See e.g. https://trac.macports.org/ticket/60419

# DO NOT change this unless you have understood and acted on the above comment!
set py_ver          3.10
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    port:gettext \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib-append  \
                    port:gettext-runtime \
                    port:libiconv \
                    port:libidn2 \
                    port:libunistring

license_noconflict  python${py_ver_nodot}

post-extract {
    # Replace older bundled publicsuffix list.
    delete ${worksrcpath}/list
    move ${workpath}/${psl_data_worksrcdir} ${worksrcpath}/list
}

post-patch {
    reinplace "s|^#!.*|#!${prefix}/bin/python${py_ver}|" \
        ${worksrcpath}/src/psl-make-dafsa
}

configure.python    ${prefix}/bin/python${py_ver}

configure.args      --enable-builtin \
                    --enable-runtime=libidn2 \
                    --disable-silent-rules

if {${subport} eq ${name}} {
    revision            0

    configure.args-append \
        --disable-gtk-doc \
        --disable-gtk-doc-html \
        --disable-gtk-doc-pdf

    notes "${name} API documentation is provided by the ${name}-docs port."
}

subport ${name}-docs {
    revision            0

    description         GTK docs for libpsl.
    long_description    {*}${description}
    platforms           any
    supported_archs     noarch

    depends_build-append \
        port:gtk-doc

    depends_lib-append \
        port:libpsl

    configure.args-append \
        --enable-gtk-doc

    post-destroot {
        delete ${destroot}${prefix}/bin \
            ${destroot}${prefix}/include \
            ${destroot}${prefix}/lib \
            ${destroot}${prefix}/share/man
    }
}