# Maintainer: Feng Shu <tumashu@163.com>

_realname=marisa
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.2.6
pkgrel=1
pkgdesc="Static and space-efficient trie data structure library (mingw-w64)"
url="https://github.com/s-yata/marisa-trie"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "autoconf")
source=("marisa-trie-$pkgver.tar.gz::https://github.com/s-yata/marisa-trie/archive/v${pkgver}.tar.gz"
       "001-tools-makefile.patch")
sha256sums=('1063a27c789e75afa2ee6f1716cc6a5486631dcfcb7f4d56d6485d2462e566de'
            'd3ec2637462ac3331f0c6bcba9b8552bca4819321df265b3fd895547bbf75717')

prepare() {
  cd "marisa-trie-${pkgver}"
  patch -p0 -i ${srcdir}/001-tools-makefile.patch  
  autoreconf -fiv
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  case ${MINGW_CHOST} in
    i686*)
      local _conf=''      
    ;;
    x86_64*)
      local _conf='--enable-native-code'
    ;;
  esac
  
  ../marisa-trie-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    ${_conf} \
    --disable-shared

  make
}

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