# Forked from Alpine for systemd split func
maintainer="fossdd <fossdd@pwned.life>"
pkgname=phosh
_pkgver=0.45.0
pkgver=9999$_pkgver
pkgrel=0
pkgdesc="Wayland shell for GNOME on mobile devices"
# armhf: blocked by gnome-shell-schemas
arch="all !armhf"
url="https://gitlab.gnome.org/World/Phosh/phosh"
license="GPL-3.0-only"
triggers="$pkgname.trigger=/usr/lib/phosh/plugins/prefs"
depends="
	adwaita-icon-theme
	bash
	dbus-x11
	dbus:org.freedesktop.Secrets
	desktop-file-utils
	font-adobe-source-code-pro
	font-cantarell
	gnome-control-center
	gnome-session
	gnome-settings-daemon
	gnome-shell-schemas
	gsettings-desktop-schemas
	phoc
	phosh-keyboard
	xwayland
	"
makedepends="
	callaudiod-dev
	systemd-dev
	evince-dev
	evolution-data-server-dev
	feedbackd-dev
	gcr-dev
	gettext-dev
	glib-dev
	gmobile-dev
	gnome-bluetooth-dev
	gnome-desktop-dev
	gtk+3.0-dev
	libadwaita-dev
	libgudev-dev
	libhandy1-dev
	libsecret-dev
	linux-pam-dev
	meson
	modemmanager-dev
	networkmanager-dev
	polkit-dev
	pulseaudio-dev
	py3-docutils
	upower-dev
	wayland-dev
	wayland-protocols
	"
checkdepends="xvfb-run"
# the ordering here is important - libphosh split functions need to run first to move the libphosh-0
# headers/pkgconfig/lib into the libphosh packages, before the top level -dev package gobbles
# up the rest.
subpackages="
	libphosh:libs
	libphosh-dev:libphosh_dev
	$pkgname-dbg
	$pkgname-lang
	$pkgname-dev
	$pkgname-doc
	$pkgname-portalsconf
	$pkgname-systemd
	"
source="https://sources.phosh.mobi/releases/phosh/phosh-${_pkgver/_/.}.tar.xz
	"
builddir="$srcdir/$pkgname-${_pkgver/_/.}"
# TODO: crossdirect disabled due to armv7 crosscompile failure on x86_64, see
# https://gitlab.postmarketos.org/postmarketOS/pmaports/-/issues/2820
options="!check !pmb:crossdirect" # "/var/lib/dbus/machine-id": No such file or directory

prepare() {
	default_prepare
	sed -i 's/\.rc/_rc/' meson.build
}

build() {
	# phoc tests need a running Wayland compositor
	abuild-meson \
		-Db_lto=true \
		-Dphoc_tests=disabled \
		-Dman=true \
		-Dbindings-lib=true \
		. output
	meson compile -C output
}

check() {
	xvfb-run -a meson test --no-rebuild --print-errorlogs -C output
}

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

portalsconf() {
	install_if="$pkgname=$pkgver-r$pkgrel xdg-desktop-portal>=1.17.1"
	amove usr/share/xdg-desktop-portal/phosh-portals.conf
}

libphosh_dev() {
	local _soname="libphosh-${_pkgver%.*}"
	amove usr/include/$_soname
	amove usr/lib/$_soname.so
	amove usr/lib/pkgconfig/$_soname.pc
}

sha512sums="
bb9ae902c979d410c8ab85ed04c1bdb7f99d77a0e7fe84c31485e8e9c8fdc49cc5475921b8e5839a73db9d615df5c17114149fd06642d6b37fa3fd08d8ebf1bf  phosh-0.45.0.tar.xz
"
