# Maintainer: Frederik Carlier <frederik.carlier@keysight.com>

_realname=pkcs11-helper
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.30.0
pkgrel=1
pkgdesc="pkcs11-helper (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/OpenSC/pkcs11-helper/'
license=('spdx:GPL-2.0 or BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "man2html")
depends=("${MINGW_PACKAGE_PREFIX}-openssl")
source=("https://github.com/OpenSC/${_realname}/releases/download/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.bz2")
sha256sums=('4c5815ba910cabf26df08d449ca2909daf4538c9899aa7f7fadc61229d3488a9')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  autoreconf -ivf
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../"${_realname}-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}" \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make install DESTDIR="${pkgdir}"

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