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

github.setup        jcupitt vipsdisp 4.1.4 v
revision            0
categories          graphics
license             MIT
maintainers         nomaintainer

description         Tiny libvips/gtk4 image viewer
long_description    {*}${description}

checksums           rmd160  ae4c94b605b0b2da5aba252146c2479eaa67ccc8 \
                    sha256  8937a1e4b44adf7a742ae5ea771bc797003d20500d23e8d83d522333f745c8cf \
                    size    1487836
github.tarball_from archive

installs_libs       no

# vipsdisp(31160) malloc: *** error for object 0xa04da754: pointer being freed was not allocated
legacysupport.newest_darwin_requires_legacy 0
legacysupport.redirect_bins ${name}

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

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

depends_lib-append  path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gtk4.pc:gtk4 \
                    port:vips

depends_run-append  port:desktop-file-utils

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

post-patch {
    reinplace "s|/usr/bin/env python3|${configure.python}|" \
        ${worksrcpath}/meson_post_install.py
}

# cc1: error: unrecognized command line option "-std=gnu11"
compiler.c_standard 2011

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.
"
