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

name                gtksourceview4
set gname           gtksourceview
version             4.8.4
revision            0

categories          gnome
license             LGPL-2.1+
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer
description         GtkSourceView-4.0 is a source highlighting text widget for GTK+ 3
long_description    GtkSourceView is a text widget that extends the standard \
                    GTK+ 3.x text widget GtkTextView. It improves GtkTextView \
                    by implementing syntax highlighting and other features \
                    typical of a source editor. This port contains version 4 of the \
                    GtkSourceView widget. Port gtksourceview3 contains version 3 of \
                    widget, gtksourceview2 contains version 2 and port gtksourceview \
                    contains version 1.
homepage            https://wiki.gnome.org/Projects/GtkSourceView

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

# Disable unexpected download of subprojects
meson.wrap_mode     nodownload

checksums           rmd160  de76fede1a2707052c24427da65fd76eef6d0873 \
                    sha256  7ec9d18fb283d1f84a3a3eff3b7a72b09a10c9c006597b3fbabbb5958420a87d \
                    size    1159636

set port_ver_major  [lindex [split ${version} .] 0]

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

depends_lib-append \
                    port:fribidi \
                    port:gettext-runtime \
                    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 \
                    path:bin/vala:vala

compiler.c_standard 1999
# ld: unknown option: -force_load
compiler.blacklist-append \
                    *gcc-3.* *gcc-4.0 *gcc-4.2

configure.args-append \
                    -Dgtk_doc=true

# error: declaration of 'index' shadows a global declaration
configure.cflags-append \
                    -Wno-shadow

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

variant quartz conflicts x11 {}
variant x11 conflicts quartz {}

if {[variant_isset quartz]} {
    require_active_variants gtk3 quartz
} else {
    require_active_variants gtk3 x11
}

variant glade description {Install a glade catalog file} {
    configure.args-append \
                    -Dglade_catalog=true
    depends_lib-append \
                    port:glade
}

post-destroot {
    set docdir ${prefix}/share/doc/${name}

    xinstall -d ${destroot}${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS COPYING NEWS README.md \
        ${destroot}${docdir}

    # glade expects catalog modules and libraries to have a .so suffix
    if {[variant_isset glade]} {
        set libdir ${prefix}/lib
        ln -s ${libdir}/libgtksourceview-4.0.dylib ${destroot}${libdir}/libgtksourceview-4.0.so
    }
}

platform darwin 8 {
    # Tiger lacks @rpath, apply the usual gtk-doc workaround
    destroot.env-append \
                    "DYLD_LIBRARY_PATH=${build_dir}/${gname}"
}

livecheck.type      gnome
livecheck.name      ${gname}
livecheck.regex     "LATEST-IS-(${port_ver_major}\\.\\d*\[02468\](?:\\.\\d+)*)"
