# Maintainer: liixini <https://github.com/liixini>
pkgname=skwd-daemon
pkgver=r27.2870e20
pkgrel=1
pkgdesc='Daemon for Skwd Shell, a collection of Quickshell programs and widgets'
arch=('x86_64')
url='https://github.com/liixini/skwd-daemon'
license=('MIT')
makedepends=('cargo' 'gcc' 'clang' 'pkgconf' 'ffmpeg' 'alsa-lib' 'wayland' 'wayland-protocols' 'mesa')
depends=('gcc-libs' 'imagemagick' 'ffmpeg' 'alsa-lib' 'wayland' 'mesa')
options=('!debug' '!lto')
optdepends=(
  'ollama: local LLM for automated wallpaper tagging'
  'steamcmd: Steam Workshop Wallpaper Engine downloads'
  'linux-wallpaperengine: Wallpaper Engine scene rendering'
)
install="${pkgname}.install"
source=("${pkgname}::git+https://github.com/liixini/skwd-daemon.git")
sha256sums=('SKIP')

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

prepare() {
  cd "$pkgname"
  export RUSTUP_TOOLCHAIN=stable
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "$pkgname"
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  export CFLAGS="${CFLAGS//-flto*([^ ])/}"
  export LIBCLANG_PATH=/usr/lib
  cargo build --frozen --release
}

package() {
  cd "$pkgname"

  install -Dm755 target/release/skwd-daemon "$pkgdir/usr/bin/skwd-daemon"
  install -Dm755 target/release/skwd "$pkgdir/usr/bin/skwd"
  install -Dm755 target/release/skwd-paper "$pkgdir/usr/bin/skwd-paper"
  install -Dm755 target/release/skwd-paper-still "$pkgdir/usr/bin/skwd-paper-still"

  install -Dm644 data/skwd-daemon.service "$pkgdir/usr/lib/systemd/user/skwd-daemon.service"

  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
