# Maintainer: Orhun Parmaksız <orhun@archlinux.org>
# Contributor: Eli Schwartz <eschwartz@archlinux.org>

pkgname=kmon
pkgver=1.7.1
pkgrel=1
pkgdesc="Linux kernel manager and activity monitor"
arch=('x86_64')
url="https://github.com/orhun/kmon"
license=('GPL3')
depends=('kmod' 'libxcb')
makedepends=('rust' 'python' 'git')
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha512sums=('bb5ba5ef76bc15fb4ab59061e132972760610755928fd74651d05acda0cf7e0fc6925aacbebb539349f8c58c3e963844cc87e0de9ddd942b106e16bb6bdb5fc3')

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

build() {
  cd "${pkgname}-${pkgver}"
  cargo build --release --frozen
}

check() {
  cd "${pkgname}-${pkgver}"
  cargo test --frozen
}

package() {
  cd "${pkgname}-${pkgver}"
  install -Dm 755 "target/release/${pkgname}" -t "${pkgdir}/usr/bin"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 "target/man/${pkgname}.8" -t "${pkgdir}/usr/share/man/man8"
  install -Dm 644 "target/completions/${pkgname}.bash" "${pkgdir}/usr/share/bash-completion/completions/${pkgname}"
  install -Dm 644 "target/completions/${pkgname}.fish" -t "${pkgdir}/usr/share/fish/vendor_completions.d"
  install -Dm 644 "target/completions/_${pkgname}" -t "${pkgdir}/usr/share/zsh/site-functions"
}
