# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=netcdf
pkgver=4.9.3
pkgrel=0
pkgdesc="Libraries for the Unidata network Common Data Format"
url="https://www.unidata.ucar.edu/software/netcdf/"
# disabled on s390x because of https://github.com/Unidata/netcdf-c/issues/1987
arch="all !s390x"
license="BSD-3-Clause"
options="net"  # tests need network access
makedepends="
	bash
	bzip2-dev
	cmake
	curl-dev
	hdf5-dev
	libaec-dev
	libxml2-dev
	m4
	samurai
	"
subpackages="
	$pkgname-doc
	$pkgname-dev
	$pkgname-utils:utils
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/Unidata/netcdf-c/archive/v$pkgver.tar.gz
	fix-test-on-big-endian.patch
	"
builddir="$srcdir/$pkgname-c-$pkgver"

build() {
	local _enable_cdf5=ON
	case "$CARCH" in
		x86|armhf|armv7) _enable_cdf5=OFF ;;
	esac
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DNETCDF_ENABLE_CDF5=$_enable_cdf5 \
		-DNETCDF_ENABLE_DAP_LONG_TESTS=ON \
		-DNETCDF_ENABLE_EXAMPLE_TESTS=ON \
		-DNETCDF_ENABLE_EXTRA_TESTS=ON \
		-DNETCDF_ENABLE_FAILING_TESTS=ON \
		-DNETCDF_ENABLE_FILTER_TESTING=ON \
		-DNETCDF_ENABLE_LARGE_FILE_TESTS=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

utils() {
	amove usr/bin
}

check() {
	# One test failure in nc_test as reported in https://github.com/Unidata/netcdf-c/issues/808
	# Server test.opendap.org:8080 seems to be down for dap4_test_test_hyrax|dap4_test_test_thredds test
	# Tests have to be executed in the correct order
	# ncdap_tst_remote3: fails repeatedly on builder
	# ncdump_tst_netcdf4_4: https://github.com/Unidata/netcdf-c/issues/2616
	cd build
	ctest -j 1 -E 'nc_test|dap4_test_test_hyrax|dap4_test_test_thredds|ncdump_test_rcmerge|ncdap_tst_remote3|ncdump_tst_netcdf4_4'
}

sha512sums="
c82d77572a10e8d84f5c2db205f3b486add97195c1c29ee4747a6e435fbfb03e111ddb652e137086db04d820eb7542ffbac310e48fae01474f0892abad099ed6  netcdf-4.9.3.tar.gz
29dda7a0e28333afb91f948c1f5527606634ab8014c6f123e73b092e550d9514c45391f11b33c59cbfbb1fd1ff581848305a47d3768f9b4d1a2be63609009d82  fix-test-on-big-endian.patch
"
