# The group tag is just to easily find this APKBUILD by some scripts for automation
# group=kde-plasma
maintainer="team/kde <bribbers@disroot.org>"
pkgname=powerdevil
pkgver=6.3.5
pkgrel=0
pkgdesc="Manages the power consumption settings of a Plasma Shell"
# armhf blocked by qt6-qtdeclarative -> ki18n
# s390x blocked by plasma-workspace
arch="all !armhf !s390x"
url="https://kde.org/plasma-desktop/"
license="GPL-2.0-or-later AND LGPL-2.0-or-later AND (LGPL-2.1-only OR LGPL-3.0-only)"
depends="upower"
depends_dev="
	bluez-qt-dev
	ddcutil-dev
	eudev-dev
	kauth-dev
	kcmutils-dev
	kconfig-dev
	kcrash-dev
	kdbusaddons-dev
	kglobalaccel-dev
	ki18n-dev
	kidletime-dev
	kio-dev
	kirigami-dev
	kitemmodels-dev
	knotifications-dev
	knotifyconfig-dev
	kwayland-dev
	libkscreen-dev
	networkmanager-qt-dev
	plasma-activities-dev>=$pkgver
	plasma-workspace-dev
	qt6-qtbase-dev
	solid-dev
	"
makedepends="$depends_dev
	extra-cmake-modules
	kdoctools-dev
	libcap-utils
	samurai
	"
checkdepends="bash"

case "$pkgver" in
	*.*.9*) _rel=unstable;;
	*) _rel=stable;;
esac

subpackages="$pkgname-dev $pkgname-libs $pkgname-doc $pkgname-lang"
_repo_url="https://invent.kde.org/plasma/powerdevil.git"
source="https://download.kde.org/$_rel/plasma/$pkgver/powerdevil-$pkgver.tar.xz"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib
	cmake --build build
}

check() {
	ctest --test-dir build -E "migrateconfig_test(1_default_configs_can_suspend_to_ram|2_activities|2a_activities_no_double_migration|3_profiles|4_profiles_more)"
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# We don't ship systemd
	rm -r "$pkgdir"/usr/lib/systemd

	# org_kde_powerdevil has CAP_WAKE_ALARM set and this breaks dbus
	# Remove CAP_WAKE_ALARM from org_kde_powerdevil to make it work again
	setcap -r "$pkgdir"/usr/lib/libexec/org_kde_powerdevil
}

sha512sums="
fafae5d2eaa6063d6bc16fe6fd6bbf4d47a624ce2fabb6ee06cd9c00d5412d76f77aed09bb48963a47f18e87e86ad47bbd759eba8e5c33e2806a8fa87e4c0aa9  powerdevil-6.3.5.tar.xz
"
