# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=range-v3
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.11.0
pkgrel=1
pkgdesc="Experimental range library for C++11/14/17 (mingw-w64)."
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/ericniebler/range-v3"
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
options=('strip' '!debug' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz::${url}/archive/${pkgver}.tar.gz")
sha512sums=('9d6cdcbc1e50104206ba731c3bdc9aab3acfcf69cd83f0e0b4de18b88df2a9e73d64e55638421768d4433c542b6619f6e5af6b17cccd3090cf8b4d4efe9863e4')

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DRANGE_V3_TESTS=OFF \
    -DRANGE_V3_HEADER_CHECKS=OFF \
    -DRANGE_V3_EXAMPLES=OFF \
    -DRANGE_V3_PERF=OFF \
    "../${_realname}-${pkgver}"

  ${MINGW_PREFIX}/bin/cmake.exe --build ./
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --build ./ --target install
  mv "${pkgdir}${MINGW_PREFIX}"/include/module.modulemap "${pkgdir}${MINGW_PREFIX}"/include/range-v3.modulemap

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