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

# Original upstream is stale for years: https://github.com/owl-compositor/owl
github.setup        barracuda156 owl ad50ab99b8feaeccb75dcc75aa9b9d4d36dd459d
version             2026.08.22
revision            0
categories          wayland sysutils
license             GPL-3
maintainers         nomaintainer
description         Portable Wayland compositor in Objective-C
long_description    ${description}

checksums           rmd160  ebe507c31ef6485455e40a5246de93c125b9b46d \
                    sha256  173b7c4cb6e6255859c24e1bde9092fc06cfd308ca0c38612adaade2b175e16f \
                    size    253975
github.tarball_from archive
github.livecheck.branch tmp

depends_lib-append  port:wayland
depends_run-append  port:libxkbcommon

patch.pre_args-replace  -p0 -p1

configure.cmd       ${worksrcpath}/configure

# Should not use CommandLineTools:
use_xcode           yes

# OwlKnownClientsManager.m: error: ‘for’ loop initial declaration used outside C99 mode
# OwlKnownClientsManager.m: error: 'for' loop initial declarations are only allowed in C99 or C11
# Keep general (non-powerpc) case above for simplicity.
if {${configure.build_arch} ni [list ppc ppc64]} {
    compiler.c_standard 2011
    configure.cmd-prepend \
                    CFLAGS=-std=c11
} else {
    compiler.c_standard 1999
    # Rosetta needs explicit archflags.
    configure.cmd-prepend \
                    CFLAGS='-std=c99 [get_canonical_archflags cc]' \
                    LDFLAGS=' [get_canonical_archflags ld]'
}

# owl-egl (client-side hardware EGL over CGL + IOSurface, see
# HWGL.md) is 10.6+ only: its Makefile builds with
# -mmacosx-version-min=10.6, and 10.5 clients keep Mesa swrast.
if {${os.major} >= 10} {
    # EGL headers come from our mesa (which carries the Apple
    # eglplatform pointer-ABI patch owl-egl's ABI relies on);
    # wayland-scanner and wayland-egl-backend.pc come from wayland
    # (already in depends_lib); mig comes with Xcode (use_xcode).
    depends_build-append \
                    path:bin/pkg-config:pkgconfig \
                    path:lib/pkgconfig/egl.pc:mesa

    require_active_variants mesa wayland

    post-build {
        system -W ${worksrcpath}/owl-egl \
            "${build.cmd} PREFIX=${prefix} CC=\"${configure.cc} [get_canonical_archflags cc]\""
    }

    post-destroot {
        system -W ${worksrcpath}/owl-egl \
            "${build.cmd} install PREFIX=${prefix} DESTDIR=${destroot}"
    }
}

destroot {
    move ${worksrcpath}/Owl.app ${destroot}${applications_dir}
}

notes "
Example how to run owl:

mkdir -p -m 700 /tmp/owl-runtime
export XDG_RUNTIME_DIR=/tmp/owl-runtime && open ${applications_dir}/Owl.app

To run GL clients on the GPU via owl-egl:
DYLD_LIBRARY_PATH=${prefix}/lib/owl-egl mpv --vo=gpu --gpu-context=wayland <file>
"
