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

_realname=libvoikko
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.3.3
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' 'clangarm64')
msys2_repository_url='https://github.com/voikko/corevoikko'
url="https://voikko.puimula.org/"
license=('spdx:MPL-1.1 OR GPL-2.0-or-later OR LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://www.puimula.org/voikko-sources/${_realname}/${_realname}-${pkgver}.tar.gz"{,.asc})
sha256sums=('d1162965c61de44f72162fd87ec1394bd4f90f87bc8152d13fe4ae692fdc73fa'
            'SKIP')
validpgpkeys=('AC5D65F10C8596D7E2DAE2633D309B604AE3942E') # Harri Pitkänen <hatapitk@iki.fi>

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

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

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  # 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-${MSYSTEM}
  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

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE.CORE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.CORE"
}
