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

name                glade
version             3.40.0
revision            4

categories          devel gnome
license             LGPL-2+ GPL-2+
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer

description         Glade is a RAD tool to enable quick & easy development of user interfaces \
                    for the GTK+ 3.* toolkit and the GNOME desktop environment.
long_description    {*}${description}
homepage            https://wiki.gnome.org/Apps/Glade

set branch          [join [lrange [split ${version} .] 0 1] .]
master_sites        gnome:sources/${name}/${branch}/
use_xz              yes

checksums           rmd160  4063ca4a153d3ec620b5aa944e8c07cd4ab76cc2 \
                    sha256  31c9adaea849972ab9517b564e19ac19977ca97758b109edc3167008f53e3d9c \
                    size    2654772

depends_skip_archcheck devhelp

depends_build-append \
                    port:docbook-xml \
                    port:docbook-xsl-nons \
                    port:gettext \
                    port:itstool \
                    port:libxslt \
                    port:pkgconfig

depends_lib-append \
                    path:lib/pkgconfig/gdk-pixbuf-2.0.pc:gdk-pixbuf2 \
                    path:lib/pkgconfig/glib-2.0.pc:glib2 \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:libxml2

depends_run-append \
                    port:desktop-file-utils

# error: redefinition of typedef ‘GladeWidgetAdaptor’
compiler.blacklist-append \
                    *gcc-4.0 *gcc-4.2

configure.args-append \
                    -Dgladeui=true \
                    -Dgjs=disabled \
                    -Dpython=disabled \
                    -Dwebkit2gtk=disabled

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

app.icon            ${worksrcpath}/data/icons/hicolor/scalable/apps/org.gnome.Glade.svg
app.retina          yes

proc py_setup {python_branch} {
    global prefix frameworks_dir
    set python_version          [string map {"." ""} ${python_branch}]
    set python_framework        ${frameworks_dir}/Python.framework/Versions/${python_branch}

    configure.args-replace      -Dpython=disabled -Dpython=enabled
    configure.python            ${prefix}/bin/python${python_branch}
    configure.env-append        "PYTHON_LIBS=-L${python_framework}/lib -lpython${python_branch}" \
                                PYTHON_LIB_LOC=${python_framework}/lib
    depends_lib-append          port:py${python_version}-gobject3
    configure.pkg_config_path   ${python_framework}/lib/pkgconfig
}

variant python310 conflicts python311 description {Build Python 3.10 widgets support} {
    py_setup 3.10
}

variant python311 conflicts python310 description {Build Python 3.11 widgets support} {
    py_setup 3.11
}

if {![variant_isset python310] && \
    ![variant_isset python311]} {
    default_variants +python311
}

variant gjs description {Enable GJS support} {
    configure.args-replace  -Dgjs=disabled -Dgjs=enabled
    depends_lib-append      path:lib/pkgconfig/gjs-1.0.pc:gjs
}

variant webkit2gtk description {Enable WebKit widgets catalog} {
    configure.args-replace  -Dwebkit2gtk=disabled -Dwebkit2gtk=enabled
    depends_lib-append      path:lib/pkgconfig/webkit2gtk-4.1.pc:webkit2-gtk
    depends_run-append      port:devhelp
    patchfiles-append       patch-meson-webkit2gtk-4.1.diff
}

# See: https://github.com/macports/macports-ports/pull/23137
if {(${os.platform} eq "darwin" && ${os.major} > 19) ||
    ${os.platform} ne "darwin"} {
    default_variants +gjs +webkit2gtk
}

notes "
To view the Glade Interface Designer Manual (GTK+ 3 version), use

% yelp help:glade
"

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

variant x11 conflicts quartz {
    require_active_variants gtk3 x11 quartz
}

variant quartz conflicts x11 {
    require_active_variants gtk3 quartz x11
    depends_lib-append port:gtk-osx-application-gtk3
# disable dependency on devhelp at runtime
# until +quartz problem solved for webkit2-gtk (#52688)
    depends_run-delete port:devhelp
}

if {![variant_isset quartz]} {
    default_variants +x11
}
if {![variant_isset x11]} {
    default_variants +quartz
}
if {![variant_isset quartz] && ![variant_isset x11]} {
    error "Either +x11 or +quartz is required"
}

livecheck.type      gnome
