#!/usr/bin/env modbuild

# pbuild::set_download_url "http://cucis.ece.northwestern.edu/projects/PnetCDF/Release/$P-$V.tar.gz"
if (( V_MAJOR >= 1 && V_MINOR >= 11 )); then
  pbuild::set_download_url "https://parallel-netcdf.github.io/Release/pnetcdf-${V_PKG}.tar.gz"
else
  pbuild::set_download_url "https://parallel-netcdf.github.io/Release/parallel-netcdf-${V_PKG}.tar.gz"
fi

pbuild::add_to_group 'HDF5'

pbuild::install_docfiles 'AUTHORS' 'CREDITS'
pbuild::install_docfiles 'COPYING' 'COPYRIGHT'
pbuild::install_docfiles 'ChangeLog' 'NEWS'
pbuild::install_docfiles 'RELEASE_NOTES'

pbuild::pre_configure() {
	pbuild::add_configure_args "--with-mpi=${MPICC/bin\/*}"
	pbuild::add_configure_args "--with-pic"
	pbuild::add_configure_args "--disable-shared"
	case "${COMPILER}" in
		pgi )
			# PGI uses GCC's include files, some object files and
			# the STL implementation!
			# The PGI C pre-processor is broken and doesn't work 
			# for HDF5. We use the pre-processor of the underlying
			# GCC...
			# This is a bit hackish!
			#
			# The following eval sets GCCDIR! Which is something 
			# like:
			# /opt/psi/Programming/gcc/7.3.0/bin/../lib/gcc/x86_64-pc-linux-gnu/7.3.0
			#
			eval $(pgcc -show 2>/dev/null | \
				awk '/^GCCDIR[[:space:]]*=/{gsub(/[[:space:]]/,""); print $0}')
			pbuild::add_configure_args "CPP=${GCCDIR%%/..*}/cpp"
			;;
	esac
}

