# Contributor: Karol Babioch <karol@babioch.de>

pkgbase=libfido2
pkgname=("${pkgbase}" "fido2-tools" "${pkgbase}-devel" "${pkgbase}-docs")
pkgver=1.16.0
pkgrel=1
pkgdesc="Library functionality for FIDO 2.0, including communication with a device over USB"
arch=('i686' 'x86_64')
url="https://developers.yubico.com/libfido2/"
msys2_repository_url="https://github.com/Yubico/libfido2"
license=('BSD-2-Clause')
depends=("libcbor" "openssl" "zlib")
makedepends=("libcbor-devel" "openssl-devel" "cmake" "gcc" "zlib-devel" "ninja")
source=("https://developers.yubico.com/libfido2/Releases/libfido2-${pkgver}.tar.gz"{,.sig}
        msys2-fix-ln.diff)
sha256sums=('8c2b6fb279b5b42e9ac92ade71832e485852647b53607c43baaafbbcecea04e4'
            'SKIP'
            '3134757a26e80eb1917036d4402551fa517e4e0e678c54dcf6c166b714de2bf2')
# https://developers.yubico.com/Software_Projects/Software_Signing.html
validpgpkeys=(
  '1D7308B0055F5AEF36944A8F27A9C24D9588EA0F' # Aveen Ismail <aveen.ismail@yubico.com>
  '7FBB6186957496D58C751AC20E777DD85755AA4A' # Konstantinos Georgantas <kostas@yubico.com>
  '78D997D53E9C0A2A205392ED14A19784723C9988' # Ludvig Michaelsson <ludvig.michaelsson@yubico.com>
)

prepare() {
  cd ${pkgname}-${pkgver}
  patch -p1 -i ${srcdir}/msys2-fix-ln.diff
}

build() {
  cmake \
    -GNinja \
    -S "${pkgname}-${pkgver}" \
    -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DUSE_WINHELLO=ON
  cmake --build build
  DESTDIR="${srcdir}/dest" cmake --install build
}

package_libfido2() {
  groups=("libraries")

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_fido2-tools() {
  pkgdesc="FIDO2 command line tools to access and configure a FIDO2 compliant authentication device"
  depends=("$pkgbase=$pkgver")

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  mkdir -p ${pkgdir}/usr/share/man
  cp -rf ${srcdir}/dest/usr/share/man/man1 ${pkgdir}/usr/share/man
}

package_libfido2-devel() {
  pkgdesc="Development headers and library for libfido2"
  depends=("$pkgbase=$pkgver")
  groups=("development")

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib/pkgconfig ${pkgdir}/usr/lib/ 
  cp -f ${srcdir}/dest/usr/lib/*.a ${pkgdir}/usr/lib
}

package_libfido2-docs() {
  pkgdesc="Documentation for libfido2"
  depends=("libfido2-devel=$pkgver")  

  mkdir -p ${pkgdir}/usr/share/man
  cp -rf ${srcdir}/dest/usr/share/man/man3 ${pkgdir}/usr/share/man
}

