# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=usql
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.8.1
pkgrel=2
pkgdesc="SQL parser engine for C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/cybergarage/usql"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-antlr3")
checkdepends=("${MINGW_PACKAGE_PREFIX}-boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" \
             "${checkdepends[@]}")
source=("${_realname}-${pkgver}.tar.gz::https://codeload.github.com/cybergarage/usql/tar.gz/${pkgver}"
        "${_realname}-${pkgver}.patch")
sha256sums=('a4d928692bdf4e7380dde40ae09c4ed4a3cdb8ae0b3b7ab5a268d884e45d9add'
            '1714a4e70a8d5ab4cbd55da8f2241b6c2672284b7b24f94ddd0dfd98bbb3ec31')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "../${_realname}-${pkgver}.patch"
  autoreconf -fvi
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

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

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  rm ${pkgdir}${MINGW_PREFIX}/lib/*.la
}
