* Eric Blake wrote on Wed, Jun 23, 2010 at 03:09:05PM CEST:
> On 06/20/2010 12:21 PM, Ralf Wildenhues wrote:
> > The Fortran test coverage in Autoconf is far from complete.  It is not
> > easy: the relevant macros are intertwined, and Fortran compilers vary
> > wildly.
> > 
> > This patch is a test balloon really.  So far tested with GCC and one
> > Intel version on GNU/Linux, and Sun suite on Solaris.  It would need
> > lots more testing, but I don't have access to many Fortran compilers.
> > I wouldn't be surprised to see a fair amount of failures with them,
> > consider yourself warned.
> 
> I'm okay with releasing 2.66 in order to widen the feedback path of more
> Fortran setups - we can deal with failures as they are reported (this
> change isn't adding regressions, just exposing any long-time issues).
> So yes, please apply.  And thanks for the effort, since I am rather
> illiterate at the moment when it comes to Fortran.

Thanks for the review, and FWIW all of your recent reviews; I had
applied this soon after.

I now got a chance to test IBM XL Fortran on GNU/Linux ppc64, which of
course led to a couple of new failure modes, because xlf95 assumes
free-form Fortran 95 regardless of source file extension.  It has
-qfixed to override the format.

ifort OTOH interprets .f as fixed-form unles you pass -free, and .f90 as
free-form unless you pass -fixed.

gfortran has -ffixed-form and -ffree-form, and without either, decides
by file name extension.

So, let's have an AC_FC_FIXEDFORM for symmetry as well, even if that may
not be needed very often in practice.

With the patch below, I've tested some version of GNU, Sun, IBM XL, and
Intel on at least one system each.  I consider that fairly encouraging.
The other compilers' flags are taken from documentation only.

OTOH, I'd love to hear from Fortran experts about a better tests that
fails free-form-assuming compilers.  The comment seems to work with all
compilers tested, but I'm not sure that's a given.

Thanks,
Ralf

    New macro AC_FC_FIXEDFORM, improved AC_FC_FREEFORM, coverage.
    
    * lib/autoconf/fortran.m4 (_AC_FC_DIALECT_YEAR): Fix typo in
    comment.
    (AC_FC_FREEFORM): Update list of known options for Sun, HP,
    Lahey/Fujitsu Fortran compilers.  Use M4 quoting consistently.
    (AC_FC_FIXEDFORM): New macro.
    * tests/fortran.at (AC_FC_DUMMY_MAIN usage, AC_FC_MAIN usage):
    Use AC_FC_FIXEDFORM, to avoid testsuite failure with FC=xlf95.
    (AC_FC_FREEFORM with AC_FC_SRCEXT, AC_FC_FIXEDFORM)
    (AC_FC_FIXEDFORM with AC_FC_SRCEXT): New tests.
    * tests/mktests.sh: No need to exclude AC_FC_FREEFORM, it uses
    AC_LANG_PUSH/AC_LANG_POP.
    * doc/autoconf.texi (Fortran Compiler): Document it.
    * NEWS: Update.

diff --git a/NEWS b/NEWS
index eecb9f6..93ed679 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,8 @@ GNU Autoconf NEWS - User visible changes.
    AT_ARG_OPTION has been changed in that the negative of a long option
    --OPTION is now --no-OPTION rather than --noOPTION.
 
+** New macro AC_FC_FIXEDFORM to accept fixed-form Fortran.
+
 * Major changes in Autoconf 2.65 (2009-11-21) [stable]
   Released by Eric Blake, based on git versions 2.64.*.
 
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 34ae872..a8bb8d4 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -7750,8 +7750,8 @@ Fortran Compiler
 Fortran standards, and have output variables like @code{FC},
 @code{FCFLAGS}, and @code{FCLIBS}.
 
-Except for two new macros @code{AC_FC_SRCEXT} and
-...@code{ac_fc_freeform} (see below), the @code{FC} and @code{F77} macros
+Except for the macros @code{AC_FC_SRCEXT}, @code{AC_FC_FREEFORM}, and
+...@code{ac_fc_fixedform} (see below), the @code{FC} and @code{F77} macros
 behave almost identically, and so they are documented together in this
 section.
 
@@ -8109,6 +8109,28 @@ Fortran Compiler
 message).
 @end defmac
 
+...@defmac AC_FC_FIXEDFORM (@ovar{action-if-success}, @ovar{action-if-failure})
+...@acindex{fc_fixedform}
+
+The @code{AC_FC_FIXEDFORM} tries to ensure that the Fortran compiler
+(@code{$FC}) allows the old fixed-format source code (as opposed to
+free-format style).  If necessary, it may add some additional flags to
+...@code{fcflags}.
+
+This macro is needed for some compilers alias names like @command{xlf95}
+which assume free-form source code by default, and in case you want to
+use fixed-form source with an extension like @file{.f90} which many
+compilers interpret as free-form by default.  If you specify a different
+extension with @code{AC_FC_SRCEXT}, such as @file{.f}, then
+...@code{ac_fc_fixedform} ordinarily succeeds without modifying
+...@code{fcflags}.
+
+If @code{AC_FC_FIXEDFORM} succeeds in compiling fixed-form source, it
+calls @var{action-if-success} (defaults to nothing).  If it fails, it
+calls @var{action-if-failure} (defaults to exiting with an error
+message).
+...@end defmac
+
 @node System Services
 @section System Services
 
diff --git a/lib/autoconf/fortran.m4 b/lib/autoconf/fortran.m4
index 1d8ef0b..f059546 100644
--- a/lib/autoconf/fortran.m4
+++ b/lib/autoconf/fortran.m4
@@ -308,7 +308,7 @@ AC_DEFUN([_AC_FC_DIALECT_YEAR],
 #  frt: Fujitsu F77 compiler
 #  pgf77/pgf90/pghpf/pgf95/pgfortran: Portland Group F77/F90/F95 compilers
 #  xlf/xlf90/xlf95: IBM (AIX) F77/F90/F95 compilers
-#    Prefer xlf9x to the generic names because they do not reject file
+#    Prefer xlf9x to the generic names because they do not reject files
 #    with extension `.f'.
 #  lf95: Lahey-Fujitsu F95 compiler
 #  fl32: Microsoft Fortran 77 "PowerStation" compiler
@@ -1164,23 +1164,25 @@ AC_LANG_POP(Fortran)dnl
 # prevent flag from being added to FCFLAGS multiple times.)
 #
 # The known flags are:
-#        -ffree-form: GNU g77
-#                -FR: Intel compiler (icc, ecc)
-#              -free: Compaq compiler (fort)
+#        -ffree-form: GNU g77, gfortran
+#         -FR, -free: Intel compiler (icc, ecc, ifort)
+#              -free: Compaq compiler (fort), Sun compiler (f95)
 #             -qfree: IBM compiler (xlf)
 # -Mfree, -Mfreeform: Portland Group compiler
 #          -freeform: SGI compiler
 #            -f free: Absoft Fortran
+#       +source=free: HP Fortran
+#              -nfix: Lahey/Fujitsu Fortran
 # We try to test the "more popular" flags first, by some prejudiced
 # notion of popularity.
 AC_DEFUN_ONCE([AC_FC_FREEFORM],
-[AC_LANG_PUSH(Fortran)dnl
-AC_CACHE_CHECK([for Fortran flag needed to allow free-form source],
-               ac_cv_fc_freeform,
+[AC_LANG_PUSH([Fortran])dnl
+AC_CACHE_CHECK([for Fortran flag needed to accept free-form source],
+              [ac_cv_fc_freeform],
 [ac_cv_fc_freeform=unknown
 ac_fc_freeform_FCFLAGS_save=$FCFLAGS
 for ac_flag in none -ffree-form -FR -free -qfree -Mfree -Mfreeform \
-              -freeform "-f free"
+              -freeform "-f free" +source=free -nfix
 do
   test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_freeform_FCFLAGS_save $ac_flag"
 dnl Use @&t@ below to ensure that editors don't turn 8+ spaces into tab.
@@ -1204,5 +1206,58 @@ else
   fi
   $1
 fi
-AC_LANG_POP(Fortran)dnl
+AC_LANG_POP([Fortran])dnl
 ])# AC_FC_FREEFORM
+
+
+# AC_FC_FIXEDFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
+# ------------------------------------------------------------------
+# Look for a compiler flag to make the Fortran (FC) compiler accept
+# fixed-format source code, and adds it to FCFLAGS.  Call
+# ACTION-IF-SUCCESS (defaults to nothing) if successful (i.e. can
+# compile code using new extension) and ACTION-IF-FAILURE (defaults to
+# failing with an error message) if not.  (Defined via DEFUN_ONCE to
+# prevent flag from being added to FCFLAGS multiple times.)
+#
+# The known flags are:
+#       -ffixed-form: GNU g77, gfortran
+#             -fixed: Intel compiler (ifort), Sun compiler (f95)
+#            -qfixed: IBM compiler (xlf*)
+#            -Mfixed: Portland Group compiler
+#         -fixedform: SGI compiler
+#           -f fixed: Absoft Fortran
+#      +source=fixed: HP Fortran
+#              -fix: Lahey/Fujitsu Fortran
+# Since compilers may accept fixed form based on file name extension,
+# but users may want to use it with others as well, call AC_FC_SRCEXT
+# with the respective source extension before calling this macro.
+AC_DEFUN_ONCE([AC_FC_FIXEDFORM],
+[AC_LANG_PUSH([Fortran])dnl
+AC_CACHE_CHECK([for Fortran flag needed to accept fixed-form source],
+              [ac_cv_fc_fixedform],
+[ac_cv_fc_fixedform=unknown
+ac_fc_fixedform_FCFLAGS_save=$FCFLAGS
+for ac_flag in none -ffixed-form -fixed -qfixed -Mfixed -fixedform "-f fixed" \
+              +source=fixed -fix
+do
+  test "x$ac_flag" != xnone && FCFLAGS="$ac_fc_fixedform_FCFLAGS_save $ac_flag"
+  AC_COMPILE_IFELSE([
+C     This comment should confuse free-form compilers.
+      program main
+      end],
+                   [ac_cv_fc_fixedform=$ac_flag; break])
+done
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+FCFLAGS=$ac_fc_fixedform_FCFLAGS_save
+])
+if test "x$ac_cv_fc_fixedform" = xunknown; then
+  m4_default([$2],
+            [AC_MSG_ERROR([Fortran does not accept fixed-form source], 77)])
+else
+  if test "x$ac_cv_fc_fixedform" != xnone; then
+    FCFLAGS="$FCFLAGS $ac_cv_fc_fixedform"
+  fi
+  $1
+fi
+AC_LANG_POP([Fortran])dnl
+])# AC_FC_FIXEDFORM
diff --git a/tests/fortran.at b/tests/fortran.at
index 1b43532..24d2a61 100644
--- a/tests/fortran.at
+++ b/tests/fortran.at
@@ -257,6 +257,7 @@ AT_DATA([configure.ac],
 [[AC_INIT
 AC_CONFIG_HEADERS([config.h:config.hin])
 AC_PROG_FC
+AC_FC_FIXEDFORM
 AC_FC_DUMMY_MAIN([], [AC_MSG_FAILURE([failed to determine FC dummy main], 
[77])])
 AC_FC_WRAPPERS
 AC_PROG_CC
@@ -419,6 +420,7 @@ AT_DATA([configure.ac],
 [[AC_INIT
 AC_CONFIG_HEADERS([config.h:config.hin])
 AC_PROG_FC
+AC_FC_FIXEDFORM
 AC_FC_MAIN
 AC_FC_WRAPPERS
 AC_PROG_CC
@@ -757,3 +759,118 @@ AT_CHECK([$MAKE], [], [ignore], [ignore])
 dnl AT_CHECK([./prog])
 
 AT_CLEANUP
+
+
+## --------------------------------- ##
+## AC_FC_FREEFORM with AC_FC_SRCEXT. ##
+## --------------------------------- ##
+
+AT_SETUP([AC_FC_FREEFORM with AC_FC_SRCEXT])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_FC_SRCEXT([f90])
+AC_PROG_FC
+AC_FC_FREEFORM
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+]])
+
+AT_DATA([Makefile.in],
+[[prog: pr...@objext@
+       @FC@ @FCFLAGS@ -o $@ pr...@objext@ @LIBS@
+
+.SUFFIXES: .f90 ....@objext@
+.f...@objext@:
+       @FC@ @FCFLAGS@ -c @FCFLAGS_f90@ $<
+]])
+
+AT_DATA([prog.f90],
+[[program main
+end
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+: ${MAKE=make}
+AT_CHECK([$MAKE], [], [ignore], [ignore])
+dnl AT_CHECK([./prog])
+
+AT_CLEANUP
+
+
+## ---------------- ##
+## AC_FC_FIXEDFORM. ##
+## ---------------- ##
+
+AT_SETUP([AC_FC_FIXEDFORM])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_PROG_FC
+AC_FC_FIXEDFORM
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+]])
+
+AT_DATA([Makefile.in],
+[[prog: pr...@objext@
+       @FC@ @FCFLAGS@ -o $@ pr...@objext@ @LIBS@
+
+.SUFFIXES: .f ....@objext@
+...@objext@:
+       @FC@ @FCFLAGS@ -c $<
+]])
+
+AT_DATA([prog.f],
+[[      program main
+C      fixed-form style comment
+       end
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+: ${MAKE=make}
+AT_CHECK([$MAKE], [], [ignore], [ignore])
+dnl AT_CHECK([./prog])
+
+AT_CLEANUP
+
+
+## ---------------------------------- ##
+## AC_FC_FIXEDFORM with AC_FC_SRCEXT. ##
+## ---------------------------------- ##
+
+AT_SETUP([AC_FC_FIXEDFORM with AC_FC_SRCEXT])
+
+AT_DATA([configure.ac],
+[[AC_INIT
+AC_PROG_FC
+AC_FC_SRCEXT([f90])
+AC_FC_FIXEDFORM
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
+]])
+
+AT_DATA([Makefile.in],
+[[prog: pr...@objext@
+       @FC@ @FCFLAGS@ -o $@ pr...@objext@ @LIBS@
+
+.SUFFIXES: .f90 ....@objext@
+.f...@objext@:
+       @FC@ @FCFLAGS@ -c @FCFLAGS_f90@ $<
+]])
+
+AT_DATA([prog.f90],
+[[      program main
+C      fixed-form style comment
+       end
+]])
+
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+: ${MAKE=make}
+AT_CHECK([$MAKE], [], [ignore], [ignore])
+dnl AT_CHECK([./prog])
+
+AT_CLEANUP
diff --git a/tests/mktests.sh b/tests/mktests.sh
index fe59be2..0a04e59 100755
--- a/tests/mktests.sh
+++ b/tests/mktests.sh
@@ -104,9 +104,6 @@ ac_exclude_list='
        /^AC_FC_SRCEXT$/ {next}
        /^AC_PATH_((TARGET_)?TOOL|PROG)S?$/ {next}
 
-       # Requires the current language to be Fortran, not C.
-       /^AC_FC_FREEFORM$/ {next}
-
        # Is a number.
        /^AC_FD_CC$/ {next}
 

Reply via email to