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

_realname=libsodium
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.20
pkgrel=1
pkgdesc="P(ortable|ackageable) NaCl-based crypto library (mingw-w64)"
arch=(any)
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/jedisct1/libsodium"
license=('spdx:ISC')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://download.libsodium.org/libsodium/releases/${_realname}-${pkgver}.tar.gz")
sha256sums=('ebb65ef6ca439333c2bb41a0c1990587288da07f6c7fd07cb3a18cc18d30ce19')

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

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --enable-static

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make -k check || true
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE

  # Remove unused DEF file
  rm "${pkgdir}${MINGW_PREFIX}"/bin/*.def
}
