# Maintainer: Yuui Tanabe <yuuitanabe@163.com>

_realname=pinentry
pkgbase=mingw-w64-${_realname}
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgver=1.3.2
pkgrel=1
pkgdesc='Collection of simple PIN or passphrase entry dialogs which utilize the Assuan protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.gnupg.org/software/pinentry/index.html"
msys2_references=(
  'anitya: 3643'
  'gentoo: app-crypt/pinentry'
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libsecret"
         "${MINGW_PACKAGE_PREFIX}-libassuan"
         $([[ ${CARCH} == i686 ]] || echo "${MINGW_PACKAGE_PREFIX}-qt6-base"))
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://www.gnupg.org/ftp/gcrypt/pinentry/pinentry-${pkgver}.tar.bz2"{,.sig}
        "0003-m4-qt6libexecdir-unix-path.patch")
sha256sums=('8e986ed88561b4da6e9efe0c54fa4ca8923035c99264df0b0464497c5fb94e9e'
            'SKIP'
            '6063e52c1eb1e477b06e5537c47bfde6c9c3f323337e5e18219001256c2fb0bb')
validpgpkeys=('D8692123C4065DEA5E0F3AB5249B39D24F25E3B6' # Werner Koch (dist sig)
              '6DAA6E64A76D2840571B4902528897B826403ADA' # Werner Koch (dist signing 2020)
              'AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD') # Niibe Yutaka (GnuPG Release Key)

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0003-m4-qt6libexecdir-unix-path.patch"
  autoreconf -fiv
}

build() {
  local -a _extra_config
  if [[ ${CARCH} != i686 ]]; then
    _extra_config+=("--enable-pinentry-qt")
  fi
  _extra_config+=("--disable-pinentry-qt5")

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --disable-pinentry-tty \
    --disable-pinentry-curses \
    --disable-fallback-curses \
    --disable-pinentry-emacs \
    --disable-pinentry-gtk2 \
    --disable-pinentry-gnome3 \
    --enable-libsecret \
    "${_extra_config[@]}"

  # For clang because VERSION file is assumed as header file
  # Required for autotools only, change the file after configure
  mv "${srcdir}/${_realname}-${pkgver}"/{VERSION,version.txt}

  make
}

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