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

pkgname=netcdf-fortran
pkgver=4.6.1
pkgrel=2.1
pkgdesc="NetCDF fortran bindings"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://github.com/Unidata/netcdf-fortran"
license=(custom)
depends=(gcc-libs netcdf curl)
makedepends=(cmake gcc-fortran doxygen)
checkdepends=(valgrind)
options=(!makeflags staticlibs)
source=(${url}/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz)
sha256sums=('40b534e0c81b853081c67ccde095367bd8a5eead2ee883431331674e7aa9509f')

build() {
  cmake -B build -S ${pkgname}-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DENABLE_FILTER_TEST=ON \
    -DENABLE_LARGE_FILE_TESTS=ON \
    -DTEST_WITH_VALGRIND=ON
  make -C build
}

check() {
  make -C build test
}

package() {
  make -C build DESTDIR="${pkgdir}" install
  install -Dm644 ${pkgname}-${pkgver}/COPYRIGHT -t "${pkgdir}"/usr/share/licenses/${pkgname}/
  # Remove unwanted artifacts https://github.com/Unidata/netcdf-fortran/issues/338
  rmdir "${pkgdir}"/usr/include/CMakeFiles/{netcdff{,_c}.dir,}
  rm "${pkgdir}"/usr/lib/objects-RelWithDebInfo/{nf_,f}test_c/f03lib.c.o
  rmdir "${pkgdir}"/usr/lib/objects-RelWithDebInfo/{{nf_,f}test_c,}
  rm "${pkgdir}"/usr/lib/objects-Release/netcdff_c/nf_{lib,v2compat}.c.o
  rmdir "${pkgdir}"/usr/lib/objects-Release/{netcdff_c,}
}
