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

pkgbase=libgcrypt
pkgname=('libgcrypt' 'libgcrypt-devel')
pkgver=1.11.2
pkgrel=1
pkgdesc="General purpose cryptographic library based on the code from GnuPG"
arch=(i686 x86_64)
url="https://gnupg.org"
msys2_repository_url="https://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git"
msys2_references=(
  "cpe: cpe:/a:gnupg:libgcrypt"
)
license=('LGPL')
depends=('libgpg-error')
makedepends=('gcc' 'make' 'libgpg-error-devel' 'autotools')
options=('!emptydirs')
source=(https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2{,.sig})
sha256sums=('6ba59dd192270e8c1d22ddb41a07d95dcdbc1f0fb02d03c4b54b235814330aac'
            'SKIP')
#These might be signed by any of these keys https://gnupg.org/signature_key.html
validpgpkeys=('5B80C5754298F0CB55D8ED6ABCEF7E294B092E28'  # Andre Heinecke (Release Signing Key)
              '6DAA6E64A76D2840571B4902528897B826403ADA'  # Werner Koch (dist signing 2020)
              'AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD'  # Niibe Yutaka (GnuPG Release Key)
              '02F38DFF731FF97CB039A1DA549E695E905BA208') # GnuPG.com (Release Signing Key 2021)

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

  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')

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