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

_realname=libvoikko
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.3.1
pkgrel=1
pkgdesc="A spelling and grammar checker, hyphenator and collection of related linguistic data for Finnish language (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://voikko.sourceforge.net"
license=('GPL2')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libssp")
makedepends=("${MINGW_PACKAGE_PREFIX}-python")
source=("https://www.puimula.org/voikko-sources/${_realname}/${_realname}-${pkgver}.tar.gz"{,.asc})
sha256sums=('368240d4cfa472c2e2c43dc04b63e6464a3e6d282045848f420d0f7a6eb09a13'
            'SKIP')
validpgpkeys=('AC5D65F10C8596D7E2DAE2633D309B604AE3942E') # Harri Pitkänen <hatapitk@iki.fi>

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

  sed "s/-Werror//g" -i configure.ac
  autoreconf -fiv
}

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"

  LDFLAGS+=" -fstack-protector" \
  ../${_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 _pyver=$(${MINGW_PREFIX}/bin/python.exe -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")

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