# Contributor: Tobias Smolka <tsmolka@gmail.com>

_realname=yajl
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.1.0
pkgrel=1
pkgdesc='Yet Another JSON Library (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://lloyd.github.io/yajl/'
license=('ISC')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/lloyd/$_realname/archive/${pkgver}.tar.gz"
         '01-fix-compiler.patch'
         '02-fix-tests.patch')
sha256sums=('3fb73364a5a30efe615046d07e6db9d09fd2b41c763c5f7d3bfb121cd5c5ac5a'
            'fa629191df14f32d54cc03999e9913ed2afa83c032249f9399ee93d87380b49a'
            '2345c74a3a005f4bb5a9ff49bc0700d41672b742eea0775a3637f164118f9195')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i "${srcdir}/01-fix-compiler.patch"
  patch -p1 -i "${srcdir}/02-fix-tests.patch"
}
build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  make
}
check() {
  cd "${srcdir}/build-${CARCH}"

  make test
  PATH="$PATH:${srcdir}/build-${CARCH}/${_realname}-${pkgver}/lib" make test-api
}
package() {
  cd "${srcdir}/build-${CARCH}"
  
  make DESTDIR=${pkgdir} install  
  mv ${pkgdir}${MINGW_PREFIX}/lib/*.dll ${pkgdir}${MINGW_PREFIX}/bin/
  
  install -Dm644 "../${_realname}-${pkgver}/COPYING" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
