# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=openpgp-card-tools
pkgver=0.11.2
pkgrel=1
pkgdesc="CLI tool to inspect, manage and use OpenPGP cards"
arch=(x86_64)
url="https://codeberg.org/openpgp-card/openpgp-card-tools"
license=('Apache-2.0 OR MIT')
depends=(
  ccid
  gcc-libs
  glibc
)
makedepends=(
  cargo
  pcsclite
)
source=($pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz)
sha512sums=('6a1899e6338718a0602bac99872c2d3a84b18bfee0f39a7cfe298225cae00fb5ed9c1ac15de74d0eb071e9c3ab0915e3cab062d631997e2db63434cbd6f37e80')
b2sums=('4f5bce60fdf5c2c99ae6dadaf666a619eeeed51bd5841dfeb41e73d5919cf1253fae274f05d0228438f61ced66ed5531a7337b5df5c31fb18dc972972728f95f')

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

build() {
  cd $pkgname
  export RUSTUP_TOOLCHAIN=stable
  export CARGO_TARGET_DIR=target
  cargo build --frozen --release
  OCT_MANPAGE_OUTPUT_DIR="$PWD/../man/" cargo run
  OCT_COMPLETION_OUTPUT_DIR="$PWD/../completion/" cargo run
}

package() {
  depends+=(
    pcsclite libpcsclite.so
  )

  cd $pkgname
  install -vDm 755 target/release/oct -t "$pkgdir/usr/bin/"
  install -vDm 644 {scripting,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
  install -vDm 644 LICENSES/MIT.txt -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 ../man/*.1 -t "$pkgdir/usr/share/man/man1/"
  install -vDm 644 ../completion/oct.bash "$pkgdir/usr/share/bash-completion/completions/oct"
  install -vDm 644 ../completion/_oct -t "$pkgdir/usr/share/zsh/site-functions/"
  install -vDm 644 ../completion/oct.fish -t "$pkgdir/usr/share/fish/vendor_completions.d/"
}
