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

# When building universal the meson test for unistd.h fails because
# clang: error: cannot use 'cpp-output' output with multiple -arch options
# leading to build failure later when unistd.h doesn't get included if
# implicit function declarations are not allowed (Xcode 12+).
PortGroup           muniversal 1.0

github.setup        xkbcommon libxkbcommon 1.7.0 xkbcommon-
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
checksums           rmd160  08ef850e66c8ec448725fb7c4f286ee30ba691cf \
                    sha256  65782f0a10a4b455af9c6baab7040e2f537520caa2ec2092805cdfd36863b247 \
                    size    534312

categories          devel
maintainers         {ryandesign @ryandesign} openmaintainer
license             MIT

description         library to handle keyboard descriptions

long_description    ${name} is a {*}${description}, including loading them from \
                    disk, parsing them and handling their state. It's mainly \
                    meant for client toolkits, window systems, and other \
                    system applications. It is also used by some XCB \
                    applications for proper keyboard support.

homepage            https://xkbcommon.org
master_sites        ${homepage}/download/
use_xz              yes

depends_build-append \
                    port:bison \
                    path:bin/pkg-config:pkgconfig \
                    port:xorg-util-macros

compiler.c_standard 2011

configure.args      -Ddefault_library=both \
                    -Denable-docs=false \
                    -Denable-wayland=false \
                    -Denable-x11=false

if {${subport} eq ${name}} {
    revision        1

    depends_lib-append \
                    port:libxml2 \
                    port:xkeyboard-config
}

subport ${name}-x11 {
    revision        0

    PortGroup       legacysupport 1.0

    # strnlen
    legacysupport.newest_darwin_requires_legacy 10

    depends_lib-append \
                    port:${name} \
                    port:xorg-libxcb

    configure.args-replace \
                    -Denable-x11=false -Denable-x11=true

    post-destroot {
        # Upstream wants packagers to package libxkbcommon-x11 separately
        # from libxkbcommon (see PACKAGING) yet refuses to provide a way
        # to do so, so we have to delete everything libxkbcommon already
        # provides manually.
        # https://github.com/xkbcommon/libxkbcommon/issues/75
        fs-traverse item ${destroot} {
            if {![file isdirectory ${item}] && ![string match *x11* [file tail ${item}]]} {
                delete ${item}
            }
        }
    }
}

if {${subport} ne ${name}} {
    livecheck.type  none
}
