# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=libcacard
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.8.1
pkgrel=2
pkgdesc="(Common Access Card) library thar provides emulation of smart cards to a virtual card reader running in a guest virtual machine (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://gitlab.freedesktop.org/spice/libcacard'
msys2_references=(
  "cpe: cpe:/a:libcacard_project:libcacard"
)
license=('spdx:LGPL-2.1-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-glib2"
  "${MINGW_PACKAGE_PREFIX}-nspr"
  "${MINGW_PACKAGE_PREFIX}-nss"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
source=(https://www.spice-space.org/download/libcacard/libcacard-$pkgver.tar.xz{,.sig}
        "001-missing-deps.patch")
validpgpkeys=('EFC9937E969FD53E718D0DD4CB6BE1D0D7D1594A') #Jakub Jelen (work) <jjelen@redhat.com>
sha256sums=('fbbf4de8cb7db5bdff5ecb672ff0dbe6939fb9f344b900d51ba6295329a332e7'
            'SKIP'
            'bb26937a1384e93999625c477660d7774e4c5766ebfdab0b15823a3857db154b')

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

  patch -Np1 -i "${srcdir}"/001-missing-deps.patch
}

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

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    meson \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Dpcsc=disabled \
      ../${_realname}-${pkgver}

  meson compile
}

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

  DESTDIR="${pkgdir}" meson install

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