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

github.setup        owl-compositor owl 91abf02613cd2ddb97be58b5b6703240320233a0
version             2026.07.31
revision            0
categories          x11 graphics wayland
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

# In-source builds are not supported.
post-extract {
    system -W ${worksrcpath} "mkdir ./build && cd ./build"
}

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

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]} {
    configure.cmd-prepend \
                    CFLAGS=-std=c11
} else {
    # Rosetta needs explicit archflags.
    configure.cmd-prepend \
                    CFLAGS='-std=c99 [get_canonical_archflags cc]' \
                    LDFLAGS=' [get_canonical_archflags ld]'
}

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
"
