# Maintainer: Andrew Sun <adsun701@gmail.com>

_pyname=PyStemmer
_realname=pystemmer
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=2.0.0.1
pkgrel=1
pkgdesc="Snowball stemming algorithms, for information retrieval (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://snowball.tartarus.org"
license=('MIT' 'BSD')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-cython"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("${_realname}-${pkgver}.tar.gz"::"https://pypi.io/packages/source/P/PyStemmer/${_pyname}-${pkgver}.tar.gz")
sha256sums=('57d1e353b11c5f90566efec7037deaa0e411b1df1e4e5522ce97d7be34b49478')

prepare() {  
  cd "${srcdir}/${_pyname}-${pkgver}"

  # Force cython rebuild
  rm "src/Stemmer.c"

  cd ${srcdir}
  rm -rf python-build-${CARCH} | true
  cp -r "${_pyname}-${pkgver}" "python-build-${CARCH}"
}
  
build() {
  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
  
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
