# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Ronald van Haren <ronald.archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: damir <damir@archlinux.org>

pkgname=netcdf
pkgver=4.9.2
pkgrel=4.1
pkgdesc="network Common Data Form interface for array-oriented data access and corresponding library"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://www.unidata.ucar.edu/software/netcdf/"
depends=(hdf5 curl libxml2 libaec blosc bzip2 libzip zstd)
makedepends=(cmake git)
checkdepends=(unzip)
optdepends=('netcdf-fortran: fortran bindings' 'netcdf-cxx: c++ bindings')
options=(!makeflags)
license=(custom)
_commit=d18a6061c2f22cdc21e712a312da3807bec6c54d
source=("git+https://github.com/Unidata/netcdf-c.git#commit=${_commit}")
sha256sums=('f0081a888658814019c3d0550e0aaa25d99a3465472f72cdc850d6ad1726659c')

prepare() {
  # https://github.com/Unidata/netcdf-c/issues/2188 https://github.com/Unidata/netcdf-c/issues/2242
  sed -i "/tst_remote3/d" ${pkgname}-c/ncdap_test/CMakeLists.txt
}

build() {
  case "${CARCH}" in
    powerpc64*|riscv64|x86_64)
      cmake_options=(
        -DENABLE_CDF5=ON
      )
    ;;
    powerpc)
      cmake_options=(
        -DENABLE_CDF5=OFF
        -DNETCDF_GENERATE_NCGEN=ON
      )
    ;;
  esac 

  cmake -B build -S ${pkgname}-c \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCMAKE_BUILD_TYPE=Release \
    -DENABLE_BYTERANGE=ON ${cmake_options[@]}
  make -C build
}

check() {
  case "${CARCH}" in
    x86_64) make -C build test ;;
    *) warn "tests disabled for ${CARCH}" ;;
  esac
}

package() {
  make -C build DESTDIR="${pkgdir}" install
  install -Dm644 ${pkgname}-c/COPYRIGHT -t "${pkgdir}"/usr/share/licenses/${pkgname}/
}
