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

_realname=nettle
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.7.3
pkgrel=1
pkgdesc="A low-level cryptographic library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://www.lysator.liu.se/~nisse/nettle"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-gmp")
options=('staticlibs' 'strip')
source=("https://ftp.gnu.org/gnu/nettle/nettle-${pkgver}.tar.gz"{,.sig})
sha256sums=('661f5eb03f048a3b924c3a8ad2515d4068e40f67e774e8a26827658007e3bcf0'
            'SKIP')
validpgpkeys=('343C2FF0FBEE5EC2EDBEF399F3599FF828C67298') #Niels Möller <nisse@lysator.liu.se>

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

build() {
  local -a extra_config
  case "${CARCH}" in
    i?86|x86_64)
      ;;
    *)
      extra_config+=(--disable-assembler)
  esac

  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST} \
      "${extra_config[@]}" \
      --enable-shared \
      --enable-public-key

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

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