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

pkgbase=jansson
pkgname=("${pkgbase}" "${pkgbase}-devel")
pkgver=2.13.1
pkgrel=1
pkgdesc='C library for encoding, decoding and manipulating JSON data'
arch=('i686' 'x86_64')
url='http://www.digip.org/jansson/'
license=('MIT')
options=('staticlibs')
source=("http://www.digip.org/${pkgname}/releases/${pkgname}-${pkgver}.tar.bz2"
        "jansson-2.12-msys2.patch")
sha256sums=('ee90a0f879d2b7b7159124ff22b937a2a9a8c36d3bb65d1da7dd3f04370a10bd'
            '89d41a3d99453abb89ce51c6e69199de905d94cd82fc415f2019c78caaeddda1')


# 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
  apply_patch_with_msg jansson-2.12-msys2.patch
  autoreconf -fiv
}

build() {
  cd "$srcdir/$pkgname-$pkgver"
  ./configure \
      --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:
