# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=('libksba' 'libksba-devel')
pkgver=1.6.7
pkgrel=1
pkgdesc="A CMS and X.509 access library"
arch=('i686' 'x86_64')
url="https://www.gnupg.org/related_software/libksba/"
msys2_repository_url="https://git.gnupg.org/cgi-bin/gitweb.cgi?p=libksba.git"
msys2_references=(
  "cpe: cpe:/a:gnupg:libksba"
  "cpe: cpe:/a:libksba_library:libksba_library"
)
license=('spdx:LGPL-3.0-or-later OR GPL-2.0-or-later')
makedepends=('libgpg-error-devel' 'autotools' 'gcc')
options=('strip' 'libtool')
source=(https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2{,.sig})
sha256sums=('cf72510b8ebb4eb6693eef765749d83677a03c79291a311040a5bfd79baab763'
            'SKIP')
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA') # Werner Koch (dist signing 2020)

prepare() {
  cd "$pkgname-$pkgver"

  autoreconf -fiv
}

build() {
  cd "$pkgname-$pkgver"

  ./configure \
    --prefix=/usr \
    --build="${CHOST}" \
    --enable-shared \
    --disable-static

  make no_undefined="-no-undefined"
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "$pkgname-$pkgver"

  make check
}

package_libksba() {
  groups=('libraries')
  depends=('gcc-libs' 'libgpg-error')

  mkdir -p $pkgdir/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll $pkgdir/usr/bin/
  cp -rf ${srcdir}/dest/usr/share $pkgdir/usr/
  install -D -m644 ${srcdir}/${pkgname}-${pkgver}/COPYING $pkgdir/usr/share/licenses/libksba/COPYING
}

package_libksba-devel() {
  pkgdesc="Libassuan headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libksba=${pkgver}" 'libgpg-error-devel')

  mkdir -p $pkgdir/usr/bin
  cp -f ${srcdir}/dest/usr/bin/ksba-config $pkgdir/usr/bin/
  cp -rf ${srcdir}/dest/usr/include $pkgdir/usr/
  cp -rf ${srcdir}/dest/usr/lib $pkgdir/usr/
}
