# Builds the newest state of the main branch:
#   makepkg -si
#
# KWin only loads effects built against its exact version, so the package
# depends on exactly the KWin it was built with: rebuild it after every
# KWin update (pacman refuses the update until then).

pkgname=pla8ma-kwineffect-openclose-git
_repo=pla8ma-kwineffect-openclose
pkgver=r0
pkgrel=1
pkgdesc='Pla8ma open/close animation for KDE Plasma'
arch=('x86_64')
url="https://github.com/pla8ma/$_repo"
license=('GPL-2.0-or-later')
depends=('kwin')
makedepends=('git' 'cmake' 'extra-cmake-modules' 'vulkan-headers')
provides=("${pkgname%-git}")
conflicts=("${pkgname%-git}")
source=("git+$url.git")
sha256sums=('SKIP')

pkgver() {
    cd "$_repo"
    printf 'r%s.%s' "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
}

build() {
    cmake -S "$_repo" -B build \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE=None \
        -DBUILD_TESTING=OFF \
        -DKDE_INSTALL_USE_QT_SYS_PATHS=ON
    cmake --build build
}

package() {
    local kwin_version
    kwin_version=$(pacman -Q kwin | awk '{ sub(/-[^-]*$/, "", $2); print $2 }')
    depends=("kwin=$kwin_version")

    DESTDIR="$pkgdir" cmake --install build
    install -Dm644 "$_repo/README.md" -t "$pkgdir/usr/share/doc/$pkgname/"
}
