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

_realname=jq
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.8.1
pkgrel=1
pkgdesc="Command-line JSON processor (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://jqlang.github.io/jq/'
msys2_repository_url="https://github.com/jqlang/jq"
msys2_references=(
  "cpe: cpe:/a:jq_project:jq"
)
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-oniguruma"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
source=("https://github.com/jqlang/${_realname}/releases/download/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('2be64e7129cecb11d5906290eba10af694fb9e3e7f9fc208a311dc33ca837eb0')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  # avoid it asking git for the version
  echo "echo ${pkgver}" > scripts/version
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_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-${MSYSTEM}
  make check
}

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