# Contributor: Bart Ribbers <bribbers@disroot.org>
# Contributor: Danct12 <danct12@disroot.org>
# Contributor: Newbyte <newbyte@disroot.org>
# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: team/phosh <newbyte@postmarketos.org>
pkgname=phosh
pkgver=0.47.0
pkgrel=2
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-fonts
	adwaita-icon-theme
	bash
	dbus-x11
	dbus:org.freedesktop.Secrets
	desktop-file-utils
	gnome-control-center
	gnome-session
	gnome-settings-daemon
	gnome-shell-schemas
	gsettings-desktop-schemas
	phoc
	phosh-keyboard
	xwayland
	"
makedepends="
	callaudiod-dev
	elogind-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-elogind-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
	"
source="https://sources.phosh.mobi/releases/phosh/phosh-${pkgver/_/.}.tar.xz
	wayland-session-start-dbus.patch
	media-player.patch
	update-force-adaptive-list.patch
	"
builddir="$srcdir/$pkgname-${pkgver/_/.}"

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 --print-errorlogs -C output
}

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

	# https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/64741#note_402279
	rm -r "$pkgdir"/usr/lib/systemd
}

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

libphosh_dev() {
	amove usr/include/libphosh-*
	amove usr/lib/libphosh-*.so
	amove usr/lib/pkgconfig/libphosh-*.pc
}

sha512sums="
19c150d28921b383269e4c95d353b7ea69e62cc4075a7a1e1523aa0977b347898d16df7d88861e5d029469a881623e15673ee270c3c514db123aec683ec8194d  phosh-0.47.0.tar.xz
927e6a531c81c90b3f54f10b360b1e7c8b0eacf549f623096c50ecfbc752ad59486e2748acb1f0c88c1a93db67dd3864b007b623e1a99b0bc8a5b9c91d4185f5  wayland-session-start-dbus.patch
20bf4d50611560e14182c7cb139aadcf59508f57caefe564e0cfe7d29e7c3e9985c787f832f353b7c7f017e6b373ef0a7b69368071ac0ba4b2a6160ad606f0a9  media-player.patch
b4cf4c1dd5993cdb1d77daa066be46768e65231a3b9d89aba02e7326882b0dfca69ca4fa69cb2c25b41d974e81f1a9a858e7bda669d376097a6c3615bf665c8c  update-force-adaptive-list.patch
"
