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

pkgname=("aspell" "aspell-devel")
pkgver=0.60.8.1
pkgrel=1
pkgdesc="A Free and Open Source spell checker (libraries)"
arch=('i686' 'x86_64')
url="http://aspell.net/"
msys2_repository_url="https://github.com/GNUAspell/aspell"
msys2_references=(
  "cpe: cpe:/a:gnu:aspell"
)
license=('LGPL')
groups=('libraries')
makedepends=('gcc' 'gettext-devel' 'libiconv-devel' 'ncurses-devel' 'autotools')
options=()
source=("https://ftp.gnu.org/gnu/aspell/${pkgname}-${pkgver}.tar.gz"
        "aspell-noundefined.patch"
        "aspell-so2dll.patch"
        "aspell-fileno.patch")
sha256sums=('d6da12b34d42d457fa604e435ad484a74b2effcd120ff40acd6bb3fb2887d21b'
            '35c0a786f580302052bab7569007735436dad9ceb551910205651bc2ad6bcb85'
            '9b9e4300d35a92f029c098da7001235d1dd6aeb03a854591afd84606b5cd257b'
            '8054609ba63038c7f488782a1f80ed31ba1fe18ded842707702ad08793903c7b')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p1 -i ${srcdir}/aspell-noundefined.patch
  patch -p1 -i ${srcdir}/aspell-so2dll.patch
  patch -p1 -i ${srcdir}/aspell-fileno.patch

  autoreconf -ivf
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure -C \
    --prefix=/usr \
    --sysconfdir=/etc \
    --build=${CHOST} \
    --enable-static

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package_aspell() {
  depends=("gcc-libs" "gettext" "libiconv" "ncurses")

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/

  mkdir -p ${pkgdir}/usr/lib/aspell-0.60
  cp -rf ${srcdir}/dest/usr/lib/aspell-0.60 ${pkgdir}/usr/lib/

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_aspell-devel() {
  pkgdesc="Aspell headers and libraries (development)"
  groups=('development')
  depends=("aspell=${pkgver}" "gettext-devel" "libiconv-devel" "ncurses-devel")

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -f ${srcdir}/dest/usr/lib/*.a ${pkgdir}/usr/lib
}
