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

name                eog
version             3.38.3
revision            0
license             GPL-2+
set branch          [join [lrange [split ${version} .] 0 1] .]
description         An image viewing and cataloging program.
long_description    This is the Eye of Gnome, an image viewer program. \
                    It is meant to be a fast and functional image viewer \
                    as well as an image cataloging program.
maintainers         {devans @dbevans} openmaintainer
categories          gnome
homepage            https://wiki.gnome.org/Apps/EyeOfGnome
master_sites        gnome:sources/${name}/${branch}/

use_xz              yes

checksums           rmd160  12854b6656c27f5cef38c44209fc3290c01a592f \
                    sha256  b35294e66170b788a686ca8807b0bbb6ddcaf5db87c60018fe524b5328958c79 \
                    size    3614520

depends_build-append \
                    port:pkgconfig \
                    port:gettext \
                    port:gtk-doc \
                    port:itstool \
                    port:python310

depends_lib         port:desktop-file-utils \
                    port:exempi \
                    port:gettext-runtime \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    port:gnome-desktop \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    port:gsettings-desktop-schemas \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    path:include/turbojpeg.h:libjpeg-turbo \
                    port:lcms2 \
                    port:libexif \
                    port:libpeas1 \
                    path:lib/pkgconfig/librsvg-2.0.pc:librsvg \
                    port:libxml2 \
                    port:shared-mime-info

depends_run         port:adwaita-icon-theme

patchfiles          meson.build.patch

post-patch {
    reinplace "s|#!.*|#!${prefix}/bin/python3.10|" ${worksrcpath}/meson_post_install.py
}

configure.args      -Dlibportal=false \
                    -Dgtk_doc=true

# disable librsvg on platforms that don't yet support rust
# use the criteria that librsvg itself uses to make this determination
set max_darwin_for_rust 13
if {${os.platform} eq "darwin" && (
    ${os.major} < ${max_darwin_for_rust}
    || ${os.arch} eq "arm"
    || ${universal_possible} && [variant_isset universal] && "arm64" in ${configure.universal_archs}
    || ${build_arch} eq "i386"
    || ${universal_possible} && [variant_isset universal] && "i386" in ${configure.universal_archs}
)} {
    depends_lib-delete \
                    path:lib/pkgconfig/librsvg-2.0.pc:librsvg

    configure.args-append \
                    -Dlibrsvg=false
}

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

post-destroot {
    # libpeas expects plugin modules with .so extensions
    # make .so symlink for each plugin module built as .dylib
    set plugindir lib/eog/plugins
    foreach pluginlib {libfullscreen libreload libstatusbar-date} {
        ln -s ${prefix}/${plugindir}/${pluginlib}.dylib ${destroot}${prefix}/${plugindir}/${pluginlib}.so
    }

    # add symlink to lib/eog/libeog.dylib in standard libdir
    # works around introspection typelib issue
    ln -s ${prefix}/lib/eog/libeog.dylib  ${destroot}${prefix}/lib/libeog.dylib
}

notes               "For extra functionality install eog-plugins"

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

livecheck.type      gnome
