pkgname=jq
pkgver=1.8.1
pkgdesc='Command-line JSON processor'
arch=('x86_64')
homepage='https://jqlang.github.io/jq/'
license=('MIT')
depends=('glibc' 'oniguruma')
makedepends=('autoconf' 'automake' 'bison' 'flex' 'python')
_patches=("jq-1.6-r3-never-bundle-oniguruma.patch")
_patch_sums=("08413ae86ca528083375cf89bdfd84c1")
sources=("${pkgname}-${pkgver}.tar.gz"
  ${_patches[@]}
)
urls=("https://github.com/jqlang/jq/release/download/${pkgname}-${pkgver/_/}.tar.gz"
  ${_patches[@]}
)
md5sums=("0df1524fe928528b3c533c69d4ddfa23"
  ${_patch_sums[@]}
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
 
  sed -e '/^dist_doc_DATA/d; s:-Wextra ::' -i Makefile.am
  printf "#!/bin/sh\\nprintf '%s'\\n\n" "${pkgver/_/}" > scripts/version

  sed -e '/vendor\/oniguruma/d' -i Makefile.am
  rm -rf "${srcdir}"/vendor/oniguruma
 
  for _patch in ${_patches[@]}; do
    patch -p1 -i ${filedir}/${_patch}
  done

  sed -i "s/\[jq_version\]/[${pkgver/_/}]/" configure.ac

  autoreconf -fi
}

src_build() {
  local conf_args=(
    --prefix=/usr
    --disable-docs
    --enable-valgrind=no
    --disable-maintainer-mode
    --disable-static
    --with-oniguruma
  )
  ./configure "${conf_args[@]}"
}

src_install() {
  make DESTDIR="${pkgdir}" prefix=/usr install
  install -Dm644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/COPYING"
}

# vim:ft=sh syn=sh et sw=2:
