# Maintainer: Dirk Stolle

_realname=cotp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.9.7
pkgrel=1
pkgdesc="Trustworthy, encrypted, command-line TOTP/HOTP authenticator app with import functionality (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/replydev/cotp'
msys2_changelog_url='https://github.com/replydev/cotp/blob/main/CHANGELOG.md'
msys2_references=(
  'archlinux: cotp'
  'aur: cotp-git'
  'purl: pkg:cargo/cotp'
)
license=('spdx:GPL-3.0-only')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
optdepends=("${MINGW_PACKAGE_PREFIX}-python: to use scripts for import from other OTP apps")
source=("https://github.com/replydev/cotp/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('6234805a8eb20a71d2acb07ad8d7827bd5c98c653b7eb733bab0f90cbb9f6212')

prepare() {
  cd "${_realname}-${pkgver}"

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

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen --all-features
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen --all-features
}

package() {
  cd "${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm0755 -t "${pkgdir}${MINGW_PREFIX}/share/cotp/converters/" converters/*.py

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
