# Maintainer: Gore Liu <goreliu@126.com>

_realname=jq
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.6
pkgrel=4
pkgdesc="Command-line JSON processor (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://stedolan.github.io/jq/'
license=('MIT')
makedepends=("autoconf" "automake" "bison" "flex")
depends=("${MINGW_PACKAGE_PREFIX}-oniguruma"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
source=("https://github.com/stedolan/${_realname}/releases/download/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.gz"
        no-undefined.patch)
sha256sums=('5de8c8e29aaa3fb9cc6b47bb27299f271354ebb72514e3accadc7d38b5bbaa72'
            'ed3f9824901a49d146b74c2a0a212595522dfa0fa5da32200c8384a779bbfa78')
noextract=(${_realname}-${pkgver}.tar.gz)

prepare() {
  [[ -d ${srcdir}/${_realname}-${pkgver} ]] && rm -rf ${srcdir}/${_realname}-${pkgver}
  tar -xzvf ${srcdir}/${_realname}-${pkgver}.tar.gz -C ${srcdir} || true

  cd "${srcdir}"/${_realname}-${pkgver}
  cp README.md README
  patch -p1 -i ${srcdir}/no-undefined.patch
  
  autoreconf -fiv
}

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} \
    --enable-static \
    --enable-shared \
    --disable-docs

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check || true
}

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