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

_realname=yaml-cpp
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.6.3
pkgrel=4
pkgdesc="A YAML parser and emitter in C++ matching the YAML 1.2 spec (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/jbeder/yaml-cpp"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/jbeder/yaml-cpp/archive/${_realname}-${pkgver}.tar.gz
        mingw-install-pkgconfig.patch
        010-no-fPIC.patch)
sha256sums=('77ea1b90b3718aa0c324207cb29418f5bced2354c2e483a9523d98c3460af1ed'
            '872d28cfb8cfc0280de846e80359c1ae3987afc8095b653df1a4e18daa7dcf72'
            '597da9ea350a4c13e07ce3f0fd5f66b40209610644762ee55b1435103375ae24')

prepare() {
  cd ${srcdir}/${_realname}-${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/mingw-install-pkgconfig.patch
  patch -p1 -i ${srcdir}/010-no-fPIC.patch
}

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
    -DYAML_BUILD_SHARED_LIBS=ON \
    -DYAML_CPP_BUILD_TESTS=OFF \
    ../${_realname}-${_realname}-${pkgver}
  make

  msg2 "Build static library"
  [[ -d "build-${MINGW_CHOST}-static" ]] && rm -rf "build-${MINGW_CHOST}-static"
  mkdir -p ${srcdir}/build-${MINGW_CHOST}-static && cd ${srcdir}/build-${MINGW_CHOST}-static

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DYAML_BUILD_SHARED_LIBS=OFF \
    -DYAML_CPP_BUILD_TESTS=OFF \
    ../${_realname}-${_realname}-${pkgver}
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}-static"
  make DESTDIR=${pkgdir} install
  
  cd "${srcdir}/build-${MINGW_CHOST}-shared"
  make DESTDIR=${pkgdir} install
  
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
