# Maintainer: Peter Budai <peterbudai at hotmail dot com>

_realname=pugixml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.11.4
pkgrel=1
pkgdesc="Light-weight, simple and fast XML parser for C++ with XPath support (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://pugixml.org/"
license=("MIT")
depends=()
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake")
source=(https://github.com/zeux/pugixml/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('8ddf57b65fb860416979a3f0640c2ad45ddddbbafa82508ef0a0af3ce7061716')

build() {
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

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

  msg "Build shared library"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DBUILD_SHARED_LIBS=ON \
    ../${_realname}-${pkgver}

  make

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

  msg "Build static library"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ${extra_config} \
    -DBUILD_SHARED_LIBS=OFF \
    ../${_realname}-${pkgver}

  make
}

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

  msg "Install shared library"
  cd "${srcdir}/build-shared-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
