From 0da057e20ad6224d4d244fd06278f51b3098a74c Mon Sep 17 00:00:00 2001 From: Ralf Wildenhues Date: Tue, 29 Jun 2010 00:15:25 +0200 Subject: [PATCH] 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. Signed-off-by: Eric Blake --- ChangeLog | 17 +++++++ NEWS | 2 + doc/autoconf.texi | 26 ++++++++++- lib/autoconf/fortran.m4 | 73 ++++++++++++++++++++++++++---- tests/fortran.at | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/mktests.sh | 3 -- 6 files changed, 224 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index a559c167..82df57ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2010-07-02 Ralf Wildenhues + + 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 Optimize AS_BOX. diff --git a/NEWS b/NEWS index 8acc6e7a..cb1ffbd2 100644 --- a/NEWS +++ b/NEWS @@ -46,6 +46,8 @@ GNU Autoconf NEWS - User visible changes. ** 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.*. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index f531ed6e..0c106c71 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -7750,8 +7750,8 @@ are for newer programs that can (or must) compile under the newer 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 @@ calls @var{action-if-failure} (defaults to exiting with an error 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 1d8ef0b8..f059546d 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 1b435322..24d2a61f 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: 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 diff --git a/tests/mktests.sh b/tests/mktests.sh index fe59be2c..0a04e59c 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} -- 2.11.4.GIT