# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=enchant
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.6.7
pkgrel=4
pkgdesc="Enchanting Spell Checking Library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://rrthomas.github.io/enchant/"
msys2_repository_url="https://github.com/rrthomas/enchant"
msys2_references=(
  'archlinux: enchant'
)
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-aspell"
         "${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-hunspell"
         "${MINGW_PACKAGE_PREFIX}-icu"
         "${MINGW_PACKAGE_PREFIX}-libvoikko"
         "${MINGW_PACKAGE_PREFIX}-nuspell")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "groff")
checkdepends=("${MINGW_PACKAGE_PREFIX}-unittest-cpp")
source=("https://github.com/rrthomas/enchant/releases/download/v${pkgver}/enchant-${pkgver}.tar.gz"
        001_fix_relocation.patch)
sha256sums=('a1c2e5b59acca000bbfb24810af4a1165733d407f2154786588e076c8cd57bfc'
            '2eaee551887a4dcd9b47fa3fc31db8955c51b323b89b9a6a4f096b7dca135942')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/001_fix_relocation.patch

  autoreconf -fiv
}

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

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-relocatable \
    --with-aspell \
    --with-voikko \
    --without-hspell \
    --without-zemberek

  # MSYS2_ARG_CONV_EXCL="-DENCHANT_USPELL_DICT_DIR=;-DENCHANT_MYSPELL_DICT_DIR=;-DENCHANT_ISPELL_DICT_DIR=;-DENCHANT_PREFIX_DIR=;-DENCHANT_GLOBAL_MODULE_DIR=;-DENCHANT_GLOBAL_ORDERING=;-DENCHANT_BIN_DIR="
  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  # MSYS2_ARG_CONV_EXCL="-DENCHANT_USPELL_DICT_DIR=;-DENCHANT_MYSPELL_DICT_DIR=;-DENCHANT_ISPELL_DICT_DIR=;-DENCHANT_PREFIX_DIR=;-DENCHANT_GLOBAL_MODULE_DIR=;-DENCHANT_GLOBAL_ORDERING=;-DENCHANT_BIN_DIR="
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LIB" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB"
}
