New macro AC_FC_PP_SRCEXT for preprocessed file extensions.

* lib/autoconf/fortran.m4 (AC_FC_PP_SRCEXT): New macro.
* lib/autom4te.in (Automake-preselections): Preselect it.
* doc/autoconf.texi (Fortran Compiler): Document it, rewriting
the documentation for AC_FC_SRCEXT along the way.
* tests/fortran.at (AC_FC_PP_SRCEXT usage): New test.
* tests/mktests.sh: Exclude the macro from default testing.
* NEWS: Update.

Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
This commit is contained in:
Ralf Wildenhues 2011-04-02 14:52:20 +02:00
parent ac427166c5
commit 1c3373c5f0
7 changed files with 252 additions and 21 deletions

View File

@ -1,5 +1,14 @@
2011-04-02 Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
New macro AC_FC_PP_SRCEXT for preprocessed file extensions.
* lib/autoconf/fortran.m4 (AC_FC_PP_SRCEXT): New macro.
* lib/autom4te.in (Automake-preselections): Preselect it.
* doc/autoconf.texi (Fortran Compiler): Document it, rewriting
the documentation for AC_FC_SRCEXT along the way.
* tests/fortran.at (AC_FC_PP_SRCEXT usage): New test.
* tests/mktests.sh: Exclude the macro from default testing.
* NEWS: Update.
New macro AC_FC_MODULE_OUTPUT_FLAG: module output directory.
* lib/autoconf/fortran.m4 (AC_FC_MODULE_OUTPUT_FLAG): New macro.
* doc/autoconf.texi (Fortran Compiler): Document it.

1
NEWS
View File

@ -19,6 +19,7 @@ GNU Autoconf NEWS - User visible changes.
AC_FC_MODULE_EXTENSION to compute the Fortran 90 module name extension
AC_FC_MODULE_FLAG for the Fortran 90 module search path flag
AC_FC_MODULE_OUTPUT_FLAG for the Fortran 90 module output directory flag
AC_FC_PP_SRCEXT for preprocessed Fortran source files extensions
* Noteworthy changes in release 2.68 (2010-09-22) [stable]
Released by Eric Blake, based on git versions 2.67.*.

View File

@ -8198,47 +8198,68 @@ to call Fortran routines from some language other than C/C++.
@defmac AC_FC_SRCEXT (@var{ext}, @ovar{action-if-success}, @
@dvar{action-if-failure, AC_MSG_FAILURE})
@defmacx AC_FC_PP_SRCEXT (@var{ext}, @ovar{action-if-success}, @
@dvar{action-if-failure, AC_MSG_FAILURE})
@acindex{FC_SRCEXT}
@acindex{FC_PP_SRCEXT}
@caindex fc_srcext_@var{ext}
@caindex fc_pp_srcext_@var{ext}
By default, the @code{FC} macros perform their tests using a @file{.f}
extension for source-code files. Some compilers, however, only enable
newer language features for appropriately named files, e.g., Fortran 90
features only for @file{.f90} files. On the other hand, some other
compilers expect all source files to end in @file{.f} and require
special flags to support other file name extensions. The
@code{AC_FC_SRCEXT} macro deals with both of these issues.
features only for @file{.f90} files, or preprocessing only with
@file{.F} files or maybe other upper-case extensions. On the other
hand, some other compilers expect all source files to end in @file{.f}
and require special flags to support other file name extensions. The
@code{AC_FC_SRCEXT} and @code{AC_FC_PP_SRCEXT} macros deal with these
issues.
The @code{AC_FC_SRCEXT} tries to get the @code{FC} compiler to accept files
ending with the extension .@var{ext} (i.e., @var{ext} does @emph{not}
contain the dot). If any special compiler flags are needed for this, it
stores them in the output variable @code{FCFLAGS_}@var{ext}. This
extension and these flags are then used for all subsequent @code{FC} tests
(until @code{AC_FC_SRCEXT} is called again).
The @code{AC_FC_SRCEXT} macro tries to get the @code{FC} compiler to
accept files ending with the extension @file{.@var{ext}} (i.e.,
@var{ext} does @emph{not} contain the dot). If any special compiler
flags are needed for this, it stores them in the output variable
@code{FCFLAGS_@var{ext}}. This extension and these flags are then used
for all subsequent @code{FC} tests (until @code{AC_FC_SRCEXT} or
@code{AC_FC_PP_SRCEXT} is called another time).
For example, you would use @code{AC_FC_SRCEXT(f90)} to employ the
@file{.f90} extension in future tests, and it would set the
@code{FCFLAGS_f90} output variable with any extra flags that are needed
to compile such files.
The @code{FCFLAGS_}@var{ext} can @emph{not} be simply absorbed into
@code{FCFLAGS}, for two reasons based on the limitations of some
compilers. First, only one @code{FCFLAGS_}@var{ext} can be used at a
Similarly, the @code{AC_FC_PP_SRCEXT} macro tries to get the @code{FC}
compiler to preprocess and compile files with the extension
@file{.@var{ext}}. When both @command{fpp} and @command{cpp} style
preprocessing are provided, the former is preferred, as the latter may
treat continuation lines, @code{//} tokens, and white space differently
from what some Fortran dialects expect. Conversely, if you do not want
files to be preprocessed, use only lower-case characters in the file
name extension. Like with @code{AC_FC_SRCEXT(f90)}, any needed flags
are stored in the @code{FCFLAGS_@var{ext}} variable.
The @code{FCFLAGS_@var{ext}} flags can @emph{not} be simply absorbed
into @code{FCFLAGS}, for two reasons based on the limitations of some
compilers. First, only one @code{FCFLAGS_@var{ext}} can be used at a
time, so files with different extensions must be compiled separately.
Second, @code{FCFLAGS_}@var{ext} must appear @emph{immediately} before
Second, @code{FCFLAGS_@var{ext}} must appear @emph{immediately} before
the source-code file name when compiling. So, continuing the example
above, you might compile a @file{foo.f90} file in your makefile with the
command:
@example
foo.o: foo.f90
$(FC) -c $(FCFLAGS) $(FCFLAGS_f90) '$(srcdir)/foo.f90'
$(FC) -c $(FCFLAGS) $(FCFLAGS_f90) '$(srcdir)/foo.f90'
@end example
If @code{AC_FC_SRCEXT} succeeds in compiling files with the @var{ext}
extension, it calls @var{action-if-success} (defaults to nothing). If
it fails, and cannot find a way to make the @code{FC} compiler accept such
files, it calls @var{action-if-failure} (defaults to exiting with an
error message).
If @code{AC_FC_SRCEXT} or @code{AC_FC_PP_SRCEXT} succeeds in compiling
files with the @var{ext} extension, it calls @var{action-if-success}
(defaults to nothing). If it fails, and cannot find a way to make the
@code{FC} compiler accept such files, it calls @var{action-if-failure}
(defaults to exiting with an error message).
The @code{AC_FC_SRCEXT} and @code{AC_FC_PP_SRCEXT} macros cache their
results in @code{ac_cv_fc_srcext_@var{ext}} and
@code{ac_cv_fc_pp_srcext_@var{ext}} variables, respectively.
@end defmac
@defmac AC_FC_FREEFORM (@ovar{action-if-success}, @dvar{action-if-failure, @

View File

@ -1176,6 +1176,105 @@ AC_LANG_POP(Fortran)dnl
])# AC_FC_SRCEXT
# AC_FC_PP_SRCEXT(EXT, [ACTION-IF-SUCCESS], [ACTION-IF-FAILURE])
# --------------------------------------------------------------
# Like AC_FC_SRCEXT, set the source-code extension used in Fortran (FC) tests
# to EXT (which defaults to f). Also, look for any necessary additional
# FCFLAGS needed to allow this extension for preprocessed Fortran, and store
# them in the output variable FCFLAGS_<EXT> (e.g. FCFLAGS_f90 for EXT=f90).
# If successful, call ACTION-IF-SUCCESS. If unable to compile preprocessed
# source code with EXT, call ACTION-IF-FAILURE, which defaults to failing with
# an error message.
#
# Some compilers allow preprocessing with either a Fortran preprocessor or
# with the C preprocessor (cpp). Prefer the Fortran preprocessor, to deal
# correctly with continuation lines, `//' (not a comment), and preserve white
# space (for fixed form).
#
# (The flags for the current source-code extension, if any, are stored in
# $ac_fcflags_srcext and used automatically in subsequent autoconf tests.)
#
# For ordinary extensions like f90, etcetera, the modified FCFLAGS
# are needed for IBM's xlf*. Also, for Intel's ifort compiler, the
# $FCFLAGS_<EXT> variable *must* go immediately before the source file on the
# command line, unlike other $FCFLAGS. Ugh.
#
# Known extensions that enable preprocessing by default, and flags to force it:
# GNU: .F .F90 .F95 .F03 .F08, -cpp for most others,
# -x f77-cpp-input for .f77 .F77; -x f95-cpp-input for gfortran < 4.4
# SGI: .F .F90, -ftpp or -cpp for .f .f90, -E write preproc to stdout
# -macro_expand enable macro expansion everywhere (with -ftpp)
# -P preproc only, save in .i, no #line's
# SUN: .F .F95, -fpp for others; -xpp={fpp,cpp} for preprocessor selection
# -F preprocess only (save in lowercase extension)
# IBM: .F .F77 .F90 .F95 .F03, -qsuffix=cpp=EXT for extension .EXT to invoke cpp
# -WF,-qnofpp -WF,-qfpp=comment:linecont:nocomment:nolinecont
# -WF,-qlanglvl=classic or not -qnoescape (trigraph problems)
# -d no #line in output, -qnoobject for preprocessing only (output in .f)
# -q{no,}ppsuborigarg substitute original macro args before expansion
# HP: .F, +cpp={yes|no|default} use cpp, -cpp, +cpp_keep save in .i/.i90
# PGI: -Mpreprocess
# Absoft: .F .FOR .F90 .F95, -cpp for others
# Cray: .F .F90 .FTN, -e Z for others; -F enable macro expansion everywhere
# Intel: .F .F90, -fpp for others, but except for .f and .f90, -Tf may also be
# needed right before the source file name
# PathScale: .F .F90 .F95, -ftpp or -cpp for .f .f90 .f95
# -macro_expand for expansion everywhere, -P for no #line in output
# Lahey: .F .FOR .F90 .F95, -Cpp
# NAGWare: .F .F90 .F95, .ff .ff90 .ff95 (new), -fpp for others
# Compaq/Tru64: .F .F90, -cpp, -P keep .i file, -P keep .i file
# f2c: .F, -cpp
# g95: .F .FOR .F90 .F95 .F03, -cpp -no-cpp, -E for stdout
AC_DEFUN([AC_FC_PP_SRCEXT],
[AC_LANG_PUSH(Fortran)dnl
AC_CACHE_CHECK([for Fortran flag to compile preprocessed .$1 files],
ac_cv_fc_pp_srcext_$1,
[ac_ext=$1
ac_fcflags_pp_srcext_save=$ac_fcflags_srcext
ac_fcflags_srcext=
ac_cv_fc_pp_srcext_$1=unknown
case $ac_ext in #(
[[fF]]77) ac_try=f77-cpp-input;; #(
*) ac_try=f95-cpp-input;;
esac
for ac_flag in none -ftpp -fpp -Tf "-fpp -Tf" -xpp=fpp -Mpreprocess "-e Z" \
-cpp -xpp=cpp -qsuffix=cpp=$1 "-x $ac_try" +cpp -Cpp; do
test "x$ac_flag" != xnone && ac_fcflags_srcext="$ac_flag"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
#if 0
#include <ac_nonexistent.h>
choke me
#endif]])],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
#if 1
#include <ac_nonexistent.h>
choke me
#endif]])],
[],
[ac_cv_fc_pp_srcext_$1=$ac_flag; break])])
done
rm -f conftest.$ac_objext conftest.$1
ac_fcflags_srcext=$ac_fcflags_pp_srcext_save
])
if test "x$ac_cv_fc_pp_srcext_$1" = xunknown; then
m4_default([$3],
[AC_MSG_ERROR([Fortran could not compile preprocessed .$1 files])])
else
ac_fc_srcext=$1
if test "x$ac_cv_fc_pp_srcext_$1" = xnone; then
ac_fcflags_srcext=""
FCFLAGS_[]$1[]=""
else
ac_fcflags_srcext=$ac_cv_fc_pp_srcext_$1
FCFLAGS_[]$1[]=$ac_cv_fc_pp_srcext_$1
fi
AC_SUBST(FCFLAGS_[]$1)
$2
fi
AC_LANG_POP(Fortran)dnl
])# AC_FC_PP_SRCEXT
# AC_FC_FREEFORM([ACTION-IF-SUCCESS], [ACTION-IF-FAILURE = FAILURE])
# ------------------------------------------------------------------
# Look for a compiler flag to make the Fortran (FC) compiler accept

View File

@ -44,6 +44,7 @@ args: --preselect AC_CONFIG_LIBOBJ_DIR
args: --preselect AC_CONFIG_LINKS
args: --preselect AC_FC_FREEFORM
args: --preselect AC_FC_SRCEXT
args: --preselect AC_FC_PP_SRCEXT
args: --preselect AC_INIT
args: --preselect AC_LIBSOURCE
args: --preselect AC_REQUIRE_AUX_FILE

View File

@ -714,6 +714,106 @@ AT_CHECK([$MAKE], [], [ignore], [ignore])
AT_CLEANUP
## ---------------------- ##
## AC_FC_PP_SRCEXT usage. ##
## ---------------------- ##
AT_SETUP([AC_FC_PP_SRCEXT usage])
AT_DATA([configure.ac],
[[AC_INIT
AC_PROG_FC
# Unconditionally require .f and .F to work.
AC_FC_PP_SRCEXT([f])
AC_FC_PP_SRCEXT([F])
# For each other extension, fail gracefully if it does not work:
# Not all compilers support all extensions/language versions.
m4@&t@_foreach([ext], [f77, f90, f95, f03, f08],
[AC_FC_PP_SRCEXT(ext, ext[_object='foo]ext[.$(OBJEXT)'], ext[_object=])
AC_SUBST(ext[_object])])
m4@&t@_foreach([ext], [F77, F90, F95, F03, F08],
[AC_FC_PP_SRCEXT(ext, ext[_object='bar]ext[.$(OBJEXT)'], ext[_object=])
AC_SUBST(ext[_object])])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
]])
AT_DATA([Makefile.in],
[[OBJEXT = @OBJEXT@
all: prog@EXEEXT@
prog@EXEEXT@: foof.@OBJEXT@ @f77_object@ @f90_object@ \
@f95_object@ @f03_object@ @f08_object@ \
barF.@OBJEXT@ @F77_object@ @F90_object@ \
@F95_object@ @F03_object@ @F08_object@
@FC@ @FCFLAGS@ -o $@ foof.@OBJEXT@ @f77_object@ @f90_object@ \
@f95_object@ @f03_object@ @f08_object@ \
barF.@OBJEXT@ @F77_object@ @F90_object@ \
@F95_object@ @F03_object@ @F08_object@
.SUFFIXES: .f .f77 .f90 .f95 .f03 .f08 .F .F77 .F90 .F95 .F03 .F08 .@OBJEXT@
.f.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_f@ $<
.f77.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_f77@ $<
.f90.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_f90@ $<
.f95.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_f95@ $<
.f03.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_f03@ $<
.f08.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_f08@ $<
.F.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_F@ $<
.F77.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_F77@ $<
.F90.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_F90@ $<
.F95.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_F95@ $<
.F03.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_F03@ $<
.F08.@OBJEXT@:
@FC@ -c @FCFLAGS@ @FCFLAGS_F08@ $<
]])
for ext in f77 f90 f95 f03 f08; do
cat > foo$ext.$ext <<EOF
subroutine foo$ext
#if 0
this is not correct fortran
#endif
end
EOF
done
for ext in F F77 F90 F95 F03 F08; do
cat > bar$ext.$ext <<EOF
subroutine bar$ext
#if 0
this is not correct fortran
#endif
end
EOF
done
AT_DATA([foof.f],
[[ program main
#if 0
this is not correct fortran
#endif
end
]])
AT_CHECK_AUTOCONF
AT_CHECK_CONFIGURE
: "${MAKE=make}"
AT_CHECK([$MAKE], [], [ignore], [ignore])
AT_CLEANUP
## --------------- ##
## AC_FC_FREEFORM. ##
## --------------- ##

View File

@ -100,7 +100,7 @@ ac_exclude_list='
# Produce "= val" because $1, the variable used to store the result,
# is empty.
/^AC_(F77|FC)_FUNC$/ {next}
/^AC_FC_SRCEXT$/ {next}
/^AC_FC_(PP_)?SRCEXT$/ {next}
/^AC_PATH_((TARGET_)?TOOL|PROG)S?$/ {next}
# Is a number.