# Maintainer:  Matheus Catarino <matheus-catarino@hotmail.com>

pkgbase=mingw-w64-expresscpp
pkgname="${MINGW_PACKAGE_PREFIX}-expresscpp"
pkgver=0.20.0
pkgrel=4
pkgdesc='Fast, unopinionated, minimalist web framework for C++ Perfect for building REST APIs.(mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/expresscpp/expresscpp'
license=(spdx:MIT)
depends=("${MINGW_PACKAGE_PREFIX}-fmt"
         "${MINGW_PACKAGE_PREFIX}-nlohmann-json"
         "${MINGW_PACKAGE_PREFIX}-boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/expresscpp/expresscpp/archive/v${pkgver}/expresscpp-${pkgver}.tar.gz"
       "001-Windows-dll-mingw.patch"
       "002-missing-headers.patch")
sha512sums=('afe554f01d8f43253a23daea086e9b67d9593b057534929e18ead99da5e41cb826374cf8c67b3df8c25e78aa6966fdb3afa0659482f96da67cec460882aa5461'
            'a0a9bc22817835ff35c33f8dbf6311bd35d5a6a898fac1fc99427e6212ad376c314c270cf4ac8ac899f35f446ad4b361f12cd43a04b42617263518845fbd2bc7'
            '396c09ff3ef07cf60794b04a557cac926eee6c64067737fe8cae66c3808580202a8ef24f8f9ae02d7ea561113fe1daf474bceee4d099a19e860b687706d133f6')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare(){
  cd "${srcdir}"/expresscpp-${pkgver}
  
  apply_patch_with_msg \
    001-Windows-dll-mingw.patch \
    002-missing-headers.patch
}
build() {

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DBUILD_SHARED_LIBS=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -S expresscpp-${pkgver} \
      -B build-${MSYSTEM}

  ${MINGW_PREFIX}/bin/cmake --build build-${MSYSTEM}
}

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

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
