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

_realname=mecab-naist-jdic
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.6.3b_20111013
pkgrel=2
pkgdesc="NAIST Japanese Dictionary (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://osdn.net/projects/naist-jdic/"
license=('BSD')
source=("https://ja.osdn.net/projects/naist-jdic/downloads/53500/mecab-naist-jdic-${pkgver//_/-}.tar.gz"
        01-prefix.patch)
depends=("${MINGW_PACKAGE_PREFIX}-mecab")
sha256sums=('cb37700dc9a77b953f2bf3b15b49cfecd67848530a2cf8abcb09b594ca5628cc'
            '997894bac71673d85d43efc88b994e7cc7983ed00fc8398d70bca01134229e77')

prepare() {
  cd "${_realname}-${pkgver//_/-}"
  patch -p1 -i ${srcdir}/01-prefix.patch
  
  autoreconf -fiv
}

build() {
  cd "${_realname}-${pkgver//_/-}"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-mecab-config=${MINGW_PREFIX}/bin/mecab-config \
    --with-dicdir=${MINGW_PREFIX}/lib/mecab/dic/naist-jdic \
    --with-charset=utf-8

  make
}

package() {
  cd "${_realname}-${pkgver//_/-}"

  # First make install fails, retry again.
  make DESTDIR="${pkgdir}" install || true
  make DESTDIR="${pkgdir}" install

  for license in AUTHORS COPYING; do
    install -Dm644 ${srcdir}/${_realname}-${pkgver//_/-}/${license} "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/${license}"
  done
}
