From 4fcc421745eff8b5631719cd028a395c25e35988 Mon Sep 17 00:00:00 2001 From: Ryan Mulhall <35538242+rem1776@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:53:04 -0400 Subject: [PATCH] build: add cray compiler .mod output check and unused newunit macro to configure script (#1561) --- configure.ac | 7 ++++++ m4/gx_fortran_options.m4 | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/configure.ac b/configure.ac index 190a0e51ba..e7dc02506e 100644 --- a/configure.ac +++ b/configure.ac @@ -280,6 +280,13 @@ if test $hdf5_fpe_bug = yes; then NetCDF must be built with a HDF5 version other than 1.14.3 to support floating point exception traps.]) fi +rm -f test.nc + +# Check if we need a flag to not capitalize module output (needed with cray compiler) +GX_FC_MOD_CASE_FLAG([FCFLAGS="$FCFLAGS $FC_MOD_CASE_FLAG"]) + +# Check if new unit is supported +GX_FC_08_OPEN_NEWUNIT([], [AC_MSG_ERROR([Compiler support for use of newunit argument is required to build FMS])]) # Check if Fortran compiler has the Class, Character array assign bug GX_FC_CLASS_CHAR_ARRAY_BUG_CHECK() diff --git a/m4/gx_fortran_options.m4 b/m4/gx_fortran_options.m4 index 2bb5e7b90e..04980c1b68 100644 --- a/m4/gx_fortran_options.m4 +++ b/m4/gx_fortran_options.m4 @@ -27,6 +27,7 @@ # GX_FC_CRAY_POINTER_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE]) # GX_FC_INTERNAL_FILE_NML() # GX_FC_CHECK_MOD(module-name, [only], [action-if-found], [action-if-not-found]) +# GX_FC_MOD_OUTPUT_CASE([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE]) # # DESCRIPTION # @@ -405,3 +406,54 @@ AC_DEFUN([_GX_FORTRAN_PP_SRCEXT_POP], [ AS_VAR_SET_IF([_gx_fortran_pp_srcext_save], [ac_ext=${_gx_fortran_pp_srcext_save}], [ac_ext="f"]) unset _gx_fortran_pp_srcext_save ])# _GX_FORTRAN_PP_SRCEXT_POP + + +# GX_FC_MOD_CASE_FLAG([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE]) +# ----------------------------------------------------------------------------- +# Checks if the output .mod files are in uppercase by default. +# This has only been seen with cray compiler. A flag is required to disable the uppercase output +# and instead follow the case of the module name as written in the source file. +# +# Sets the variable FC_MOD_CASE_FLAG to hold the flag that disables the behavior. +# +AC_DEFUN([GX_FC_MOD_CASE_FLAG],[ +AC_LANG_PUSH([Fortran]) +AC_FC_SRCEXT(F90) +AC_CACHE_CHECK([if Fortran flag needed for module output case], [gx_cv_fc_mod_case_flag],[ +gx_cv_fc_mod_case_flag="unknown" +gx_mod_case_flag_FCFLAGS_save=$FCFLAGS + +FCFLAGS="$gx_mod_case_flag_FCFLAGS_save -c" +AC_COMPILE_IFELSE([[module foo +end module foo]], + [], + AC_MSG_ERROR(["Failed to compile test module with -c"])) + +# if output .mod file is capitalized, add the flag and check that it works +if test -f "FOO.${FC_MODEXT}"; then + FCFLAGS="$gx_mod_case_flag_FCFLAGS_save -c -ef" + AC_COMPILE_IFELSE([[module foo + end module mod]], + []) + if test -f "foo.${FC_MODEXT}"; then + gx_cv_fc_mod_case_flag="-ef" + fi +else + gx_cv_fc_mod_case_flag=no +fi + +rm -f conftest.err conftest.$ac_objext conftest.$ac_ext +FCFLAGS=$gx_mod_case_flag_FCFLAGS_save +]) + +if test "x$gx_cv_fc_mod_case_flag" = "xunknown"; then + m4_default([$2], + [AC_MSG_ERROR([No working flag found to disable module filename capitalization])]) +elif test "x$gx_cv_fc_mod_case_flag" != "xno"; then + FC_MOD_CASE_FLAG=$gx_cv_fc_mod_case_flag + AC_SUBST([FC_MOD_CASE_FLAG]) + $1 +fi +AC_LANG_POP([Fortran]) +]) +