+2010-07-02 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
+
+ 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.
+
2010-07-02 Eric Blake <eblake@redhat.com>
Optimize AS_BOX.
** The following macros are now documented:
AS_BOX
+** 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.*.
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.
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
# 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
# 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.
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
[[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
[[AC_INIT
AC_CONFIG_HEADERS([config.h:config.hin])
AC_PROG_FC
+AC_FC_FIXEDFORM
AC_FC_MAIN
AC_FC_WRAPPERS
AC_PROG_CC
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: prog.@OBJEXT@
+ @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
+
+.SUFFIXES: .f90 .@OBJEXT@
+.f90.@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: prog.@OBJEXT@
+ @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
+
+.SUFFIXES: .f .@OBJEXT@
+.f.@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: prog.@OBJEXT@
+ @FC@ @FCFLAGS@ -o $@ prog.@OBJEXT@ @LIBS@
+
+.SUFFIXES: .f90 .@OBJEXT@
+.f90.@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
/^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}