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

name                gtk-doc
version             1.36.1
revision            0

categories          gnome devel
license             GPL-2+
maintainers         {mascguy @mascguy} openmaintainer
description         GTK+/GNOME API documentation generator
long_description    GTK-Doc generates API documentation from comments added to C code. \
                    It is typically used to document the public API of GTK+  and GNOME \
                    libraries, but it can also be used to document application code.
homepage            https://wiki.gnome.org/DocumentationProject/GtkDoc

platforms           any
supported_archs     noarch
installs_libs       no

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        gnome:sources/${name}/${branch}/
use_xz              yes

checksums           rmd160  0a262625813293d51dd9189795e2ce1a1df59516 \
                    sha256  0e517a5f97069831181be177516bde8aa8b3922398f2bdb09e265d22aecadbc5 \
                    size    594020

depends_build-append \
                    path:lib/pkgconfig/glib-2.0.pc:glib2

depends_lib-append \
                    port:docbook-xml \
                    port:docbook-xsl-nons \
                    port:itstool \
                    port:libxml2 \
                    port:libxslt \
                    path:bin/pkg-config:pkgconfig

configure.env-append \
                    XSLTPROC=${prefix}/bin/xsltproc
configure.args-append \
                    -Dautotools_support=true \
                    -Dcmake_support=true \
                    -Dtests=false \
                    -Dyelp_manual=false

variant pdf description {Build with PDF output support} {
    depends_lib-append \
                    port:fop
}

variant tests description {Build with tests} {
    configure.args-replace \
                    -Dtests=false \
                    -Dtests=true

    # some tests are known to fail in gtk-doc 1.29+
    # see https://gitlab.gnome.org/GNOME/gtk-doc/blob/7db567e83fe5d2d0659560c6dfb25ee27b338140/NEWS
    test.run            yes
}

proc py_setup {p_py_ver} {
    global prefix worksrcpath
    # Note: we must export these vars, due to lazy expansion inside strings
    global py_ver py_ver_nodot py_bin

    set py_ver ${p_py_ver}
    set py_ver_nodot [string map {. {}} ${py_ver}]
    set py_bin ${prefix}/bin/python${py_ver}

    configure.python ${py_bin}

    patchfiles-append \
                    patch-meson-python3.diff

    post-patch {
        reinplace "s|@@PYTHON3_BIN@@|${py_bin}|" \
                    meson.build

        # Fix python shebangs
        fs-traverse f ${worksrcpath} {
            if {[string match *.py ${f}]} {
                ui_info "patching python script: ${f}"
                reinplace -q "s|/usr/bin/python3$|${configure.python}|" ${f}
                reinplace -q "s|/usr/bin/env python2$|${configure.python}|" ${f}
                reinplace -q "s|/usr/bin/env python3$|${configure.python}|" ${f}
            }
        }
    }

    depends_lib-append \
                    port:python${py_ver_nodot} \
                    port:py${py_ver_nodot}-anytree \
                    port:py${py_ver_nodot}-lxml \
                    port:py${py_ver_nodot}-pygments

    depends_test-append \
                    port:py${py_ver_nodot}-mock
}

variant python310 conflicts python311 python312 python313 python314 description {Build using Python 3.10} {
    py_setup 3.10
}

variant python311 conflicts python310 python312 python313 python314 description {Build using Python 3.11} {
    py_setup 3.11
}

variant python312 conflicts python310 python311 python313 python314 description {Build using Python 3.12} {
    py_setup 3.12
}

variant python313 conflicts python310 python311 python312 python314 description {Build using Python 3.13} {
    py_setup 3.13
}

variant python314 conflicts python310 python311 python312 python313 description {Build using Python 3.14} {
    py_setup 3.14
}

if {![variant_isset python310] &&
    ![variant_isset python311] &&
    ![variant_isset python312] &&
    ![variant_isset python313] &&
    ![variant_isset python314] } {
    default_variants +python314
}

livecheck.type      gnome
