# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=jansson
pkgname=("${pkgbase}" "${pkgbase}-devel")
pkgver=2.14.1
pkgrel=1
pkgdesc='C library for encoding, decoding and manipulating JSON data'
arch=('i686' 'x86_64')
url='https://www.digip.org/jansson/'
msys2_repository_url="https://github.com/akheron/jansson"
msys2_references=(
  "cpe: cpe:/a:jansson_project:jansson"
)
license=('MIT')
makedepends=('autotools' 'gcc')
options=('staticlibs')
source=("https://github.com/akheron/jansson/releases/download/v$pkgver/$pkgname-$pkgver.tar.gz"{,.asc})
sha256sums=('2521cd51a9641d7a4e457f7215a4cd5bb176f690bc11715ddeec483e85d9e2b3'
            'SKIP')
validpgpkeys=('B5D6953E6D5059ED7ADA0F2FD3657D24D058434C') # Petri Lehtinen <petri@digip.org>

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

prepare() {
  cd $srcdir/$pkgname-$pkgver

  autoreconf -fiv
}

build() {
  cd "$srcdir/$pkgname-$pkgver"

  ./configure \
      --build=${CHOST} \
      --prefix=/usr \
      --enable-static=yes \
      --enable-shared=yes

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "$srcdir/$pkgname-$pkgver"

  make check
}


package_jansson() {
  pkgdesc='C library for encoding, decoding and manipulating JSON data (runtime)'
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  install -Dm644 "$srcdir/$pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_jansson-devel() {
  pkgdesc="jansson headers and libraries"
  depends=("jansson=${pkgver}")
  options=('staticlibs')
  groups=('development')

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}

# vim:set ts=2 sw=2 et:
