# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=yaml-cpp0.3
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.0
pkgrel=2
pkgdesc="A YAML parser and emitter in C++ matching the YAML 1.2 spec (mingw-w64) - old version"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/jbeder/yaml-cpp"
license=("MIT")
provides=("${MINGW_PACKAGE_PREFIX}-yaml-cpp")
conflicts=("${MINGW_PACKAGE_PREFIX}-yaml-cpp")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=(yaml-cpp-${pkgver}.tar.gz::https://github.com/jbeder/yaml-cpp/archive/release-${pkgver}.tar.gz
        mingw-install-pkgconfig.patch)
sha256sums=('ab8d0e07aa14f10224ed6682065569761f363ec44bc36fcdb2946f6d38fe5a89'
            '858915b03a300145a466bd68d3f95ff80738f0821f9bba5563b4fadb2dc4fffb')

prepare() {
  cd ${srcdir}/yaml-cpp-release-${pkgver}
  patch -p1 -i ${srcdir}/mingw-install-pkgconfig.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=OFF \
    ../yaml-cpp-release-${pkgver}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
  install -Dm644 ${srcdir}/yaml-cpp-release-${pkgver}/license.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
