# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=numba
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.53.1
pkgrel=1
pkgdesc='NumPy aware dynamic Python compiler using LLVM (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://numba.pydata.org/"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python-llvmlite>=0.34.0" "${MINGW_PACKAGE_PREFIX}-python-numpy>=1.15")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cython")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-scipy>=1.0.0")
options=('!emptydirs')
source=(numba-$pkgver.tar.gz::"https://github.com/numba/numba/archive/$pkgver.tar.gz"
       "omppool.patch"
	   "setup.patch")
sha256sums=('c0d5ef90eb959f919cf134512259459430c58d566ff2124535572648b3b3931d'
            '48c7004ccf353278d8c822e5482183e73bd7eb8b48235c48175213ae2232ee24'
            'd60de705fb4a4517ab43e371f1da9b2b660387760a7db9b0526f2f5ab84d4693')

prepare() {  
  cd "$srcdir"
  rm -rf python-build-${CARCH} | true
  pushd "${_realname}-${pkgver}"
	patch -p1 -i "${srcdir}/omppool.patch"
	patch -p1 -i "${srcdir}/setup.patch"
	sed -i "s,_MSC_VER,_WIN32," numba/np/ufunc/workqueue.c
  popd
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"  
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  local _PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/numba"
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/pycc"

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