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

pkgname=('libksba' 'libksba-devel')
pkgver=1.6.0
pkgrel=1
pkgdesc="A CMS and X.509 access library"
arch=('i686' 'x86_64')
url="https://www.gnupg.org/related_software/libksba/"
license=('GPL')
makedepends=('libgpg-error-devel')
options=('strip' 'libtool')
source=(https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2{,.sig}
        'msysize.patch')
sha256sums=('dad683e6f2d915d880aa4bed5cea9a115690b8935b78a1bbe01669189307a48b'
            'SKIP'
            '8329b743fa106622ac30451b60decdafce9149b94980de0d79489ed768301f3a')
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA') # Werner Koch (dist signing 2020)

prepare() {
  cd "$pkgname-$pkgver"
  patch -Np1 -i "$srcdir/msysize.patch"

  autoreconf -fiv
}

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

  ./configure \
    --prefix=/usr \
    --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')
  install=libksba.install

  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/
}
