# Maintainer: Kentaro Hayashi <hayashi@clear-code.com>

_realname=mecab
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.996
pkgrel=4
pkgdesc="Yet another Japanese morphological analyzer (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://taku910.github.io/mecab/"
license=('GPL2' 'LGPL2' 'BSD') # licensed under triple lincense
options=('strip' 'staticlibs')
source=("http://ftp.debian.org/debian/pool/main/m/mecab/mecab_0.996.orig.tar.gz"
        "mecab-0.996.diff"
        "mecab-0.996-iconv.patch"
        "mecab-0.996-naist-jdic.patch")
install=${_realname}-${MSYSTEM}.install
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-libiconv")
sha256sums=('e073325783135b72e666145c781bb48fada583d5224fb2490fb6c1403ba69c59'
            '88a56efae57e30ffcc1b117fe152f37dd7bc419368b1d0e422d5b62245dd2d5c'
            '2dff2b3ae7faec432885a804210d55e2ed68b1af03c138e8297e0c510ef48bdf'
            '222cc3938da2e9cd79908ceeda15889f4fe78664fb61ddb83a2a18f9809c4c6b')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/mecab-0.996.diff
  patch -p1 -i ${srcdir}/mecab-0.996-iconv.patch
  patch -p1 -i ${srcdir}/mecab-0.996-naist-jdic.patch
  sed -i.orig -e '/^AC_CHECK_LIB(stdc++/d' configure.in
  mkdir -p m4
  autoreconf --force
  libtoolize --install
}

build() {
  [[ -d ${srcdir}/build-${CARCH} ]] && rm -rf ${srcdir}/build-${CARCH}
  mkdir -p ${srcdir}/build-${CARCH} && cd ${srcdir}/build-${CARCH}

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

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

  mv "${pkgdir}${MINGW_PREFIX}/etc/mecabrc" "${pkgdir}${MINGW_PREFIX}/bin/mecabrc"
  for license in AUTHORS BSD COPYING GPL LGPL; do
    install -Dm644 ${srcdir}/${_realname}-${pkgver}/${license} "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/${license}"
  done
}
