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

pkgbase=libgcrypt
pkgname=('libgcrypt' 'libgcrypt-devel')
pkgver=1.9.4
pkgrel=1
pkgdesc="General purpose cryptographic library based on the code from GnuPG"
arch=(i686 x86_64)
url="https://gnupg.org"
license=('LGPL')
depends=('libgpg-error')
makedepends=('libgpg-error-devel')
options=('!emptydirs')
source=(https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2{,.sig}
        libgcrypt-1.7.3-ecc-test-fix.patch
        libgcrypt-1.8.0-use-poll.patch
        libgcrypt-1.6.1-msys2.patch)
sha256sums=('ea849c83a72454e3ed4267697e8ca03390aee972ab421e7df69dfe42b65caaf7'
            'SKIP'
            '3a420cc2b238203b1d107bb20313bfdaa79f8a1358678a2f222093223132038c'
            'ffa8d8dcb6193ff85f8f978625f24e589985dbe22e1858af9b52cd141a76052f'
            'cd7f58dc81a13328e34e0de8c6011196b5a2aa61b69dd611d4d7579ebf6cbb32')
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA') # "Werner Koch (dist signing 2020)"

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

  patch -p1 -i ${srcdir}/libgcrypt-1.7.3-ecc-test-fix.patch
  patch -p1 -i ${srcdir}/libgcrypt-1.8.0-use-poll.patch
  patch -p1 -i ${srcdir}/libgcrypt-1.6.1-msys2.patch

  autoreconf -fi
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}
  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static \
    --exec-prefix=/usr \
    --localstatedir=/var \
    --sysconfdir=/etc \
    --docdir=/usr/share/doc/libgcrypt \
    --htmldir=/usr/share/doc/libgcrypt/html \
    --config-cache \
    --disable-asm

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

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package_libgcrypt() {
  groups=('libraries')
  install=${pkgname}.install

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*-config
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
}

package_libgcrypt-devel() {
  pkgdesc="Libgcrypt headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libgcrypt=${pkgver}" 'libgpg-error-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
}
