# 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.45.0
pkgrel=0
pkgdesc="Wayland shell for GNOME on mobile devices"
# armhf: blocked by gnome-shell-schemas
# Blocked on s390x by gnome-session, gnome-settings-daemon, squeekboard and libhandy
arch="all !armhf !s390x"
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
	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
	phosh.desktop
	"
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 --no-rebuild --print-errorlogs -C output
}

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

	install -D -m644 "$srcdir"/phosh.desktop \
		"$pkgdir"/usr/share/wayland-sessions/phosh.desktop

	# 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() {
	local _soname="libphosh-$(echo $pkgver | sed -E 's/^([0-9]+)\.([0-9]+).*/\1.\2/')"
	amove usr/include/$_soname
	amove usr/lib/$_soname.so
	amove usr/lib/pkgconfig/$_soname.pc
}

sha512sums="
bb9ae902c979d410c8ab85ed04c1bdb7f99d77a0e7fe84c31485e8e9c8fdc49cc5475921b8e5839a73db9d615df5c17114149fd06642d6b37fa3fd08d8ebf1bf  phosh-0.45.0.tar.xz
8ca4893a751311de326e198314669f5a276092ade99c6353c4c9ce070713fb1a5b1615e7fecb93b428dc79fd4001a9af43d24eafaf2545d7db464963fda25330  phosh.desktop
"
