# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >
# Contributor: Naveen M K <naveen521kk@gmail.com> @naveen521kk on Github

_realname=scipy
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.6.3
pkgrel=1
pkgdesc="SciPy is open-source software for mathematics, science, and engineering (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.scipy.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libgfortran"
         "${MINGW_PACKAGE_PREFIX}-openblas"
         "${MINGW_PACKAGE_PREFIX}-python-numpy")
optdepends=(
        "${MINGW_PACKAGE_PREFIX}-python-nose: testsuite"
        "${MINGW_PACKAGE_PREFIX}-python-pillow: for image saving module"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc-fortran"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-pybind11"
             "${MINGW_PACKAGE_PREFIX}-cython")
source=(
  "${_realname}-${pkgver}.tar.gz::https://pypi.python.org/packages/source/${_realname:0:1}/${_realname}/${_realname}-${pkgver}.tar.gz"
)
sha256sums=('a75b014d3294fce26852a9d04ea27b5671d86736beb34acdfc05859246260707')

prepare() {
  rm -rf python-build-${CARCH} | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd ${srcdir}/python-build-${CARCH}
  # we do not have the C11 header threads.h (build error in vodemodule.c)
  CFLAGS+=" -D__STDC_NO_THREADS__=1"
  CXXFLAGS+=" -D__STDC_NO_THREADS__=1"
  # the correct flag here is LDSHARED not LDFLAGS.
  LDFLAGS="${LDFLAGS} -Wall -shared"
  result="fail"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py config_fc --fcompiler=gnu95 build
}

package() {
  cd python-build-${CARCH}
  LDFLAGS="${LDFLAGS} -Wall -shared"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py config_fc --fcompiler=gnu95 install \
    --prefix=${MINGW_PREFIX} --root=${pkgdir} --optimize=1  --skip-build

  install -Dm644 LICENSE.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
