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

name                gucharmap
version             18.0.0
revision            0

# Ensure this is updated based on what upstream requires
set unicode_ver     18.0.0

categories          gnome
license             {GPL-3+ GFDL}
maintainers         {devans @dbevans} {mascguy @mascguy} openmaintainer
description         gucharmap is a featureful unicode character map.
long_description    {*}${description}
homepage            https://wiki.gnome.org/Apps/Gucharmap

master_sites        https://gitlab.gnome.org/GNOME/${name}/-/archive/${version}:source \
                    https://www.unicode.org/Public/${unicode_ver}/ucd:ucd

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]
configure.python    ${prefix}/bin/python${py_ver}

use_bzip2           yes
set source_distfile ${distfiles}
set ucd_distfile    UCD.zip
set unihan_distfile Unihan.zip

distfiles           ${source_distfile}:source \
                    ${ucd_distfile}:ucd \
                    ${unihan_distfile}:ucd

dist_subdir         ${name}/${version}

checksums           ${source_distfile} \
                    rmd160  3302ca4e30de912d80a5018297ab0e1f0afcbdec \
                    sha256  564aca0ed8a25e4880ed5298de033889dfbc11bd49af1d7ee2959a5f46eb8f1d \
                    size    1525560 \
                    ${ucd_distfile} \
                    rmd160  10d4a59fe74c2feea356ae51384432c6dd5a95d8 \
                    sha256  7b3e555514060b92290d154f53655c5eb0fa62b16eb04c03434ff72d1a66a0d8 \
                    size    5657953 \
                    ${unihan_distfile} \
                    rmd160  c41be5c57499b9709a421855a9162793e51aa64e \
                    sha256  4c93ea9c1f636451729a840978f1667a53886af37ba854fdcce109721c63d43e \
                    size    8340649

depends_extract     port:unzip

extract.only        ${source_distfile}

post-extract {
    system -W ${workpath} "${prefix}/bin/unzip -q '${distpath}/${ucd_distfile}' -d ./UCD"
    copy ${distpath}/${unihan_distfile} ${workpath}/UCD
}

depends_build-append \
                    port:pkgconfig \
                    port:appstream-glib \
                    port:itstool \
                    port:gettext \
                    port:gtk-doc \
                    port:python${py_ver_nodot} \
                    path:bin/vala:vala

depends_lib-append \
                    port:desktop-file-utils \
                    port:freetype \
                    port:gettext-runtime \
                    path:lib/pkgconfig/gobject-introspection-1.0.pc:gobject-introspection \
                    path:lib/pkgconfig/gtk+-3.0.pc:gtk3 \
                    port:pcre2

license_noconflict  vala

depends_run-append \
                    port:adwaita-icon-theme

patchfiles-append   patch-no-Bsymbolic-functions.diff

post-patch {
    reinplace "s|^#!.*|#!${configure.python}|" \
        ${worksrcpath}/data/meson_desktopfile.py
}

# requires support for C11
compiler.c_standard 2011

# requires support for -fvisibility
compiler.blacklist-append \
                    {clang < 700}

configure.args-append \
                    -Ddocs=false \
                    -Ducd_path=${workpath}/UCD

# 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-activate   {
    system "${prefix}/bin/update-desktop-database ${prefix}/share/applications"
    system "${prefix}/bin/glib-compile-schemas ${prefix}/share/glib-2.0/schemas"
}

livecheck.type      regex
livecheck.url       https://gitlab.gnome.org/GNOME/${name}/-/tags
livecheck.regex     tags/(\\d+(?:\\.\\d+)*)
