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

categories          devel graphics wayland
license             MIT
maintainers         {@barracuda156 macos-powerpc.org:barracuda} openmaintainer

depends_build-append \
                    path:bin/pkg-config:pkgconfig

if {${subport} eq "${name}" || ${subport} eq "${name}-scanner"} {
    PortGroup       github 1.0
    PortGroup       legacysupport 1.1

    # Forked from https://gitlab.freedesktop.org/wayland/wayland
    github.setup    barracuda156 wayland-mac eb50623fa89082cdf2927546274fafaa08baea9a
    set upstream_v  1.26.0
    version         ${upstream_v}.1
    checksums       rmd160  331c32b1e4395bd41e1ee77d987aa0f530570de0 \
                    sha256  8392d59672e625e4bc84fbcaa07f540c59f58e93a0766bc77996292590ca77ef \
                    size    770241
    github.tarball_from archive

    configure.args-append \
                    -Ddocbook_validation=false \
                    -Ddocumentation=false \
                    -Ddtd_validation=true

    github.livecheck.branch ${upstream_v}-mac
}

if {${subport} eq "${name}"} {
    # CLOCK_MONOTONIC
    legacysupport.newest_darwin_requires_legacy 15

    revision        0
    epoch           1
    description     Core Wayland protocol and libraries
    long_description \
                    Wayland is intended as a simpler replacement for X \
                    easier to develop and maintain. GTk, Qt, GNOME and KDE \
                    have backends for it.

    depends_build-append \
                    path:bin/cmake:cmake

    depends_lib-append \
                    port:epoll-shim \
                    port:expat \
                    port:libffi \
                    port:libxml2 \
                    port:wayland-scanner

    # stdatomic.h
    compiler.c_standard 2011

    # because Apple Clang 6 on OS X 10.9 appears to lack stdatomic.h
    compiler.blacklist-append {clang < 602}

    configure.args-append \
                    -Dlibraries=true \
                    -Dscanner=false \
                    -Dtests=true

    if [string match *clang* ${configure.compiler}] {
        configure.args-append \
                    -Dc_std=c11
    }

    variant docs description "Install docs" {
        configure.args-replace \
                    -Ddocumentation=false \
                    -Ddocumentation=true
    }

    test.run        yes
}

subport wayland-scanner {
    # strndup
    legacysupport.newest_darwin_requires_legacy 10

    revision        0
    description     C code generator for Wayland protocol XML files
    long_description \
                    {*}${description}
    installs_libs   no

    depends_build-append \
                    port:expat \
                    port:libxml2

    compiler.c_standard 1999

    configure.args-append \
                    -Dlibraries=false \
                    -Dscanner=true \
                    -Dtests=false
}

subport wayland-protocols {
    PortGroup       gitlab 1.0

    gitlab.instance https://gitlab.freedesktop.org
    gitlab.setup    wayland wayland-protocols 1.50
    revision        0
    platforms       any
    description     Wayland protocols
    long_description \
                    {*}${description}
    checksums       rmd160  e21a56b22e86cab3e76da002166f914266f77098 \
                    sha256  dc5899a21274fd03d06472a753d1954ab30ecc6af372105d72d472ba17a65705 \
                    size    175008
    supported_archs noarch

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

    post-patch {
        reinplace "s|/usr/bin/env python3|${configure.python}|" ${worksrcpath}/tests/replace.py
    }

    depends_build-append \
                    port:python${py_ver_nodot} \
                    port:wayland
    depends_run-append \
                    port:wayland

    configure.args-append \
                    -Dtests=false

    livecheck.url   https://wayland.freedesktop.org/releases.html
    livecheck.regex "${subport}-(\\d+(?:\\.\\d+)*)"
}
