# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=snowball
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-libstemmer")
pkgver=2.2.0
pkgrel=1
pkgdesc="String processing language for creating stemming algorithms (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://snowballstem.org/'
license=('spdx:BSD-3-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://github.com/snowballstem/snowball/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('425cdb5fba13a01db59a1713780f0662e984204f402d3dae1525bda9e6d30f1a')

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

  make
}

package_snowball() {
  cd "${srcdir}/build-${MSYSTEM}"

  install -Dt "${pkgdir}${MINGW_PREFIX}/bin" snowball.exe stemwords.exe

  install -Dt "${pkgdir}${MINGW_PREFIX}/share/licenses/$_realname" -m644 COPYING
}

package_libstemmer() {
  pkgdesc="Stemming library supporting several languages (mingw-w64)"

  cd "${srcdir}/build-${MSYSTEM}"

  install -Dt "${pkgdir}${MINGW_PREFIX}/include" -m644 include/libstemmer.h
  install -Dm644 libstemmer.a "${pkgdir}${MINGW_PREFIX}/lib/libstemmer.a"

  install -Dt "${pkgdir}${MINGW_PREFIX}/share/licenses/libstemmer" -m644 COPYING
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
