# Maintainer: Dirk Stolle

_realname=passagemath-ntl
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=10.6.40
pkgrel=1
pkgdesc="passagemath: Computational Number Theory with NTL (mingw-w64)"
arch=('any')
# Builds for clang64 and clangarm64 currently have problems with ntl, so it's
# only mingw64 and ucrt64 for now.
mingw_arch=('mingw64' 'ucrt64')
url='https://github.com/passagemath/passagemath'
msys2_references=(
  'purl: pkg:pypi/passagemath-ntl'
)
license=('spdx:GPL-2.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-ntl"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-cysignals"
         "${MINGW_PACKAGE_PREFIX}-python-memory-allocator"
         "${MINGW_PACKAGE_PREFIX}-python-passagemath-categories"
         "${MINGW_PACKAGE_PREFIX}-python-passagemath-environment")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-m4ri"
             "${MINGW_PACKAGE_PREFIX}-mpfi"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-passagemath-modules"
             "${MINGW_PACKAGE_PREFIX}-python-passagemath-setup"
             "${MINGW_PACKAGE_PREFIX}-python-pkgconfig"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname/-/_}-${pkgver}.tar.gz")
sha256sums=('62e33b8b272877c2cfe5d613da6b4f2bbf202e72376f5f1f672781fc16091c69')

build() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  # Add -fpermissive to compiler flags, because otherwise the build will fail.
  # Reported upstream: <https://github.com/passagemath/passagemath/issues/1862>
  # Recommendation there was just to go with the -fpermissive flag.
  CFLAGS+=" -fpermissive"
  CXXFLAGS="$CFLAGS"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl
}
