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

_realname=nettle
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.10.2
pkgrel=1
pkgdesc="A low-level cryptographic library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_repository_url='https://git.lysator.liu.se/nettle/nettle'
url="https://www.lysator.liu.se/~nisse/nettle"
msys2_references=(
  "cpe: cpe:/a:nettle_project:nettle"
)
license=('spdx:GPL-2.0-or-later' 'spdx:LGPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs" "${MINGW_PACKAGE_PREFIX}-gmp")
source=("https://ftp.gnu.org/gnu/nettle/nettle-${pkgver}.tar.gz"{,.sig})
sha256sums=('fe9ff51cb1f2abb5e65a6b8c10a92da0ab5ab6eaf26e7fc2b675c45f1fb519b5'
            '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

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_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-${MSYSTEM}"
  make check
}

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