# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=grantlee
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.3.1
pkgrel=1
pkgdesc="Libraries for text templating with Qt (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/steveire/grantlee"
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-qt6-declarative")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-graphviz")
source=("https://github.com/steveire/grantlee/releases/download/v${pkgver}/grantlee-${pkgver}.tar.gz"{,.asc})
sha256sums=('ba288ae9ed37ec0c3622ceb40ae1f7e1e6b2ea89216ad8587f0863d64be24f06'
            'SKIP')
validpgpkeys=(FCA530E51EE4331C2DF16637D264C7B1D02D6509) # Stephen Kelly <steveire@gmail.com>

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #

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

  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake.exe \
      -G'Ninja' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${_extra_config[@]}" \
      -DGRANTLEE_BUILD_WITH_QT6=ON \
      -DBUILD_SHARED_LIBS=ON \
      -DBUILD_TESTS=OFF \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
  ${MINGW_PREFIX}/bin/cmake --build . --target docs
}

#check() {
#  cd "${srcdir}"/build-${MSYSTEM}
#  ${MINGW_PREFIX}/bin/cmake -DBUILD_TESTS=ON ../${_realname}-${pkgver}
#  ${MINGW_PREFIX}/bin/cmake --build .
#  ${MINGW_PREFIX}/bin/ctest
#}

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

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share/doc/${_realname}/
  install -Dm066 apidox/* "${pkgdir}"${MINGW_PREFIX}/share/doc/${_realname}/

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.LIB "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LIB
}
