# -*- 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           active_variants 1.1
PortGroup           legacysupport 1.1
PortGroup           meson 1.0

name                gobject-introspection
conflicts           gobject-introspection-devel
set my_name         gobject-introspection

version             1.78.1
revision            5
epoch               1

categories          gnome
# library under LGPL-2+, tools under GPL-2+
license             {LGPL GPL-2+}
maintainers         {mascguy @mascguy} openmaintainer

description         GObject Introspection
long_description    Gobject Introspection acts as a bridge between low-level C+GObject code and \
                    a managed runtime (JavaScript, Python, Java, Lua, .NET, Scheme, etc.).
homepage            https://wiki.gnome.org/Projects/GObjectIntrospection

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

checksums           rmd160  3fda7e7ac0eb288335a4db69551fdf356fcc03b1 \
                    sha256  bd7babd99af7258e76819e45ba4a6bc399608fe762d83fde3cac033c50841bb4 \
                    size    1060296

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

# https://trac.macports.org/ticket/71191
legacysupport.newest_darwin_requires_legacy 0
legacysupport.redirect_bins g-ir-compiler g-ir-generate g-ir-inspect g-ir-scanner

set py_ver          3.13
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build-append \
                    port:bison \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot} \
                    port:py${py_ver_nodot}-cython

depends_lib-append \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:libffi \
                    port:py${py_ver_nodot}-mako \
                    port:py${py_ver_nodot}-markdown \
                    port:py${py_ver_nodot}-setuptools

patchfiles-append   patch-fix-rpath-gir-typelib.diff
patchfiles-append   patch-fix-scanner-in-build-execution.diff
patchfiles-append   patch-fix-tools-python.diff
patchfiles-append   msvccompiler.patch

post-patch {
    reinplace "s|libcairo-gobject\\.2\\.dylib|${prefix}/lib/libcairo-gobject.2.dylib|g" ${worksrcpath}/gir/meson.build
    reinplace "s|@MP_LIB@|${prefix}/lib/|g" ${worksrcpath}/giscanner/shlibs.py
    reinplace "s|@MP_PYTHON_CMD@|${configure.python}|g" ${worksrcpath}/tools/meson.build
    reinplace "s|#!/usr/bin/env python3|#!${configure.python}|g" \
        ${worksrcpath}/misc/update-glib-annotations.py \
        misc/update-gtkdoc-tests.py \
        misc/update-vulkan-gir.py \
        tests/gi-tester
}

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

configure.args-append \
                    -Ddoctool=enabled \
                    -Dpython=${configure.python}

# By default, gir will attempt to link programs using
# the same compiler used to build Python itself. However,
# the system clang on 10.6 does not appear to respect
# LIBRARY_PATH, resulting in g-ir-scanner errors such as:
#
# ld: library not found for -lgio-2.0
#
# The following workaround selects a more up-to-date linker
# when building this project. Identical logic already exists
# in the gobject_introspection PortGroup, so dependent projects
# should not require modification.
#
# 10.6.8 Rosetta requires a specific solution: https://github.com/mesonbuild/meson/issues/10351

platform darwin {
    if {${os.major} == 10 && ${build_arch} eq "ppc"} {
        build.env-append    CC=${developer_dir}/usr/bin/powerpc-apple-darwin10-gcc-4.2.1
    } else {
        build.env-append    CC=${configure.cc}
    }
}

platform darwin 8 {
    # Tiger does not support RPATHs at this time
    patchfiles-append patch-girscanner-tiger-no-rpath.diff

    build.env-append DYLD_LIBRARY_PATH=${workpath}/build/girepository
    destroot.env-append DYLD_LIBRARY_PATH=${workpath}/build/girepository
}

#--------------------------------------------------------------------------------------------------
# Note that several tests fail, due to @rpath issues with temporary test-only libs.
# Needs to be reported to upstream.
#
#  7/65 test_shlibs.py                          FAIL            2.67s   exit status 1
#    sanitize_shlib_path('@rpath/libbarapp-1.0.dylib'),
#    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#    TypeError: sanitize_shlib_path() missing 1 required positional argument: 'libdir'
#
#
# 53/65 gitypelibtest                           FAIL            0.33s   killed by signal 5 SIGTRAP
#   Failed to load shared library '/opt/local/lib/libregress-1.0.dylib' referenced by the
#   typelib: dlopen(/opt/local/lib/libregress-1.0.dylib, 9): image not found
#--------------------------------------------------------------------------------------------------
test.run            yes

livecheck.type      gnome
livecheck.name      ${my_name}
