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

name                py-gobject3
set my_name         pygobject
version             3.50.0
revision            2

categories-append   gnome
license             LGPL-2.1+
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer

description         Python bindings for GObject, version 3
long_description    PyGObject is a Python dynamic module that enables developers to use the \
                    power of GObject, which is part of the GNOME platform.
homepage            https://pygobject.readthedocs.io/

use_xz              yes

checksums           rmd160  8a797437434ed98e0d957815ec77f85cffcb7ca9 \
                    sha256  8d836e75b5a881d457ee1622cae4a32bcdba28a0ba562193adb3bbb472472212 \
                    size    929848

# Note: 3.6 needed for a few old Gnome ports, remove once those have been migrated to 3.9+
python.versions     36 39 310 311 312 313

if {${name} ne ${subport}} {
    if {${python.version} < 38} {
        version     3.44.1
        revision    0

        checksums   rmd160  6c6eb71defdef6095371bcddc33faf4db4e856e9 \
                    sha256  3c6805d1321be90cc32e648215a562430e0d3d6edcda8f4c5e7a9daffcad5710 \
                    size    559432

        python.pep517 no
    }

    set branch              [join [lrange [split ${version} .] 0 1] .]
    master_sites            gnome:sources/${my_name}/${branch}/
    distname                ${my_name}-${version}

    depends_build-append \
                            path:bin/pkg-config:pkgconfig \
                            port:py${python.version}-setuptools

    depends_lib-append \
                            path:lib/pkgconfig/glib-2.0.pc:glib2 \
                            path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                            port:libffi \
                            port:py${python.version}-cairo

    compiler.c_standard     2011

    configure.args-append   --buildtype=plain

    # uses g-ir-scanner, which uses $CC from env
    if {${universal_possible} && [variant_isset universal]} {
        foreach arch ${configure.universal_archs} {
            lappend merger_build_env(${arch}) \
                            "CC=${configure.cc} -arch ${arch}"
            lappend merger_destroot_env(${arch}) \
                            "CC=${configure.cc} -arch ${arch}"
        }
    } else {
        build.env-append    "CC=${configure.cc} ${configure.cc_archflags}"
        destroot.env-append "CC=${configure.cc} ${configure.cc_archflags}"
    }

    if {${python.version} >= 38} {
        python.pep517       yes
        python.pep517_backend \
                            meson

        depends_build-append \
                            port:py${python.version}-packaging

        configure.args-append \
                            -Dpython=${python.bin} \
                            -Dtests=false

        # Hack: For now, manually install pkgconfig, as a wheel-based build disables that
        post-destroot {
            set pc_src_file "${worksrcpath}/pygobject-3.0.pc.in"
            set pc_dest_dir "${destroot}${python.prefix}/lib/pkgconfig"
            set pc_dest_file "${pc_dest_dir}/pygobject-3.0.pc"

            xinstall -d "${pc_dest_dir}"
            copy "${pc_src_file}" "${pc_dest_file}"
            reinplace "s|@prefix@|${python.prefix}|" ${pc_dest_file}
            reinplace "s|@exec_prefix@|${python.prefix}|" ${pc_dest_file}
            reinplace "s|@includedir@|${python.include}/pygobject|" ${pc_dest_file}
            reinplace "s|@datadir@|\${prefix}/share|" ${pc_dest_file}
            reinplace "s|@datarootdir@|\${prefix}/share|" ${pc_dest_file}
            reinplace "s|@VERSION@|${version}|" ${pc_dest_file}
        }
    }

    livecheck.type          none
} else {
    livecheck.type          gnome
    livecheck.name          ${my_name}
}
