Skip to content

Commit

Permalink
Merge pull request #1272 from marshallward/ac_ncflag_update
Browse files Browse the repository at this point in the history
Autoconf netCDF flag update
  • Loading branch information
adcroft authored Dec 18, 2020
2 parents 446becc + 7fc8a41 commit 1f38235
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 58 deletions.
14 changes: 1 addition & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
69 changes: 50 additions & 19 deletions ac/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,56 @@ AX_FC_CHECK_MODULE([mpi],

# 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.])]
)
# 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 -I$($NF_CONFIG --includedir)"])
], [AC_MSG_ERROR([Could not find nf-config.])]
)
AX_FC_CHECK_MODULE([netcdf], [], [
AC_MSG_ERROR([Could not find netcdf module.])
])
])

# 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 -L$($NC_CONFIG --libdir)"]
)
], [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 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], [], [], [
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 -L$($NF_CONFIG --prefix)/lib"]
)
], [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
Expand Down
2 changes: 1 addition & 1 deletion ac/deps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 33 additions & 19 deletions ac/deps/configure.fms.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 -I$($NC_CONFIG --includedir)"])
],
[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 -I$($NF_CONFIG --includedir)"])
],
[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])


Expand Down
13 changes: 7 additions & 6 deletions ac/m4/ax_fc_check_lib.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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])]
Expand Down
7 changes: 7 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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*

0 comments on commit 1f38235

Please sign in to comment.