# -*- 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.56.3
revision            0

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/

checksums           rmd160  adb7d87fb2e89d2dd176ed04cdd7045e92948d57 \
                    sha256  12760e4a0e3d04b6eb95e06f7a27e362c826d567ea613373a92c003b6c70d2d6 \
                    size    1411853

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

if {${name} ne ${subport}} {
    if {${python.version} == 36} {
        version     3.44.1
        revision    0
        use_xz      yes

        checksums   rmd160  6c6eb71defdef6095371bcddc33faf4db4e856e9 \
                    sha256  3c6805d1321be90cc32e648215a562430e0d3d6edcda8f4c5e7a9daffcad5710 \
                    size    559432

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

    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

    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} > 36} {
        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}
}
