# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=openpgp-card-tools
pkgver=0.11.7
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=('8a92b4ba88a80a0d57f7fc6002aa44e407433f0e27bf85bd240acfe405e53e934684036255aa36663065402da3275978ebf347d7213944088ea9673623e8e6d8')
b2sums=('b39fa5396e12819670030d241d5f3048660e31e8c09f640e42ef0877f1d658d314bd9031d1d2497088c48b810516dccb388f41f3e891549e6003ac4938367aeb')

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/"
}
