# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           gitlab 1.0
PortGroup           meson  1.0

gitlab.instance     https://gitlab.gnome.org
gitlab.setup        GNOME libgit2-glib 1.2.1 v
revision            1

categories          gnome devel
license             LGPL-2+
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer
description         Glib wrapper library around the libgit2 git access library.
long_description    ${description}

checksums           rmd160  17f3cfb5df8544b5ed040724a3a3feaafa985048 \
                    sha256  8a61b5589788cfbba58a3f8018240de8cc1d2707bdc9b609e453faf890ade43c \
                    size    135614

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

# patch meson.build to correctly find our configured python and its installation path
patchfiles-append   patch-meson-find-mp-python3.diff

post-patch {
    reinplace -W ${worksrcpath} "s|@@PYTHON3_BIN@@|${configure.python}|" \
        meson.build

    reinplace -W ${worksrcpath} "s|^#!.*|#!${configure.python}|" \
        meson_python_compile.py \
        tools/coverage.py
}

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 \
                    path:lib/pkgconfig/libgit2.pc:libgit2 \
                    port:libssh2 \
                    path:bin/vala:vala

compiler.c_standard 2011

configure.args-append \
                    -Dgtk_doc=false \
                    -Dpython=false \
                    -Dtranslate_windows_paths=false

# Work around lack of @rpath on Tiger, i.e. this error:
# dyld: Library not loaded: @loader_path/libgit2-glib-1.0.0.dylib
platform darwin 8 {
    destroot.env-append \
                    "DYLD_LIBRARY_PATH=${build_dir}/${name}"
}

# 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}"
}

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

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

    configure.pkg_config_path-append \
                    ${frameworks_dir}/Python.framework/Versions/${py_ver}/lib/pkgconfig/

    configure.args-delete \
                    -Dpython=false

    depends_lib-append \
                    port:py${py_ver_nodot}-gobject3
}

variant python38 conflicts python39 python310 python311 description {Enable Python support using python38} {
    py_setup 3.8
}

variant python39 conflicts python38 python310 python311 description {Enable Python support using python39} {
    py_setup 3.9
}

variant python310 conflicts python38 python39 python311 description {Enable Python support using python310} {
    py_setup 3.10
}

variant python311 conflicts python38 python39 python310 description {Enable Python support using python311} {
    py_setup 3.11
}

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