# Maintainer: Louis-Alexander Kerst <louis@alexander-kerst.de>
#
# Builds the pacman package from this source checkout:
#   cd packaging/arch && makepkg -f
#   sudo pacman -U predator-control-*.pkg.tar.zst

pkgname=predator-control
pkgver=1.3.0
pkgrel=1
pkgdesc="PredatorSense replacement for Acer Predator laptops: performance modes, fans, keyboard RGB, lightbar, battery (Qt app + Plasma widget)"
arch=('any')
url="https://git.mrblake.cc/MrBlake/Cachy-Predator-Keyboard"
license=('GPL-2.0-only')
depends=('python' 'pyside6' 'dkms')
optdepends=('plasma-workspace: panel widget'
            'linux-headers: build the kernel module for the stock Arch kernel'
            'linux-cachyos-headers: build the kernel module for CachyOS kernels'
            'clang: needed by DKMS for clang-built kernels (CachyOS)'
            'lld: needed by DKMS for clang-built kernels (CachyOS)'
            'llvm: needed by DKMS for clang-built kernels (CachyOS)')
install=predator-control.install
source=()

_src="$(realpath "$startdir/../..")"
_modver=1.3.0

package() {
    cd "$_src"

    # Python package and launchers
    install -d "$pkgdir/usr/lib/predator-control/predator_control/gui"
    install -m644 predator_control/*.py "$pkgdir/usr/lib/predator-control/predator_control/"
    install -m644 predator_control/gui/*.py "$pkgdir/usr/lib/predator-control/predator_control/gui/"
    python -m compileall -q -d /usr/lib/predator-control "$pkgdir/usr/lib/predator-control"
    for b in predatord predatorctl predator-control; do
        install -Dm755 "bin/$b" "$pkgdir/usr/bin/$b"
    done

    # Kernel module as DKMS source (built automatically by the dkms pacman hook)
    install -d "$pkgdir/usr/src/predator-wmi-$_modver"
    install -m644 kernel/{predator_wmi.c,Makefile,dkms.conf} "$pkgdir/usr/src/predator-wmi-$_modver/"
    install -Dm644 data/modules-load-predator-control.conf "$pkgdir/usr/lib/modules-load.d/predator-control.conf"

    # Service, resume hook, desktop integration
    install -Dm644 data/predatord.service "$pkgdir/usr/lib/systemd/system/predatord.service"
    install -Dm755 data/system-sleep-predator-control "$pkgdir/usr/lib/systemd/system-sleep/predator-control"
    install -Dm644 data/predator-control.desktop "$pkgdir/usr/share/applications/predator-control.desktop"
    install -Dm644 data/predator-control.svg "$pkgdir/usr/share/icons/hicolor/scalable/apps/predator-control.svg"

    # Plasma panel widget
    local p="$pkgdir/usr/share/plasma/plasmoids/org.predatorcontrol.panel"
    install -Dm644 plasmoid/org.predatorcontrol.panel/metadata.json "$p/metadata.json"
    install -Dm644 plasmoid/org.predatorcontrol.panel/contents/ui/main.qml "$p/contents/ui/main.qml"

    install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
    install -Dm644 CHANGELOG.md "$pkgdir/usr/share/doc/$pkgname/CHANGELOG.md"
}
