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

name                gtk-doc
version             1.34.0
revision            0

categories          gnome devel
license             GPL-2+
platforms           any
supported_archs     noarch
installs_libs       no
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

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

checksums           rmd160  9362899e58de810c6c7cf964f5fe4fe94c7994b7 \
                    sha256  b20b72b32a80bc18c7f975c9d4c16460c2276566a0b50f87d6852dff3aa7861c \
                    size    494116

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 \
                    port:pkgconfig

# As of version 1.34.x, upstream no longer provides pre-generated configure script.
use_autoreconf      yes
autoreconf.args     -fvi

configure.env-append \
                    XSLTPROC=${prefix}/bin/xsltproc
configure.args-append \
                    --disable-silent-rules \
                    --with-xml-catalog=${prefix}/etc/xml/catalog

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

if {![variant_isset pdf]} {
    patchfiles-append \
                    patch-disable-pdf.diff
}

proc py_setup {p_py_ver} {
    global prefix py_ver py_ver_nodot
    set py_ver ${p_py_ver}
    set py_ver_nodot [string map {. {}} ${py_ver}]

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

    post-patch {
        # Fixup shebangs referencing generic python3
        reinplace "s|^#!/usr/bin/env python3|#!${prefix}/bin/python${py_ver}|" \
                    gtkdoc/highlight.py \
                    gtkdoc/mkhtml2.py \
                    tools/db2md.py
    }

    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 python39 conflicts python310 python311 python312 python313 description {Build using Python 3.9} {
    py_setup 3.9
}

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

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

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

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

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

# 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
test.dir            ${worksrcpath}/tests
test.target         check

livecheck.type      gnome
