# Maintainer: Alexey Kasatkin <alexeikasatkin@gmail.com>

_realname=stxxl
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=1.4.1.387.gb9e44f0e
pkgrel=2
_commit=b9e44f0ecba7d7111fbb33f3330c3e53f2b75236
pkgdesc="Standard Template Library for Extra Large Data Sets (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'aur: libstxxl'
)
url="https://stxxl.sourceforge.io/"
license=('spdx:BSL-1.0')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  'git')
source=("${_realname}"::"git+https://github.com/stxxl/stxxl.git#commit=$_commit"
        001-cmake-files-location.patch
        002-install-shared-lib.patch)
sha256sums=('SKIP'
            'da0c4dc2e3bf3a1f1978116fde036f2087af8307101e76fe36b773cb5a22a432'
            '00388f16e6f94abf83de444e7b4940e65e4325258a05f4e4a6a2dad79915960b')

pkgver() {
  cd "${_realname}"
  git describe --tags | sed 's|-|.|g'
}

prepare() {
  cd ${_realname}
  patch -p1 -i "${srcdir}"/001-cmake-files-location.patch
  patch -p1 -i "${srcdir}"/002-install-shared-lib.patch
}

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

  CXXFLAGS+=" -Wno-deprecated-copy" \
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_STATIC_LIBS=ON \
    -DUSE_STD_THREADS=ON \
    ../${_realname}

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


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

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

  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -Dm644 ../${_realname}/LICENSE_1_0.txt \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE_1_0.txt"
}
