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

name                gnome-terminal
version             3.38.3
revision            0
set branch          [join [lrange [split ${version} .] 0 1] .]
description         Terminal component for the GNOME 3 Desktop
long_description    {*}${description}
maintainers         {devans @dbevans} openmaintainer
categories          gnome
license             GPL-3+
homepage            https://wiki.gnome.org/Apps/Terminal
master_sites        gnome:sources/${name}/${branch}/

use_xz              yes

checksums           rmd160  7d3c01322e4e6b826e45d4689848cbe824d566e2 \
                    sha256  11a5b0d635f15fdce7508351a510fbf4e92aa533152a50ff0c7845e3102e4764 \
                    size    2574916

depends_build       port:appstream-glib \
                    port:autoconf \
                    port:automake \
                    port:gnome-common \
                    port:intltool \
                    port:itstool \
                    port:libtool \
                    port:libxml2 \
                    path:bin/pkg-config:pkgconfig \
                    port:yelp-tools

depends_lib         port:dbus \
                    port:dconf \
                    port:desktop-file-utils \
                    path:lib/pkgconfig/gnutls.pc:gnutls \
                    port:gsettings-desktop-schemas \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:pcre2 \
                    port:vte \
                    port:xorg-libX11

depends_run         port:adwaita-icon-theme

patchfiles          patch-src-server.c.diff \
                    patch-strchrnul.diff

post-patch {
    # build fails with ossp-uuid active
    # force use of system uuid even if ossp-uuid is installed
    reinplace "s|^#include <uuid.h>|#include <uuid/uuid.h>|" \
        ${worksrcpath}/src/terminal-prefs.c \
        ${worksrcpath}/src/terminal-profiles-list.c \
        ${worksrcpath}/src/terminal-screen.c \
        ${worksrcpath}/src/terminal-settings-list.c \
        ${worksrcpath}/src/terminal-window.c
}

# The driver driver trips over gterminal.c for some reason
# clang-77 (Xcode 3.2.6) hits an assertion failure: "UNREACHABLE executed!"
compiler.blacklist  *gcc-4* {clang < 100}

use_autoreconf      yes

configure.args      --with-gtk=3.0 \
                    --with-nautilus-extension=no \
                    --enable-debug \
                    --disable-migration \
                    --disable-search-provider \
                    --disable-silent-rules \
                    --disable-schemas-compile

# -iwithsysroot was added in https://github.com/macports/macports-ports/commit/358616e7589431f57e3d5b6231eed159d38ad8a8
# This flag is not supported by gcc and should be used conditionally.
if {[string match *clang* ${configure.compiler}]} {
    configure.cflags-append \
                    -iwithsysroot ${configure.sdkroot}/usr/include
} elseif {[string match *gcc* ${configure.compiler}]} {
    configure.cflags-prepend \
                    -I/usr/include
}

variant nautilus description {Build optional nautilus extension} {
    configure.args-replace  --with-nautilus-extension=no --with-nautilus-extension=yes
    depends_lib-append      port:nautilus
}

variant migration description {Enable prefs migration from GConf to GSettings} {
    configure.args-delete   --disable-migration
    depends_lib-append      port:gconf
}

platform darwin {
    patchfiles-append   patch-configure.ac.diff
    livecheck.type      gnome
}

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

livecheck.type      gnome
