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

gitlab.instance     https://gitlab.gnome.org
gitlab.setup        GNOME gitg 44 v
revision            1

categories          gnome devel
license             GPL-2+
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer
description         GNOME git repository viewer.
long_description    gitg is a fast git repository browser. It currently features: \
                    \n * Loading large repositories very fast \
                    \n * Show/browse repository history \
                    \n * Show highlighted revision diff \
                    \n * Browse file tree of a revision and export by drag and drop \
                    \n * Search in the revision history on subject, author or hash \
                    \n * Switch between history view of branches easily \
                    \n * Commit view providing per hunk stage/unstage and commit

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

checksums           rmd160  159c1af06c3ece95b55e63bdd44b36a6bbab8608 \
                    sha256  f2cca5599ee261bbaf954fcc8c5be94f9ad1111b24849e5c82ec0dfb8b48d8ae \
                    size    10805758

# Don't allow build to promote warnings to errors. Full details in patchfile.
patchfiles-append   patch-meson-build-debug.diff

# build GitgExt python extension for our configured python
# use meson python module rather than deprecated python3 module
patchfiles-append   patch-libgitg-ext-meson-build.diff

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

    reinplace -W ${worksrcpath} "s|^#!.*|#!${configure.python}|" \
                    meson_post_install.py
}

depends_build-append \
                    port:gettext \
                    port:pkgconfig

depends_lib-append \
                    port:desktop-file-utils \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    port:gpgme \
                    port:gsettings-desktop-schemas \
                    port:gspell \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:gtksourceview4 \
                    port:json-glib \
                    port:libdazzle \
                    port:libgee \
                    port:libgit2-glib \
                    port:libhandy \
                    port:libpeas1 \
                    port:libsecret \
                    path:lib/pkgconfig/libsoup-2.4.pc:libsoup \
                    port:libxml2 \
                    path:bin/vala:vala

depends_run-append \
                    port:adwaita-icon-theme

# requires C11
compiler.c_standard 2011

configure.args-append \
                    -Ddocs=false \
                    -Dpython=false

app.icon            ${worksrcpath}/osx/data/Gitg.iconset/icon_512x512@2x.png
app.retina          yes

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

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

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

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

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

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

variant quartz {}

if {[variant_isset quartz]} {
    require_active_variants gtk3 quartz
} else {
    require_active_variants gtk3 x11
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    system "${prefix}/bin/gtk-update-icon-cache -f -t ${prefix}/share/icons/hicolor"
    system "${prefix}/bin/glib-compile-schemas ${prefix}/share/glib-2.0/schemas"
}
