# -*- 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.22.0
# 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     18ecca5d54471f21918798da451dd8d03a18f3c7
set psl_data_date       20260624
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  486716c479891ae0446521b3abed3c9ac91f5141 \
                    sha256  c45c3aa17576b99873e05a9b09a44041b065bbfa390e6d474d06fbfaeb9c7722 \
                    size    7745227 \
                    ${psl_data_distfile} \
                    rmd160  0f7b867ed1f00aba43a30602bb9e654c1e9db0ff \
                    sha256  5fa1d3f28c224ba2e2470717a44e318d25b24d897d7f7f50cc70a7156dbe4a29 \
                    size    302617

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