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

gitlab.instance     https://gitlab.gnome.org
# After the following commit libadwaita 1.6.x is required,
# which in turn needs a newer gtk4 than MacPorts now has.
# https://gitlab.gnome.org/World/secrets/-/commit/c52d6f9e5c483e1ec141f4a113425890fa8b4b29
gitlab.setup        World secrets 9.4
revision            0
categories          gnome security sysutils
license             GPL-3
maintainers         nomaintainer
description         Password manager for GNOME
long_description    {*}${description}
use_bzip2           yes
checksums           rmd160  8f50951382df5d151553ab85a5ba4a212be10403 \
                    sha256  5e0850fffc3a9d4ab20670b6c200e7f15f50ce31b73b5622de00939c1d0d69ce \
                    size    465812

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

depends_build-append \
                    port:gettext \
                    path:bin/pkg-config: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 \
                    path:lib/pkgconfig/gtk+-4.0.pc:gtk4 \
                    port:libadwaita \
                    port:python${py_ver_nodot} \
                    port:py${py_ver_nodot}-kcs11 \
                    port:py${py_ver_nodot}-pykeepass \
                    port:py${py_ver_nodot}-pyotp \
                    port:py${py_ver_nodot}-validators \
                    port:py${py_ver_nodot}-yubico \
                    port:py${py_ver_nodot}-zxcvbn

# Dependency is not declared anywhere explicitly,
# but secrets will fail to launch if usb module is not found.
depends_run-append  port:py${py_ver_nodot}-pyusb

patchfiles-append   patch-find-right-python.diff

set python.prefix   ${frameworks_dir}/Python.framework/Versions/${py_ver}
set python.bin      ${python.prefix}/bin/python${py_ver}
set python.pkgd     ${python.prefix}/lib/python${py_ver}/site-packages

post-patch {
    reinplace "s|@PYTHON@|${python.bin}|" ${worksrcpath}/meson.build
    reinplace "s|@PY_PACKAGES@|${python.pkgd}|" ${worksrcpath}/meson.build
}

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

# https://trac.macports.org/ticket/70137
notes "
If you get an error upon launching the app,\
try setting GSK_RENDERER=cairo in the environment.\
You may also add it into a shell config file.
"
