# Maintainer: Andreas Radke <andyrtr@archlinux.org>

# after a .so bump first rebuild dirmngr
# with sudo testing-x86_64-build -- -I libgcrypt-1.6.0-1-x86_64.pkg.tar.xz
# then cp /usr/lib/libgcrypt.so.11 /var/lib/archbuild/staging-x86_64/root/usr/lib/ and do staging-x86_64-build

_pkgname=libgcrypt
pkgname=static-compat-$_pkgname
pkgver=1.10.1
pkgrel=1
pkgdesc="General purpose cryptographic library based on the code from GnuPG"
arch=(x86_64)
url="https://www.gnupg.org"
license=('LGPL')
depends=('static-compat-libgpg-error')
makedepends=('static-compat-configure')
options=('!emptydirs' staticlibs)
# https://www.gnupg.org/download/integrity_check.html
source=(https://gnupg.org/ftp/gcrypt/${_pkgname}/${_pkgname}-${pkgver}.tar.bz2{,.sig})
sha1sums=('de2cc32e7538efa376de7bf5d3eafa85626fb95f'
          'SKIP')
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA') # "Werner Koch (dist signing 2020)"

prepare() {
  source static-compat-environment
  cd "${_pkgname}"-${pkgver}
  # tests fail due to systemd+libseccomp preventing memory syscalls when building in chroots
  #  t-secmem: line 176: gcry_control (GCRYCTL_INIT_SECMEM, pool_size, 0) failed: General error
  #  FAIL: t-secmem
  #  t-sexp: line 1174: gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0) failed: General error
  #  FAIL: t-sexp
  sed -i "s:t-secmem::" tests/Makefile.am
  sed -i "s:t-sexp::" tests/Makefile.am
  autoreconf -vfi
}

build() {
  source static-compat-environment
  cd "${_pkgname}"-${pkgver}
  static-compat-configure \
    --disable-shared \
    --enable-static \
    --disable-padlock-support
  make
}

check() {
  cd "${_pkgname}"-${pkgver}
  make check
}

package() {
  source static-compat-environment
  cd "${_pkgname}"-${pkgver}
  make DESTDIR="${pkgdir}" install
  rm -r "$pkgdir/$static_compat_prefix"/share/{man,info}
}
