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

_realname=libvoikko
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.2
pkgrel=1
pkgdesc="A spelling and grammar checker, hyphenator and collection of related linguistic data for Finnish language (mingw-w64)"
arch=('any')
url="http://voikko.sourceforge.net"
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-python3")
source=("http://www.puimula.org/voikko-sources/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('f13c59825f36152f388cd96f638e447744199775277f4e6bcd0b9483f0eebeca')

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  # Workaround encoding error
  export LANG=en_US.UTF-8
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --enable-hfst=false \
    --with-dictionary-path=${MINGW_PREFIX}/share/voikko

  make
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  local _py3ver=$(${MINGW_PREFIX}/bin/python3 -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

  mkdir -p "${pkgdir}${MINGW_PREFIX}/lib/python${_py3ver}/site-packages"
  cp "${srcdir}/${_realname}-${pkgver}/python/libvoikko.py" "${pkgdir}${MINGW_PREFIX}"/lib/python${_py3ver}/site-packages/libvoikko.py
}
