# Maintainer: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: Roman Kyrylych <roman@archlinux.org>
# Contributor: Sarah Hay <sarah@archlinux.org>

pkgbase=gpgme
pkgname=(gpgme) #qgpgme-qt5 qgpgme-qt6  python-gpgme
pkgver=1.23.2
pkgrel=1.1
pkgdesc='A C wrapper library for GnuPG'
url='https://www.gnupg.org/related_software/gpgme/'
license=('LGPL')
ncxfab_makedepends=(base-devel)
ncxfat_makedepends=(
  'binutils'
  'gnupg'
  'libgpg-error'
  # 'python'
  # 'python-build'
  # 'python-installer'
  # 'python-setuptools'
  # 'python-wheel'
  # 'qt5-base'
  # 'qt6-base'
  # 'swig'
)
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA'  # Werner Koch (dist signing 2020)
              'AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD') # Niibe Yutaka (GnuPG Release Key)
source=("https://www.gnupg.org/ftp/gcrypt/gpgme/gpgme-${pkgver}.tar.bz2"{,.sig})
sha256sums=('9499e8b1f33cccb6815527a1bc16049d35a6198a6c5fae0185f2bd561bce5224'
            'SKIP')

prepare() {
  cd gpgme-${pkgver}/

  sed -i 's/-unknown//' autogen.sh
  autoreconf -fi

  # Building qt5 and qt6 bindings in the same source tree is not supported
  cp -r ${srcdir}/gpgme-${pkgver}{,-qt6}
}

build() {
  cd gpgme-${pkgver}

  ./configure \
    --prefix=$MPKG_USRPATH \
    --host=$MPKG_TARGETMACHINE \
    --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
  # )

  # cd ../gpgme-${pkgver}-qt6
  # ./configure \
  #   --prefix=/usr \
  #   --disable-fd-passing \
  #   --disable-static \
  #   --disable-gpgsm-test \
  #   --enable-languages=cpp,qt6
  # make
}

check() {
  cd gpgme-${pkgver}

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

  make check
}

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

  cd gpgme-${pkgver}

  make DESTDIR="${pkgdir}" install

  # split qgpgme
  rm -rf "${pkgdir}"$MPKG_USRPATH/lib/{cmake/QGpgme/,libqgpgme.*}
  rm -rf "${pkgdir}"$MPKG_USRPATH/lib/python*
  rm "${pkgdir}"$MPKG_USRPATH/share/info/dir
}

# package_qgpgme-qt5() {
#   pkgdesc="Qt5 bindings for GPGme"
#   ncxfah_depends=('gpgme' 'qt5-base')
#   provides=('qgpgme')
#   replaces=('qgpgme')

#   cd gpgme-${pkgver}/lang/qt

#   make DESTDIR="${pkgdir}" install
#   rm -r "${pkgdir}"/usr/include
# }

# package_qgpgme-qt6() {
#   pkgdesc="Qt6 bindings for GPGme"
#   ncxfah_depends=('gpgme' 'qt6-base')

#   cd gpgme-${pkgver}-qt6/lang/qt

#   make DESTDIR="${pkgdir}" install
#   rm -r "${pkgdir}"/usr/include
# }

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

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