# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=aspell
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.60.8.1
pkgrel=6
pkgdesc="A spell checker designed to eventually replace Ispell (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="http://aspell.net/"
msys2_references=(
  "cpe: cpe:/a:gnu:aspell"
)
license=("LGPL")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools")
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"{,.sig}
        0001-use-namespace.mingw.patch
        0002-printf.mingw.patch
        0003-no-undefined-on.mingw.patch
        0004-reloc.mingw.patch
        0005-w32-home.all.patch
        0006-abort.mingw.patch
        0007-fix-including-langinfo.patch
        aspell-0.60.8.1-gcc-15-fix.patch)
sha256sums=('d6da12b34d42d457fa604e435ad484a74b2effcd120ff40acd6bb3fb2887d21b'
            'SKIP'
            '903c798d1afa40b4e36ec0d4c1b82a967d217507f03742c3c480568cc527e429'
            '9d2640cd250d8a6f5ce8d59080b13edd5ecfa53c0eb1628f22cc93a8c2397109'
            '88ec0327160f362eb896158e443485cd549ede3aaa1d51ca642cf22ed2feee19'
            'e08e48c75af27ba63a4ea15f5cdee15d6f5f018e926cc5d5082ed96cc09070e2'
            '8a937dd625aefb8ece3553eb5b1aca888856298d01ae9d8da14c3d574d52871d'
            'd5e69f1c352e4d01d23297c06269f5430e584cf2535329e9c934d2209a43cc0d'
            '8ff2cfc11963d0738c435a27c42e2f28dabf473270310f98ef6252a9707d4501'
            '3efbb132327efd5bb9d34ea9ee3148e67e355e3c2c2e86fe04a4c1dd2d7e1ce2')
validpgpkeys=('31A768B0808E4BA619B48F81B6D9D0CC38B327D7') # Kevin Atkinson <kevina@gnu.org>

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0001-use-namespace.mingw.patch
  patch -p1 -i "${srcdir}"/0002-printf.mingw.patch
  patch -p1 -i "${srcdir}"/0003-no-undefined-on.mingw.patch
  patch -p1 -i "${srcdir}"/0004-reloc.mingw.patch
  patch -p1 -i "${srcdir}"/0005-w32-home.all.patch
  patch -p1 -i "${srcdir}"/0006-abort.mingw.patch
  patch -p1 -i "${srcdir}"/0007-fix-including-langinfo.patch
  patch -p1 -i "${srcdir}"/aspell-0.60.8.1-gcc-15-fix.patch

  autoreconf -fi
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -rf "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  CPPFLAGS+=" -DENABLE_W32_PREFIX=1"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --disable-curses

  make
}

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