#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobcore/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgbase=gpgme
pkgname=(gpgme qgpgme python-gpgme)
pkgver=1.20.0
pkgrel=02
pkgdesc="A C wrapper library for GnuPG"
#options=('debug')  ##  uncomment this to have the debug pkg produced
url='https://www.gnupg.org/related_software/gpgme/'
makedepends=('gnupg' 'libgpg-error' 'python' 'python-setuptools' 'python-build' 'python-installer' 'python-setuptools' 'python-wheel' 'qt5-base' 'swig')
source=("https://www.gnupg.org/ftp/gcrypt/${pkgbase}/${pkgbase}-${pkgver}.tar.bz2"{,.sig})

#prepare() {
#  cd ${pkgbase}-${pkgver}
#
#  patch -Np1 -i ../0001-python-3-10.patch
#  patch -Np1 -i ../0002-python-setup.patch
#}

build() {
  cd ${pkgbase}-${pkgver}

  ./configure \
    --prefix=/usr \
    --disable-fd-passing \
    --disable-static \
    --disable-gpgsm-test
  make

  (
    # use a PEP517 workflow to get a reproducible Python package
    # NOTE: top_builddir is required so that the build takes place against local gpgme, not system gpgme
     cd lang/python/
    top_builddir="$srcdir/$pkgbase-$pkgver" python -m build --wheel --no-isolation
  )

}

check() {
  cd ${pkgbase}-${pkgver}

  # this test fails with gnupg (FS#66572)
  sed -i 's#"t-keylist-secret",##' tests/json/t-json.c

  make check
#
#  # ensure reproducibilty whether test-suite is run or not
#  find . -name *.pyc -exec rm {} +
}

package_gpgme() {
  depends=('libgpg-error' 'gnupg>=2')
  options+=('!emptydirs')
  provides=('libgpgme.so'
            'libgpgmepp.so')

  cd ${pkgbase}-${pkgver}

  make DESTDIR="${pkgdir}" install

  # split qgpgme
  rm -r "${pkgdir}"/usr/include/{qgpgme,QGpgME}/
  rm -r "${pkgdir}"/usr/lib/{cmake/QGpgme/,libqgpgme.*}
  rm -r "${pkgdir}"/usr/lib/python*
}

package_qgpgme() {
  pkgdesc="Qt bindings for GPGme"
  depends=('gpgme' 'qt5-base')

  cd ${pkgbase}-${pkgver}/lang/qt

  make DESTDIR="${pkgdir}" install
}

package_python-gpgme() {
  pkgdesc="Python bindings for GPGme"
  depends=('gpgme' 'python')

  cd ${pkgbase}-${pkgver}/lang/python
  python -m installer --destdir="$pkgdir" dist/*.whl
}

#---- arch license gpg-key & sha256sums ----

arch=(x86_64)

license=('LGPL')

validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA' # Werner Koch (dist signing 2020)
              'AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD') # Niibe Yutaka (GnuPG Release Key)

sha256sums=(25a5785a5da356689001440926b94e967d02e13c49eb7743e35ef0cf22e42750  # gpgme-1.20.0.tar.bz2
	f32a7e1c6c132ca06dde763b243ab0f4055fb360ced1761829c7dc8b38528db6) # gpgme-1.20.0.tar.bz2.sig

##  24b7a71a323ed01ef88c76909b81e176dcfdc64730232aeae9f4e053b3d99075  gpgme-1.20.0-02-x86_64.pkg.tar.lz
##  cbe1cb571aeec3970c1d6c888b6c7d17133f2d7f3c1d86bdf686b00256eab345  python-gpgme-1.20.0-02-x86_64.pkg.tar.lz
##  65e1175c6fe91acf3bd7ff1f3d6d7bea9dc32f37755b6d462afc8b9c41dca8d8  qgpgme-1.20.0-02-x86_64.pkg.tar.lz

