# Contributor: Runar Tenfjord < runar dot tenfjord at gmail dot com >
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=cython
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-cython")
pkgver=0.29.23
pkgrel=1
pkgdesc="C-Extensions for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://cython.org/"
license=('APACHE')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/cython/cython/archive/${pkgver}.tar.gz")
sha256sums=('b10e32255418203c612b22d3647de75eafad20d79c55123ca696c7dda32d7f98')

prepare() {
  cd "${srcdir}"
  rm -rf python-build-${CARCH}| true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
  sed -e "s|\/usr\/bin\/python|${MINGW_PREFIX}\/bin\/python|" -i python-build-${CARCH}/setup.py
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  DISTUTILS_DEBUG=1 \
  ${MINGW_PREFIX}/bin/python setup.py build
}

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

  # fix python command in files
  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
