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

github.setup        owl-compositor owl 91abf02613cd2ddb97be58b5b6703240320233a0
version             2026.08.07
revision            0
categories          wayland sysutils
license             GPL-3
maintainers         nomaintainer
description         Portable Wayland compositor in Objective-C
long_description    ${description}

checksums           rmd160  552ae809147fce88808a1ca4863433379169f9d0 \
                    sha256  dc553e10ee7c78d13e2ddcb7e1ade77e66b8eefa913361997f18d965ef64129a \
                    size    123999
github.tarball_from archive

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

patch.pre_args-replace  -p0 -p1

patchfiles-append   0000-configure-when-building-on-macOS-we-know-we-are-on-m.patch \
                    0001-Gate-GCD-and-IOSurface-usage-for-Mac-OS-X-10.5-and-F.patch \
                    0002-Add-a-wl_output-global-per-screen.patch \
                    0003-Upgrade-wl_seat-to-version-5-and-overhaul-input-hand.patch \
                    0004-Fill-in-the-remaining-shell-request-handlers.patch \
                    0005-Implement-zxdg_decoration_manager_v1-and-use-native-.patch \
                    0006-Bump-wl_data_device_manager-to-version-3.patch \
                    0007-Use-host-byte-order-for-shm-buffer-pixels.patch \
                    0008-Avoid-undefined-float-to-uint32-conversion-in-event-.patch \
                    0009-Do-not-clear-the-current-GL-context-for-surfaces-tha.patch \
                    0010-Implement-wp_content_type_manager_v1.patch \
                    0011-Implement-wp_single_pixel_buffer_v1.patch \
                    0012-Implement-cursor-shape-v1.patch \
                    0013-Implement-xdg-activation-v1.patch \
                    0014-Implement-xdg-toplevel-icon-v1.patch \
                    0015-Bump-xdg_wm_base-1-to-6.patch \
                    0016-Bump-wl_compositor-4-to-6-guarded-on-libwayland-supp.patch \
                    0017-Do-not-declare-ivars-of-incomplete-enum-type-in-OwlX.patch \
                    0018-Do-not-leak-the-NSImage-when-applying-a-toplevel-ico.patch \
                    0019-Raise-the-immutable-error-when-an-applied-toplevel-i.patch \
                    0020-Implement-wp_presentation.patch \
                    0021-Keep-Command-chords-away-from-clients-and-self-heal-.patch \
                    0022-Add-an-Edit-menu-with-Copy-and-Paste-items.patch \
                    0023-Fix-the-value-of-BTN_LEFT.patch \
                    0024-Keep-the-implicit-grab-alive-while-mouse-buttons-are.patch \
                    0025-Support-dragging-files-and-text-into-client-windows.patch \
                    0026-Create-data-devices-sources-and-offers-at-the-negoti.patch \
                    0027-Notice-external-pasteboard-changes-when-becoming-act.patch \
                    0028-Implement-wl_region-and-honor-surface-input-regions.patch \
                    0029-Unregister-buffers-when-their-resource-is-destroyed.patch \
                    0030-Reuse-the-IOSurface-texture-across-draws-and-fix-its.patch \
                    0031-Validate-the-surface-port-in-zowl_iosurface_v1.creat.patch \
                    0032-Add-owl-egl-a-client-side-EGL-over-CGL-library-for-h.patch \
                    0033-Implement-wp_viewporter.patch

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>
"
