# Maintainer: Jorge Cardona <jorge@cardona.co>
pkgname=suspiro
pkgver=0.1.9
pkgrel=1
pkgdesc="Voice dictation with push-to-talk - powered by whisper.cpp"
arch=('x86_64' 'aarch64')
url="https://gitlab.com/jorgeecardona/suspiro"
license=('MIT')
depends=('gcc-libs' 'alsa-lib')
makedepends=('rust' 'cargo' 'clang' 'cmake')
source=("$pkgname-$pkgver.tar.gz::$url/-/archive/v$pkgver/$pkgname-v$pkgver.tar.gz")
sha256sums=('SKIP')

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

build() {
    cd "$pkgname-v$pkgver"
    export RUSTUP_TOOLCHAIN=stable
    export CARGO_TARGET_DIR=target
    cargo build --frozen --release --all-features
}

check() {
    cd "$pkgname-v$pkgver"
    export RUSTUP_TOOLCHAIN=stable
    cargo test --frozen --all-features
}

package() {
    cd "$pkgname-v$pkgver"

    # Binary
    install -Dm755 "target/release/suspiro" "$pkgdir/usr/bin/suspiro"

    # systemd user service
    install -Dm644 "data/suspiro.service" "$pkgdir/usr/lib/systemd/user/suspiro.service"

    # D-Bus service files
    install -Dm644 "data/io.suspiro.Daemon.service" "$pkgdir/usr/share/dbus-1/services/io.suspiro.Daemon.service"
    install -Dm644 "data/io.suspiro.Daemon.conf" "$pkgdir/usr/share/dbus-1/system.d/io.suspiro.Daemon.conf"

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

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