# Maintainer: Callum Osmotherly <acheronfail@gmail.com>
pkgname=istat
pkgver="0.1.5"
pkgrel=1
pkgdesc="A lightweight and batteries-included status_command for i3 and sway"
arch=('x86_64')
url="https://github.com/acheronfail/istat"
license=('GPL-3.0-only')
depends=('gcc-libs')
makedepends=('cargo' 'clang' 'libpulse')
source=("$pkgname-$pkgver.tar.gz::https://static.crates.io/crates/$pkgname/$pkgname-$pkgver.crate")
sha512sums=('90131481ac920c9fc7dce13c07db6503d3ba06968c7849b65d4cf6f739d35ff1a5d79630d1f34c78de7397962e4b07077419376e5972f1d57561171bc1ed37a1')

# this is effectively a no-op for standard usages of the PKGBUILD, but it exists for
# local testing of the PKGBUILD itself in the upstream repository (when the build version
# doesn't match the PKGBUILD because it hasn't been released yet)
prepare() {
  _dirname=$(bsdtar -tf "${source[0]%%::*}" | awk -F / '{print $1; exit}')
  mv "$_dirname" $pkgname-$pkgver
}

build() {
  cd "$pkgname-$pkgver"

  # builds all the crate's binaries
  cargo build --release --locked

  # the manpages are generated by the tests
  cargo test --release --locked manpage
}

check() {
  cd "$pkgname-$pkgver"

  cargo test --release --locked
}

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

  install -Dm755 "target/release/istat"         "$pkgdir/usr/bin/istat"
  install -Dm755 "target/release/istat-ipc"     "$pkgdir/usr/bin/istat-ipc"
  install -Dm755 "target/release/istat-signals" "$pkgdir/usr/bin/istat-signals"
  install -Dm755 "target/release/istat-sensors" "$pkgdir/usr/bin/istat-sensors"

  install -Dm644 "doc/istat.1"                 "$pkgdir/usr/share/man/man1/istat.1"
  install -Dm644 "doc/istat-ipc.1"             "$pkgdir/usr/share/man/man1/istat-ipc.1"
  install -Dm644 "doc/istat-ipc-click.1"       "$pkgdir/usr/share/man/man1/istat-ipc-click.1"
  install -Dm644 "doc/istat-ipc-custom.1"      "$pkgdir/usr/share/man/man1/istat-ipc-custom.1"
  install -Dm644 "doc/istat-ipc-info.1"        "$pkgdir/usr/share/man/man1/istat-ipc-info.1"
  install -Dm644 "doc/istat-ipc-refresh-all.1" "$pkgdir/usr/share/man/man1/istat-ipc-refresh-all.1"
  install -Dm644 "doc/istat-ipc-signal.1"      "$pkgdir/usr/share/man/man1/istat-ipc-signal.1"

  install -Dm644 "README.md"          "$pkgdir/usr/share/doc/${pkgname}/README.md"
  install -Dm644 "sample_config.toml" "$pkgdir/usr/share/doc/${pkgname}/sample_config.toml"
  install -Dm644 "LICENSE"            "$pkgdir/usr/share/licenses/${pkgname}/LICENSE"
}
