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

# strndup
legacysupport.newest_darwin_requires_legacy 10

github.setup        BestImageViewer geeqie 2.7 v
revision            0
categories          graphics x11
maintainers         nomaintainer
license             GPL-2+
# only used at build
license_noconflict  graphviz openssl11

description         Image viewer and organiser
long_description    Geeqie is a lightweight Gtk+-based image viewer and browser. \
                    Provides slideshow function and supports MANY image formats.

homepage            https://www.geeqie.org
use_xz              yes
checksums           rmd160  b4adee02d9d80ca87d86fe03cde15ba6bc5486a5 \
                    sha256  9b5f342d3cc47782716711e56c3c7a045b4bbeaa653e192d49ce2d5e87ac8106 \
                    size    1906552
github.tarball_from releases

# Do not override linker flags with Linux-specific one, it breaks legacysupport linking.
patchfiles          patch-meson.build.diff

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:djvulibre \
                    port:exiv2 \
                    port:ffmpegthumbnailer \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:gspell \
                    port:lcms \
                    port:libarchive \
                    port:libheif \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:libjxl \
                    port:libraw \
                    port:openexr \
                    port:openjpeg \
                    path:lib/pkgconfig/poppler.pc:poppler \
                    port:tiff \
                    port:webp

depends_run         port:adwaita-icon-theme \
                    port:desktop-file-utils

# dependencies needed by plugins (not checked by configure) -
depends_run-append  port:ImageMagick \
                    port:exiftool \
                    port:exiftran \
                    port:gphoto2 \
                    port:zenity

# geeqie(23119,0x26fc408) malloc: *** error for object 0x246f700: Non-aligned pointer being freed (2)
legacysupport.redirect_bins geeqie

compiler.cxx_standard   2017

configure.args      -Ddoxygen=disabled \
                    -Dgtk4=disabled \
                    -Dlua=disabled \
                    -Dpandoc=disabled \
                    -Dyelp-build=disabled

variant print_preview description "Print preview support with evince" {
# appears non-functional but adds many dependencies
     depends_run-append     port:evince
     configure.args-replace -Devince=disabled -Devince=enabled
}

variant docs description "Build documentation" {
     depends_build-append   path:bin/doxygen:doxygen
     configure.args-replace -Ddoxygen=disabled -Ddoxygen=enabled
}

variant quartz conflicts x11 {
    require_active_variants path:lib/pkgconfig/gtk+-3.0.pc:gtk3 quartz x11

    # meson.build looks for clutter-gtk and libchamplain unless gps-map is disabled
    # if clutter-gtk and libchamplain are found, the quartz version of the port builds
    # against them but crashes on launch with "unsupported backend"
    configure.args-append   -Dgps-map=disabled
}

variant x11 conflicts quartz {
    require_active_variants path:lib/pkgconfig/gtk+-3.0.pc:gtk3 x11 quartz
    depends_lib-append      port:clutter-gtk \
                            port:libchamplain

    notes "
        GTK-based app should be launched from the terminal.
    "
}

variant gtk3 conflicts gtk4 description "Build with GTK3" { }

# FIXME: broken at the moment, the build picks wrong headers.
variant gtk4 conflicts gtk3 description "Build with GTK4" {
    depends_lib-replace     path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                            path:lib/pkgconfig/gtk4.pc:gtk4
    configure.args-replace  -Dgtk4=disabled -Dgtk4=enabled
    # Avoid gtk3-relying ports:
    configure.args-append   -Dgps-map=disabled
}

if {![variant_isset quartz]} {
    default_variants-append +x11
}

if {![variant_isset gtk4]} {
    default_variants-append +gtk3
}

post-activate {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
}
