# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=inja
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.5.0
pkgrel=1
pkgdesc='A Template Engine for Modern C++ (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/pantor/inja"
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-nlohmann-json")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen")
options=('!strip' '!buildflags')
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a5f0266673c59028eab6ceeddd8b862c70abfeb32fb7a5387c16bf46f3269ab2')

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DINJA_USE_EMBEDDED_JSON=OFF \
    ../${_realname}-${pkgver}

  cmake --build .

  cd "${srcdir}/${_realname}-${pkgver}/doc"

  ${MINGW_PREFIX}/bin/doxygen Doxyfile 
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/ctest . || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  DESTDIR="${pkgdir}" cmake --install .

  cd "${srcdir}/${_realname}-${pkgver}/doc"
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  cp -a html "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}/html"

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