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

_realname=inja
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.4.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"
        '0001-inja-3.3.0-amalgamate.patch'
        '0002-inja-3.3.0-test-include.patch')
sha256sums=('7155f944553ca6064b26e88e6cae8b71f8be764832c9c7c6d5998e0d5fd60c55'
            '15685a53746e94624bd1531c4bd9936117c2fceacc7f515c8df18618b420508f'
            'd41c35c11a13c6cfb479e027656f035f937d7b758aa5bd93bc83307b30701a23')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}"/0001-inja-3.3.0-amalgamate.patch
  patch -p1 -i "${srcdir}"/0002-inja-3.3.0-test-include.patch
}

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 \
    -DINJA_AMALGAMATE=OFF \
    -DBUILD_BENCHMARK=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"
}
