Commit 0ac70885 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add work-around for broken netcdf-c installations.

parent a07ee240
......@@ -147,6 +147,14 @@ command-line arguments (preferred) or via environment variables:
Fortran 77 compilers and the C++ compiler. These default to -g -O2
but it is recommended to at least add flags to adjust code
generation for the target architecture, e.g. -march=native for gcc.
+ __AR__
Command to create standard Unix (library) archive, defaults to ar.
+ __RANLIB__
Command to index standard Unix (library) archive, defaults to
ranlib.
+ __CC_PIC_FLAGS__
Flag(s) to __CC__ to produce object files that can be incorporated
into dynamic shared objects. The default value is -fPIC.
+ __LIBS__ and __LDFLAGS__
These variables are meant to hold flags and library specifications
in case some special library is needed (e.g. a custom malloc
......
......@@ -37,6 +37,9 @@ case $0 in
;;
esac
script_dir=$(cd "$script_dir"; pwd)
# shellcheck source=scripts/bash_functions
source "${script_dir}/scripts/bash_functions"
#
# number of concurrent build steps (i.e. argument to make -j), and
# optional argument to build makes
......@@ -75,6 +78,9 @@ case $build in
;;
esac
AR=${AR-ar}
RANLIB=${RANLIB-ranlib}
libtype=${libtype-shared}
case $libtype in
......@@ -513,14 +519,51 @@ else
nc_config=${nc_config-$(command -v nc-config)}
fi
# build netcdf fortran interface
if [[ x${syspkg[netcdf-fortran]+set} != xset ]]; then
args=()
function netcdf_fortran_build()
{
local args=() LIBS
if [[ $libtype = static ]]; then
args+=('LIBS=-lpnetcdf -lhdf5_hl -lhdf5 -lz -lsz -laec')
LIBS="-lpnetcdf -lhdf5_hl -lhdf5 -lz -lsz -laec${LIBS+ $LIBS}"
fi
# netcdf-c 4.6.2 up to 4.8.0 inclusive suffer from a bug in
# nc_create_par_fortran and nc_open_par_fortran when built with
# cmake for OpenMPI
# see https://github.com/Unidata/netcdf-c/pull/1957 for a description
path_mpicc=$(command -v mpicc)
mpibindir=${path_mpicc%/mpicc}
netcdf_c_version=$(${nc_config} --version)
netcdf_c_version=${netcdf_c_version#netCDF }
case "$(version_compare "$netcdf_c_version" 4.6.2)$(version_compare "$netcdf_c_version" 4.8.1)" in
21|01)
netcdf_c_libdir=$(${nc_config} --libdir)
if [[ -d "${netcdf_c_libdir}/cmake" \
&& -x "${mpibindir}/ompi_info" ]]; then
local __="netcdf-c-4.6.2-to-4.8.0-opencreate_par"
local CC_PIC_FLAGS_
if [[ $libtype != static ]]; then
CC_PIC_FLAGS_=${CC_PIC_FLAGS--fPIC}
else
unset CC_PIC_FLAGS_
fi
# it's conventional that CFLAGS is some sort of array, in
# a little broken, adorably naive way from a bygone era
# shellcheck disable=SC2086,SC2046
${CC} ${CFLAGS-} ${CC_PIC_FLAGS_-} $(${nc_config} --cflags) -c \
-o "${builddir}/${__}.o" "${script_dir}/patches/${__}.c"
${AR} rcu "${builddir}/libncf_override.a" \
"${builddir}/${__}.o"
${RANLIB} "${builddir}/libncf_override.a"
args+=("ac_cv_search_nc_open=${builddir}/libncf_override.a -lnetcdf")
fi
;;
esac
autotools_build netcdf-fortran libnetcdff netcdf-c \
${args[@]+"${args[@]}"}
}
# build netcdf fortran interface
if [[ x${syspkg[netcdf-fortran]+set} != xset ]]; then
netcdf_fortran_build
fi
......
/* netcdf-c 4.6.2 up to 4.8.0, when built with cmake, fail to call
* MPI_Info_f2c here. That does not make a difference for mpich and
* derived MPI implementations but is fatal in the case of OpenMPI.
*
* In self-defense this file provides a patch to insert in whatever
* way is most convenient. Probably easiest is to compile once with
* mpicc and add the resulting .o file to LIBS argument of netcdf-fortran
* configure.
*/
#include <mpi.h>
#include <netcdf.h>
#include <netcdf_par.h>
int
nc_open_par_fortran(const char *path, int omode, MPI_Fint comm,
MPI_Fint info, int *ncidp)
{
/* Convert fortran comm and info to C comm and info. */
MPI_Comm comm_c = MPI_Comm_f2c(comm);
MPI_Info info_c = MPI_Info_f2c(info);
return nc_open_par(path, omode, comm_c, info_c, ncidp);
}
int
nc_create_par_fortran(const char *path, int cmode, MPI_Fint comm,
MPI_Fint info, int *ncidp)
{
/* Convert fortran comm and info to C comm and info. */
MPI_Comm comm_c = MPI_Comm_f2c(comm);
MPI_Info info_c = MPI_Info_f2c(info);
return nc_create_par(path, cmode, comm_c, info_c, ncidp);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment