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

pkgname=gnupg
pkgver=2.4.8
pkgrel=1
pkgdesc='Complete and free implementation of the OpenPGP standard'
provides=('dirmngr' "gnupg2=${pkgver}")
url='https://gnupg.org/'
license=('GPL')
arch=('i686' 'x86_64')
msys2_changelog_url='https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git;a=blob;f=NEWS;hb=HEAD'
msys2_documentation_url='https://www.gnupg.org/documentation'
msys2_repository_url='https://git.gnupg.org/cgi-bin/gitweb.cgi?p=gnupg.git'
msys2_issue_tracker_url='https://dev.gnupg.org/maniphest'
msys2_pgp_keys_url='https://gnupg.org/signature_key.html'
msys2_references=(
  'cygwin: gnupg2'
  'cpe: cpe:/a:gnupg:gnupg'
)
makedepends=('gettext-devel'
             'libassuan-devel'
             'libbz2-devel'
             'libcurl-devel'
             'libgcrypt-devel'
             'libgnutls-devel'
             'libgpg-error-devel'
             'libiconv-devel'
             'libksba-devel'
             'libnettle-devel'
             'libnpth-devel'
             'libp11-kit-devel'
             'libreadline-devel'
             'libsqlite-devel'
             'libtasn1-devel'
             'libunistring-devel'
             'gcc'
             'nettle'
             'tar'
             'autotools'
             'zlib-devel')
optdepends=('curl: gpg2keys_curl')
depends=('bzip2'
         'libassuan'
         'libbz2'
         'libcurl'
         'libgcrypt'
         'libgpg-error'
         'libgnutls'
         'libiconv'
         'libintl'
         'libksba'
         'libnpth'
         'libreadline'
         'libsqlite'
         'nettle'
         'pinentry'
         'zlib'
        )
source=("https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2"{,.sig}
        '0001-gnupg-2.2.8-msys2.patch'
        'gnupg-2.4-avoid_beta_warning.patch'
        'gnupg-2.4-drop_import_clean.patch'
        'gnupg-2.4-revert_default_rfc4880bis.patch')
sha256sums=('b58c80d79b04d3243ff49c1c3fc6b5f83138eb3784689563bcdd060595318616'
            'SKIP'
            '902563c91c72ed9222343de3482f4ca7b141775235625af5ad790f3d86419370'
            '243c3a79295519b3931f9d846cf2af5caa064a78de812ee336dc786c1567b4d0'
            '6ade15b536c50a88efc2d9dc958433b0ccfaf2908025b7672753e6bfce51c3c6'
            'ef2267eecd9eb59bbbbdb97d55cbfe10236b4979a125c6683a840830bc202905')
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)
)
install=${pkgname}.install

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

  # MSYS2 patches
  patch -p1 -i ${srcdir}/0001-gnupg-2.2.8-msys2.patch

  # Arch Linux patches
  patch -p1 -i ${srcdir}/gnupg-2.4-avoid_beta_warning.patch
  patch -p1 -i ${srcdir}/gnupg-2.4-drop_import_clean.patch
  patch -p1 -i ${srcdir}/gnupg-2.4-revert_default_rfc4880bis.patch

  ./autogen.sh --force
}

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

  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --sbindir=/usr/bin \
    --libexecdir=/usr/lib/gnupg \
    --disable-libdns \
    --enable-maintainer-mode

  make
}

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

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
}
