It is possible to use Fortran which has cpp-style directives within
it. Some Fortran compilers, such as g77
, can process these
directives internally, and so need no separate preprocessing stage; in
other cases, the code must be compiled indirectly, with a preprocessor
producing pure Fortran code which is only then passed to the compiler.
Because of the syntactical differences in the underlying languages,
however it is not always possible to do this using the cpp
program, and you may need help from a separate Fortran-specific
preprocessor.1
Automake's support for preprocessed Fortran is tightly bound to the
Autoconf AC_PROG_FPP
macro (introduced in version XXX), which
determines if the Fortran compiler can cope with preprocessor
directives, and if not finds a preprocessor which can. It looks for
files with a .F extension (the extension is configurable).
The AC_PROG_FPP
macro takes as argument a list of features that
you require a preprocessor to support (handling of -I and
-D options, and so on), and does one of two things:
AC_PROG_FPP
macro for more details, but note that the
@FPPDIRECT_TRUE@
and _FALSE
variables referred to
there are the implementation of an automake conditional, so that on
the (hopefully rare) occasions when you have to handle something by
hand in a Makefile.am, you can handle both direct and indirect
mode using a construction like:
if FPPDIRECT ## do things appropriate for direct mode else !FPPDIRECT ## do things appropriate for indirect mode endif !FPPDIRECT
Handling Ratfor is a type of preprocessing, but this is rather more straightforward. The file N.f is made automatically from N.r by a rule which runs just the preprocessor to convert a Ratfor source file into a strict Fortran 77 source file. The precise command used is as follows:
$(FC) $(AM_FCFLAGS) $(FCFLAGS) $(AM_RFLAGS) $(RFLAGS)
(or the corresponding alternatives for the F77 interface).
[1] There is no formal standard for Fortran preprocessors, but Sun have produced a preprocessor fpp, which is available for download at http://www.netlib.org/fortran/; this comes with a free-ish but not quite open-source licence. The documentation within that distribution is, in effect, a useful specification of a Fortran preprocessor syntax.