# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Alad Wenter <alad@archlinux.org>
# Maintainer: Christian Hesse <mail@eworm.de>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Daniel Plaza <daniel.plaza.espi@gmail.com>

pkgname=pcsclite
pkgver=2.3.0
pkgrel=1.1
pkgdesc="PC/SC Architecture smartcard middleware library"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url='https://pcsclite.apdu.fr/'
# https://salsa.debian.org/rousseau/PCSC/-/blob/2.0.3/COPYING
license=(
  'BSD-3-Clause'        # Most of it
  'GPL-3.0-or-later'    # doc/example/pcsc_demo.c, src/spy/, UnitaryTests/
  'BSD-2-Clause'        # src/auth.c, src/auth.h
  '0BSD'                # src/simclist.c, src/simclist.h
)
depends=(
  'libsystemd.so'
  'libudev.so'
  'libpolkit-gobject-1.so'
)
makedepends=(
  'git'
  'meson'
  'polkit'
  'systemd'
)
optdepends=(
  'python: API call trace logging with the pcsc-spy'
  'ccid: USB Chip/Smart Card Interface Devices driver'
)
provides=(
  'libpcsclite.so'
  'libpcsclite_real.so'
  'libpcscspy.so'
)
validpgpkeys=('F5E11B9FFE911146F41D953D78A1B4DFE8F9C57E') # Ludovic Rousseau <rousseau@debian.org>
source=(
  "git+https://github.com/LudovicRousseau/PCSC.git#tag=${pkgver}?signed"
)
sha256sums=('04bbbb8f63172cd2203d07b801f8e650c94cbcc9c222aa5f18fbabbf807f22e3')

build() {
  local meson_options=(
    -D libsystemd=true
    -D libudev=true
    -D polkit=true
    -D serial=true
    -D systemdunit=system
  )
  arch-meson PCSC build "${meson_options[@]}"
  meson compile -C build

  # namcap requires separate files for each "uncommon" license (ex: BSD* ones), so splitting the upstream COPYING file
  awk '/David Corcoran/{flag=1} /GNU GPL v3/ {flag=0} flag' PCSC/COPYING > LICENSE.BSD-3-Clause
  awk '/GNU GPL v3/    {flag=1} /auth.c/     {flag=0} flag' PCSC/COPYING > LICENSE.GPL-3.0-or-later
  awk '/auth.c/        {flag=1} /simclist.c/ {flag=0} flag' PCSC/COPYING > LICENSE.BSD-2-Clause
  awk '/simclist.c/    {flag=1} flag'                       PCSC/COPYING > LICENSE.0BSD
}

package() {
  meson install -C build --destdir "${pkgdir}"

  install -D -m0644 LICENSE.* -t "$pkgdir/usr/share/licenses/$pkgname"
  install -d "$pkgdir/usr/lib/pcsc/drivers"
}

# vim:set sw=2 sts=-1 et:
