# Contributor: Zach DeCook <zachdecook@librem.one>
maintainer="Zach DeCook <zachdecook@librem.one>"
pkgname=hyprland
pkgver=0.49.0
pkgrel=0
_commit="9958d297641b5c84dcff93f9039d80a5ad37ab00"
pkgdesc="Independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks."
url="https://hyprland.org"
arch="all"
license="BSD-3-Clause"
source="
	https://github.com/hyprwm/Hyprland/archive/v$pkgver/Hyprland-v$pkgver.tar.gz
	include-cstring.patch
	"
builddir="$srcdir/Hyprland-$pkgver"
makedepends="
	aquamarine-dev>=0.8.0
	cairo-dev
	cmake
	elogind-dev
	hyprcursor-dev>=0.1.9
	hyprgraphics-dev>=0.1.1
	hyprland-protocols>=0.6.0
	hyprlang-dev>=0.3.2
	hyprutils-dev>=0.7.0
	hyprwayland-scanner>=0.3.10
	jq
	libdrm-dev
	libinput-dev
	libliftoff-dev
	libxcb-dev
	libxcursor-dev
	libxkbcommon-dev
	mesa-dev
	meson
	ninja
	pango-dev
	pixman-dev
	re2-dev
	tomlplusplus-dev
	udis86-git-dev
	vulkan-loader-dev
	wayland-dev
	wayland-protocols
	xcb-util-errors-dev
	xcb-util-image-dev
	xcb-util-renderutil-dev
	xcb-util-wm-dev
	xkeyboard-config-dev
	xwayland-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-dev
	$pkgname-wallpapers::noarch
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"

# glaze required for hyprpm only supports little-endian
case "$CARCH" in
	s390x) _disable_pm="-Dhyprpm=disabled" ;;
	*) subpackages="$subpackages $pkgname-plugin-manager:plugin_manager"
	   makedepends="$makedepends glaze"
	   ;;
esac

prepare() {
	default_prepare
	# Set some variables in version.h.in
	sed -i "s/@HASH@/$_commit/" "$builddir"/src/version.h.in
	sed -i "s/@BRANCH@/build-alpine/" "$builddir"/src/version.h.in
	_patches="$(printf %s "$source" | grep '.patch$' | tr '\n' ' ')"
	if test "$_patches"; then
		_message="with patches: $_patches"
	else
		_message="without patches"
	fi
	sed -i "s~@MESSAGE@~$_message~" "$builddir"/src/version.h.in
	sed -i "s/@TAG@/v$pkgver/" "$builddir"/src/version.h.in
}

build() {
	abuild-meson $_disable_pm . output
	meson compile -C output
}

check() {
	meson test -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

wallpapers() {
	pkgdesc="Wallpapers for Hyprland"

	amove usr/share/hypr/wall*.png
}

plugin_manager() {
	pkgdesc="Plugin-manager for Hyprland"
	depends="
		$makedepends
		git
	"

	amove usr/bin/hyprpm
}

sha512sums="
9af6e517cf3abadb1745e5c7014ac1c88e0ee16a51400fcf4a3f13faf88a5be52f4b66ffd7e4a37cdc6351e460f53ab64547b5e1e2be73004c1084bd8b826715  Hyprland-v0.49.0.tar.gz
fc05cc9f3b5be34e65d0d427dcb8306a21bb1d312ae73463ac47bf802a31bbc886d223bdbb9b00c845a4e36e5d2848e6637a944436912bff06da7b4e75f5c6bc  include-cstring.patch
"
