# Maintainer: Diego Sogari <diego.sogari@gmail.com>

_realname=cjose
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.6.1
pkgrel=1
pkgdesc="C library implementing the Javascript Object Signing and Encryption (JOSE) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/cisco/cjose"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-check")
depends=("${MINGW_PACKAGE_PREFIX}-jansson"
         "${MINGW_PACKAGE_PREFIX}-openssl")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/cisco/cjose/archive/${pkgver}.tar.gz"
        "001-cjose-0.6.1-fix-mingw-build.patch")
sha256sums=('208eaa0fa616b44a71d8aa155c40b14c7c9d0fa2bb91d1408824520d2fc1b4dd'
            'beddabd564eb057f6a99c898e27ad048d245ac7fc9f3e43ff0f4fa53d470d100')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  cd "${srcdir}"
  rm -rf "${_realname}-${pkgver}"
  tar -xzvf "${_realname}-${pkgver}.tar.gz" --exclude lib

  cd "${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-cjose-0.6.1-fix-mingw-build.patch"
  autoreconf --force --install
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-openssl=${MINGW_PREFIX} \
    --with-jansson=${MINGW_PREFIX}
  make
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make test
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
}
