# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Aaron Blasko <blaskoazzolaaaron [at] gmail.com>
#
# Arch's aquamarine 0.15.1-1 plus one patch, carried on edge for Apple Silicon:
# re-read a connector's possible CRTCs when rescanning, so a Type-C port the
# DCP fabric reroutes to another display pipeline gets a CRTC without
# restarting the compositor. Drop the carry once hyprwm releases the fix.

pkgname=aquamarine
pkgver=0.15.1
pkgrel=1.1
pkgdesc='a very light linux rendering backend library'
arch=(aarch64)
url="https://github.com/hyprwm/$pkgname"
license=(BSD-3-Clause)
depends=(libgcc
         libstdc++
         glibc # libc.so libm.so
         hyprutils libhyprutils.so
         libdisplay-info libdisplay-info.so
         libdrm # libdrm.so
         libglvnd libEGL.so
         libinput # libinput.so
         mesa # libgbm.so
         opengl-driver
         pixman
         seatd libseat.so
         systemd-libs libudev.so
         wayland libwayland-client.so
         wayland-protocols)
makedepends=(cmake
             hyprwayland-scanner)
provides=("lib$pkgname.so")
_archive="$pkgname-$pkgver"
source=("$url/archive/v$pkgver/$_archive.tar.gz"
        0001-drm-re-read-possible-CRTCs-when-rescanning-connectors.patch)
sha256sums=('2f9de98c0bd1b7b1b09c576e390a2fef436449762fb334163c414f0c300296f2'
            '50e9e38ff915b18074dc9b5dd1d07d7f24e340e99f254476d6abe578eece7864')

prepare() {
	cd "$_archive"
	patch -Np1 -i ../0001-drm-re-read-possible-CRTCs-when-rescanning-connectors.patch
}

build() {
	cd "$_archive"
	# cc1plus needs more than 8 MiB of stack for DRM.cpp. GCC raises its own
	# limit natively, but under QEMU user-mode emulation (the aarch64 builder)
	# the guest stack is fixed at exec and setrlimit is ignored, so the compiler
	# segfaults. QEMU reads this at exec; native builds ignore it. The object
	# code is identical either way.
	export QEMU_STACK_SIZE=64M
	cmake -B build \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_BUILD_TYPE=Release
	cmake --build build
}

package() {
	cd "$_archive"
	DESTDIR="$pkgdir" cmake --install build
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}
