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

_realname=cereal
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=1
pkgdesc="A C++11 library for serialization (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://uscilab.github.io/cereal/"
license=('New BSD license')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
depends=("${MINGW_PACKAGE_PREFIX}-boost")
checkdepends=("${MINGW_PACKAGE_PREFIX}-gflags")
source=("${_realname}-${pkgver}.tar.gz::https://github.com/USCiLab/cereal/archive/v${pkgver}.tar.gz"
        "${_realname}-1.2.2.patch")
sha256sums=('329ea3e3130b026c03a4acc50e168e7daff4e6e661bc6a7dfec0d77b570851d5'
            '3a7f7a6e6d8e092c5ffb7b0342d0bfa8675a57985dc1c9e5a4209ce434156767')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/${_realname}-1.2.2.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  CFLAGS+=" -Wno-unused-variable"
  CXXFLAGS+=" -Wno-unused-variable"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE="Release" \
    "../${_realname}-${pkgver}"

  make
}

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

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

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE ${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
