From 27923cea6f43f19f21af392cfb3ddaa52a67b761 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Thu, 17 Jun 2021 19:09:59 +0200
Subject: [PATCH] Update cfortran-related m4 macros: make them work when either
 FC or F77 is disabled.

---
 m4/acx_cfortran_flags.m4 | 16 ++++++++++------
 m4/acx_check_cfortran.m4 |  3 +--
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/m4/acx_cfortran_flags.m4 b/m4/acx_cfortran_flags.m4
index 44854e587..7c56876e8 100644
--- a/m4/acx_cfortran_flags.m4
+++ b/m4/acx_cfortran_flags.m4
@@ -150,13 +150,17 @@ dnl check f77 flag matches fc flag
          AC_PROVIDE_IFELSE([AC_PROG_F77],
            [AC_PROVIDE_IFELSE([AC_PROG_FC],
               [dnl both FC and F77 are configured
-               AS_IF([test -z "$FC" -o X"$FC" != Xno],
-                 [acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)"],
-                 [test -z "$F77" -o X"$F77" != Xno],
-                 [acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"],
+               AS_IF([test -z "$FC" -o X"$FC" = Xno],
+                 [dnl FC compiler is not available, take the flag for F77
+                  acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"],
+                 [test -z "$F77" -o X"$F77" = Xno],
+                 [dnl F77 compiler is not available, take the flag for FC
+                  acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)"],
                  [AS_IF([test x"$acx_cv_f77_cf_flag" = x"$acx_cv_fc_cf_flag"],
-                    [acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"],
-                    [AC_MSG_ERROR([cfortran.h flag for $F77 does not match the flag for $FC.
+                    [dnl the flags for both compilers are the same
+                     acx_cv_cf_flag="$acx_cv_f77_cf_flag (probed)"],
+                    [dnl FC and F77 need different flags
+                     AC_MSG_ERROR([cfortran.h flag for $F77 does not match the flag for $FC.
 Have you configured compatible compilers?])])])
               ])],[acx_cv_cf_flag="$acx_cv_fc_cf_flag (probed)"])
         ])
diff --git a/m4/acx_check_cfortran.m4 b/m4/acx_check_cfortran.m4
index edd50f8b3..f784dd666 100644
--- a/m4/acx_check_cfortran.m4
+++ b/m4/acx_check_cfortran.m4
@@ -204,8 +204,7 @@ dnl
 AC_DEFUN([ACX_CHECK_CFORTRAN],
   [AC_CACHE_CHECK([if C externals constructed with cfortran.h work],
      [acx_cv_cfortran_works],
-     [acx_cv_cfortran_works=no
-      save_CPPFLAGS=$CPPFLAGS
+     [save_CPPFLAGS=$CPPFLAGS
       CPPFLAGS="-I]m4_ifval([$1],[$1],[$srcdir/include])[ $CPPFLAGS"
 dnl build C function
       AC_LANG_PUSH([C])
-- 
GitLab