# Maintainer: Martell Malone <martellmalone@gmail.com>

pkgbase="jsoncpp"
pkgname=("${pkgbase}" "${pkgbase}-devel")
pkgver=1.9.6
pkgrel=3
pkgdesc="A C++ library for interacting with JSON"
arch=('i686' 'x86_64')
url="https://github.com/open-source-parsers/jsoncpp"
msys2_references=(
  "anitya: 7483"
  "cpe: cpe:2.3:a:jsoncpp_project:jsoncpp"
)
license=('MIT')
depends=("gcc-libs")
makedepends=("gcc"
             "meson"
             "pkgconf"
             "ninja")
source=(${pkgname}-${pkgver}.tar.gz::"https://github.com/open-source-parsers/jsoncpp/archive/${pkgver}.tar.gz")
sha256sums=('f93b6dd7ce796b13d02c108bc9f79812245a82e577581c4c9aabe57075c90ea2')

build() {
  [[ -d "${srcdir}/build-${CARCH}-static" ]] && rm -rf "${srcdir}/build-${CARCH}-static"
  mkdir -p "${srcdir}/build-${CARCH}-static" && cd "${srcdir}/build-${CARCH}-static"

  meson setup \
    --prefix=/usr \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --default-library=static \
    --buildtype=plain \
    ../${pkgbase}-${pkgver}

  meson compile
  DESTDIR=${srcdir}/dest meson install

  [[ -d "${srcdir}/build-${CARCH}-shared" ]] && rm -rf "${srcdir}/build-${CARCH}-shared"
  mkdir -p "${srcdir}/build-${CARCH}-shared" && cd "${srcdir}/build-${CARCH}-shared"

  meson setup \
    --prefix=/usr \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    --default-library=shared \
    --buildtype=plain \
    ../${pkgbase}-${pkgver}

  meson compile
  DESTDIR=${srcdir}/dest meson install
}

package_jsoncpp() {
  groups=("libraries")
  cd "${srcdir}/dest"
  mkdir -p ${pkgdir}/usr/bin
  cp usr/bin/*.dll ${pkgdir}/usr/bin/
}

package_jsoncpp-devel() {
  pkgdesc="Development headers and library for JsonCpp"
  depends=("$pkgbase=$pkgver")
  options=('staticlibs')
  groups=("development")
  cd "${srcdir}/dest"
  mkdir -p ${pkgdir}/usr/lib
  mkdir -p ${pkgdir}/usr/include
  cp -rf usr/lib/* ${pkgdir}/usr/lib
  cp -rf usr/include/* ${pkgdir}/usr/include
}
