From b1e7c0216b0eba8408ff5a7e55919d4d1c9bf9b7 Mon Sep 17 00:00:00 2001 From: Marshall Ward Date: Thu, 10 Dec 2020 19:43:49 -0800 Subject: [PATCH 1/3] Autoconf: safer netCDF flag support This patch trims some of the netCDF flag management and adds more explicit tests for the FMS and MOM6 flags. - We only test for -I flags when compiling the FMS library, since links are not required at compile-time. (NOTE: This may need verification for static builds on Gaea). - Further separation of C and Fortran flags. - libnetcdf support is explicitly added to MOM6. Previously it was not tested and linked. This is in preparation for FMS 2020.04 support. --- ac/configure.ac | 62 +++++++++++++++++++++++++++++++--------- ac/deps/configure.fms.ac | 52 +++++++++++++++++++++------------ ac/m4/ax_fc_check_lib.m4 | 13 +++++---- 3 files changed, 89 insertions(+), 38 deletions(-) diff --git a/ac/configure.ac b/ac/configure.ac index b069fdd56f..6062de03d2 100644 --- a/ac/configure.ac +++ b/ac/configure.ac @@ -83,25 +83,61 @@ AX_FC_CHECK_MODULE([mpi], # netCDF configuration -# NOTE: `nf-config --flibs` combines library paths (-L) and libraries (-l), +# Search for the Fortran netCDF module, fallback to nf-config. +AX_FC_CHECK_MODULE([netcdf], [], [ + AS_UNSET([ax_fc_cv_mod_netcdf]) + AC_PATH_PROG([NF_CONFIG], [nf-config]) + AS_IF([test -n "$NF_CONFIG"], [ + AC_SUBST([FCFLAGS], ["$FCFLAGS $($NF_CONFIG --fflags)"]) + ], [AC_MSG_ERROR([Could not find nf-config.])] + ) + AX_FC_CHECK_MODULE([netcdf], [], [ + AC_MSG_ERROR([Could not find netcdf module.]) + ]) +]) + +# NOTE: `nc-config --libs` combines library paths (-L) and libraries (-l), # even though these ought to be separated in the invocation of `ld`. # # We use `sed` to strip the -l and pass the -L to LDFLAGS, and rely on autoconf # to configure the -l flags. AC_PROG_SED -AC_PATH_PROG([NF_CONFIG], [nf-config]) -AS_IF([test -n "$NF_CONFIG"], - [CPPFLAGS="$CPPFLAGS $($NF_CONFIG --fflags)" - FCFLAGS="$FCFLAGS $($NF_CONFIG --fflags)" - LDFLAGS="$LDFLAGS $($NF_CONFIG --flibs | $SED -e 's/-l[[^ ]]*//g')"], - [AC_MSG_ERROR([Could not find nf-config.])]) - -AX_FC_CHECK_MODULE([netcdf], - [], [AC_MSG_ERROR([Could not find netcdf module.])]) -AX_FC_CHECK_LIB([netcdff], [nf_create], [netcdf], - [], [AC_MSG_ERROR([Could not link netcdff library.])] -) +# FMS may invoke netCDF C calls, so we link to libnetcdf. +AC_LANG_PUSH([C]) +AC_CHECK_LIB([netcdf], [nc_create], [], [ + AS_UNSET([ac_cv_lib_netcdf_nc_create]) + AC_PATH_PROG([NC_CONFIG], [nc-config]) + AS_IF([test -n "$NC_CONFIG"], [ + AC_SUBST([LDFLAGS], + ["$LDFLAGS $($NC_CONFIG --libs | $SED -e 's/-l[[^ ]]*//g')"] + ) + ], [AC_MSG_ERROR([Could not find nc-config.])] + ) + AC_CHECK_LIB([netcdf], [nc_create], [], [ + AC_MSG_ERROR([Could not find libnetcdf.]) + ]) +]) +AC_LANG_POP([C]) + +# NOTE: We test for nf_create, rather than nf90_create, because AX_FC_CHECK_LIB +# is currently not well-suited to probe inside modules. +# Testing of the nf90_* functions will require a macro update. + +# Link to Fortran netCDF library, netcdff +AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ + AS_UNSET([ax_fc_cv_lib_netcdff_nf_create]) + AC_PATH_PROG([NF_CONFIG], [nf-config]) + AS_IF([test -n "$NF_CONFIG"], [ + AC_SUBST([LDFLAGS], + ["$LDFLAGS $($NF_CONFIG --flibs | $SED -e 's/-l[[^ ]]*//g')"] + ) + ], [AC_MSG_ERROR([Could not find nf-config.])] + ) + AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ + AC_MSG_ERROR([Could not find libnetcdff.]) + ]) +]) # Force 8-byte reals diff --git a/ac/deps/configure.fms.ac b/ac/deps/configure.fms.ac index 4ac86f6445..a4cf3ae1a1 100644 --- a/ac/deps/configure.fms.ac +++ b/ac/deps/configure.fms.ac @@ -15,6 +15,7 @@ AC_PROG_CC AX_MPI CC=$MPICC + # FMS configuration # Linux and macOS have a gettid system call, but it is not implemented in older @@ -74,25 +75,38 @@ AC_DEFINE([use_libMPI]) # netCDF configuration -# NOTE: `nf-config --flibs` combines library paths (-L) and libraries (-l), -# even though these ought to be separated in the invocation of `ld`. -# -# We use `sed` to strip the -l and pass the -L to LDFLAGS, and rely on autoconf -# to configure the -l flags. -AC_PROG_SED - -AC_PATH_PROG([NF_CONFIG], [nf-config]) -AS_IF([test -n "$NF_CONFIG"], - [CPPFLAGS="$CPPFLAGS $($NF_CONFIG --fflags)" - FCFLAGS="$FCFLAGS $($NF_CONFIG --fflags)" - LDFLAGS="$LDFLAGS $($NF_CONFIG --flibs | $SED -e 's/-l[[^ ]]*//g')"], - [AC_MSG_ERROR([Could not find nf-config.])]) - -AX_FC_CHECK_MODULE([netcdf], - [], [AC_MSG_ERROR([Could not find netcdf module.])]) -AX_FC_CHECK_LIB([netcdff], [nf_create], [netcdf], - [], [AC_MSG_ERROR([Could not link netcdff library.])] -) +# Check for netcdf.h header function declarations. +# If unavailable, then try to invoke nc-create. +AC_LANG_PUSH([C]) +AC_CHECK_HEADERS([netcdf.h], [], [ + AS_UNSET([ac_cv_header_netcdf_h]) + AC_PATH_PROG([NC_CONFIG], [nc-config]) + AS_IF([test -n "$NC_CONFIG"], [ + AC_SUBST([CPPFLAGS], ["$CPPFLAGS $($NC_CONFIG --cflags)"]) + ], + [AC_MSG_ERROR([Could not find nc-config.])] + ) + AC_CHECK_HEADERS([netcdf.h], [], [ + AC_MSG_ERROR([Could not find netcdf.h]) + ]) +]) +AC_LANG_POP([C]) + +# Search for the Fortran netCDF module, fallback to nf-config. +AX_FC_CHECK_MODULE([netcdf], [], [ + AS_UNSET([ax_fc_cv_mod_netcdf]) + AC_PATH_PROG([NF_CONFIG], [nf-config]) + AS_IF([test -n "$NF_CONFIG"], [ + AC_SUBST([FCFLAGS], ["$FCFLAGS $($NF_CONFIG --fflags)"]) + ], + [AC_MSG_ERROR([Could not find nf-config.])] + ) + AX_FC_CHECK_MODULE([netcdf], [], [ + AC_MSG_ERROR([Could not find netcdf module.]) + ]) +]) + +# FMS requires this macro to signal netCDF support. AC_DEFINE([use_netCDF]) diff --git a/ac/m4/ax_fc_check_lib.m4 b/ac/m4/ax_fc_check_lib.m4 index c0accab6cd..a7f848cd60 100644 --- a/ac/m4/ax_fc_check_lib.m4 +++ b/ac/m4/ax_fc_check_lib.m4 @@ -18,7 +18,7 @@ dnl library with different -L flags, or perhaps other ld configurations. dnl dnl Results are cached in the ax_fc_cv_lib_LIBRARY_FUNCTION variable. dnl -AC_DEFUN([AX_FC_CHECK_LIB],[dnl +AC_DEFUN([AX_FC_CHECK_LIB],[ AS_VAR_PUSHDEF([ax_fc_Lib], [ax_fc_cv_lib_$1_$2]) m4_ifval([$6], [ax_fc_lib_msg_LDFLAGS=" with $6"], @@ -29,14 +29,15 @@ AC_DEFUN([AX_FC_CHECK_LIB],[dnl LDFLAGS="$6 $LDFLAGS" ax_fc_check_lib_save_LIBS=$LIBS LIBS="-l$1 $7 $LIBS" - AS_IF([test -n $3], + AS_IF([test -n "$3"], [ax_fc_use_mod="use $3"], [ax_fc_use_mod=""]) - AC_LINK_IFELSE([ - AC_LANG_PROGRAM([], [dnl + AC_LINK_IFELSE([dnl +dnl Begin 7-column code block +AC_LANG_PROGRAM([], [dnl $ax_fc_use_mod - call $2]dnl - ) + call $2])dnl +dnl End code block ], [AS_VAR_SET([ax_fc_Lib], [yes])], [AS_VAR_SET([ax_fc_Lib], [no])] From c8fa91d4fa1219bc436f01bbdf8b47a4d06d9b20 Mon Sep 17 00:00:00 2001 From: Marshall Ward Date: Thu, 10 Dec 2020 23:56:42 -0500 Subject: [PATCH 2/3] Autoconf: explicit netCDF directry flags The --cflags/--fflags arguments of nc-config/nf-config can be volatile, since they generally represent library install-time flags, so we instead replace them with --includedir/--libdir flags, which explicitly denote the installation paths. The only real issue here is that nf-config does not have a --libdir flag, so we use $(nf-config --prefix)/lib and hope that this is where it's installed. --- ac/configure.ac | 17 ++++++----------- ac/deps/configure.fms.ac | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/ac/configure.ac b/ac/configure.ac index 6062de03d2..ad8ed83603 100644 --- a/ac/configure.ac +++ b/ac/configure.ac @@ -88,7 +88,7 @@ AX_FC_CHECK_MODULE([netcdf], [], [ AS_UNSET([ax_fc_cv_mod_netcdf]) AC_PATH_PROG([NF_CONFIG], [nf-config]) AS_IF([test -n "$NF_CONFIG"], [ - AC_SUBST([FCFLAGS], ["$FCFLAGS $($NF_CONFIG --fflags)"]) + AC_SUBST([FCFLAGS], ["$FCFLAGS -I$($NF_CONFIG --includedir)"]) ], [AC_MSG_ERROR([Could not find nf-config.])] ) AX_FC_CHECK_MODULE([netcdf], [], [ @@ -96,13 +96,6 @@ AX_FC_CHECK_MODULE([netcdf], [], [ ]) ]) -# NOTE: `nc-config --libs` combines library paths (-L) and libraries (-l), -# even though these ought to be separated in the invocation of `ld`. -# -# We use `sed` to strip the -l and pass the -L to LDFLAGS, and rely on autoconf -# to configure the -l flags. -AC_PROG_SED - # FMS may invoke netCDF C calls, so we link to libnetcdf. AC_LANG_PUSH([C]) AC_CHECK_LIB([netcdf], [nc_create], [], [ @@ -110,7 +103,7 @@ AC_CHECK_LIB([netcdf], [nc_create], [], [ AC_PATH_PROG([NC_CONFIG], [nc-config]) AS_IF([test -n "$NC_CONFIG"], [ AC_SUBST([LDFLAGS], - ["$LDFLAGS $($NC_CONFIG --libs | $SED -e 's/-l[[^ ]]*//g')"] + ["$LDFLAGS -L$($NC_CONFIG --libdir)"] ) ], [AC_MSG_ERROR([Could not find nc-config.])] ) @@ -121,8 +114,10 @@ AC_CHECK_LIB([netcdf], [nc_create], [], [ AC_LANG_POP([C]) # NOTE: We test for nf_create, rather than nf90_create, because AX_FC_CHECK_LIB -# is currently not well-suited to probe inside modules. +# is currently not yet able to properly probe inside modules. # Testing of the nf90_* functions will require a macro update. +# NOTE: nf-config does not have a --libdir flag, so we use --prefix and assume +# that libraries are in the $prefix/lib directory. # Link to Fortran netCDF library, netcdff AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ @@ -130,7 +125,7 @@ AX_FC_CHECK_LIB([netcdff], [nf_create], [], [], [ AC_PATH_PROG([NF_CONFIG], [nf-config]) AS_IF([test -n "$NF_CONFIG"], [ AC_SUBST([LDFLAGS], - ["$LDFLAGS $($NF_CONFIG --flibs | $SED -e 's/-l[[^ ]]*//g')"] + ["$LDFLAGS -L$($NF_CONFIG --prefix)/lib"] ) ], [AC_MSG_ERROR([Could not find nf-config.])] ) diff --git a/ac/deps/configure.fms.ac b/ac/deps/configure.fms.ac index a4cf3ae1a1..bf899126cc 100644 --- a/ac/deps/configure.fms.ac +++ b/ac/deps/configure.fms.ac @@ -82,7 +82,7 @@ AC_CHECK_HEADERS([netcdf.h], [], [ AS_UNSET([ac_cv_header_netcdf_h]) AC_PATH_PROG([NC_CONFIG], [nc-config]) AS_IF([test -n "$NC_CONFIG"], [ - AC_SUBST([CPPFLAGS], ["$CPPFLAGS $($NC_CONFIG --cflags)"]) + AC_SUBST([CPPFLAGS], ["$CPPFLAGS -I$($NC_CONFIG --includedir)"]) ], [AC_MSG_ERROR([Could not find nc-config.])] ) @@ -97,7 +97,7 @@ AX_FC_CHECK_MODULE([netcdf], [], [ AS_UNSET([ax_fc_cv_mod_netcdf]) AC_PATH_PROG([NF_CONFIG], [nf-config]) AS_IF([test -n "$NF_CONFIG"], [ - AC_SUBST([FCFLAGS], ["$FCFLAGS $($NF_CONFIG --fflags)"]) + AC_SUBST([FCFLAGS], ["$FCFLAGS -I$($NF_CONFIG --includedir)"]) ], [AC_MSG_ERROR([Could not find nf-config.])] ) From 008af9a357072d758138d4bff7a2caad0a5db01d Mon Sep 17 00:00:00 2001 From: Marshall Ward Date: Fri, 11 Dec 2020 10:10:43 -0500 Subject: [PATCH 3/3] Testing: Update FMS to 2020.04 ; .gitignore update The verification tests in .testing are updated to run on FMS 2020.04. Also, several documentation outputs in .gitignore were moved to docs/.gitignore, as well as some older files and directories that were interfering with content in ac/deps. --- .gitignore | 14 +------------- ac/deps/Makefile | 2 +- docs/.gitignore | 7 +++++++ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index b35af3a4ec..25f7524d1c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,19 +4,7 @@ html -# Build output -*.o -*.mod -MOM6 -build/ -_build/ -deps/ -MOM6.tags -bib*.aux -citelist.doc* - - -# Autoconf +# Autoconf output aclocal.m4 autom4te.cache/ config.log diff --git a/ac/deps/Makefile b/ac/deps/Makefile index 0ed4fd19a7..bba42a3b11 100644 --- a/ac/deps/Makefile +++ b/ac/deps/Makefile @@ -13,7 +13,7 @@ MKMF_COMMIT ?= master # FMS framework FMS_URL ?= https://github.com/NOAA-GFDL/FMS.git -FMS_COMMIT ?= 2019.01.03 +FMS_COMMIT ?= 2020.04 # List of source files to link this Makefile's dependencies to model Makefiles diff --git a/docs/.gitignore b/docs/.gitignore index 497c10b69d..e8b6a0513b 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -4,8 +4,15 @@ doxygen.log APIs MOM6.tags details/tutorial + + # Ignore sphinx-build output _build api src xml + + +# Citation output +bib*.aux +citelist.doc*