#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobextra/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgbase=jsoncpp
pkgname=('jsoncpp' 'jsoncpp-doc')
pkgver=1.9.5
pkgrel=02
pkgdesc='C++ library for interacting with JSON'
url='https://github.com/open-source-parsers/jsoncpp'
arch=('x86_64')
makedepends=('gcc-libs' 'doxygen' 'graphviz' 'python' 'meson')
options=('staticlibs')
source=(https://github.com/open-source-parsers/${pkgbase}/archive/${pkgver}/${pkgbase}-${pkgver}.tar.gz)

prepare() {
  cd ${pkgbase}-${pkgver}
  echo "${pkgver}" > version
}

build() {
  cd ${pkgbase}-${pkgver}
  echo "Building shared library..."
  arch-meson --default-library shared build
  ninja -C build

  echo "Building static library..."
  CXXFLAGS="$CXXFLAGS -ffat-lto-objects" \
  arch-meson --default-library static build-static
  ninja -C build-static

  echo "Building docs..."
  python doxybuild.py \
    --doxygen="$(command -v doxygen)" \
    --with-dot
}

check() {
  cd ${pkgbase}-${pkgver}
  ninja -C build test
  cd test
  python runjsontests.py ../build/jsontestrunner
  python rununittests.py ../build/jsoncpp_test
}

package_jsoncpp() {
  depends=('gcc-libs')
  optdepends=('jsoncpp-doc: documentation')
  provides=('libjsoncpp.so')

  cd ${pkgbase}-${pkgver}
  DESTDIR="${pkgdir}" ninja -C build install
  DESTDIR="${pkgdir}" ninja -C build-static install
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
}

package_jsoncpp-doc() {
  pkgdesc+=' (documentation)'
  optdepends=('jsoncpp')

  cd ${pkgbase}-${pkgver}
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -dm 755 "${pkgdir}/usr/share/doc/${pkgbase}"
  cp -a dist/doxygen/jsoncpp-api-html-${pkgver} "${pkgdir}/usr/share/doc/${pkgbase}/html"
}

#---- license gpg-key sha256sums ----

license=('MIT' 'custom:Public_Domain')

sha256sums=(f409856e5920c18d0c2fb85276e24ee607d2a09b5e7d5f0a371368903c275da2) #  jsoncpp-1.9.5.tar.gz

