# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Bruno Pagani <archange@archlinux.org>

pkgname=adios2
pkgver=2.10.1
pkgrel=3
pkgdesc="The Adaptable Input/Output System version 2"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://adios2.readthedocs.io/en/latest/"
license=(Apache)
depends=(blosc bzip2 glibc gcc-libs hdf5 libfabric libpng nlohmann-json
         openmpi pugixml pybind11 sz yaml-cpp zeromq zfp zlib)
# with mgard does not build currently, not time to investigate
makedepends=(cmake gcc-fortran gtest python python-mpi4py python-numpy)
source=(https://github.com/ornladios/ADIOS2/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('ce776f3a451994f4979c6bd6d946917a749290a37b7433c0254759b02695ad85')

build() {
  case "${CARCH}" in
    powerpc)
      export CFLAGS+=' -Wno-narrowing'
      export CXXFLAGS+=' -Wno-narrowing'
      cmake_options=(
        -DDILL_NATIVE_ONLY=OFF
      )
    ;;
    powerpc64|riscv64)
      cmake_options=(
        -DDILL_NATIVE_ONLY=OFF
      )
    ;;
  esac

  cmake -B build -S ${pkgname^^}-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DADIOS2_USE_EXTERNAL_DEPENDENCIES=ON \
    -DADIOS2_HAVE_HDF5_VOL=OFF \
    -DADIOS2_BUILD_EXAMPLES=OFF ${cmake_options[@]} #\
    #-DMGARD_INCLUDE_DIR=/usr/include/mgard
    #-DADIOS2_HAVE_HDF5_VOL needs hdf5-openmpi
  make VERBOSE=1 -C build
}

package() {
  CMAKE_PREFIX_PATH="$pkgdir"/usr/lib/cmake \
  make -C build DESTDIR="${pkgdir}" install

  # conflicts with the actual libffi
  rm -fv ${pkgdir}/usr/lib/{,pkgconfig/}libffi.*
}
