Automake includes full support for Fortran 77.
Any package including Fortran 77 code must define the output variable F77 in configure.in; the simplest way to do this is to use the AC_PROG_F77 macro (). the section called “Fortran 77 and Autoconf”.
A few additional variables are defined when a Fortran 77 source file is seen:
The name of the Fortran 77 compiler.
Any flags to pass to the Fortran 77 compiler.
The maintainer's variant of FFLAGS.
Any flags to pass to the Ratfor compiler.
The maintainer's variant of RFLAGS.
The command used to actually compile a Fortran 77 source file. The file name is appended to form the complete command line.
The command used to actually link a pure Fortran 77 program or shared library.
Automake can handle preprocessing Fortran 77 and Ratfor source files in addition to compiling them[4]. Automake also contains some support for creating programs and shared libraries that are a mixture of Fortran 77 and other languages (the section called “Mixing Fortran 77 With C and C++”).
These issues are covered in the following sections.
N.f is made automatically from N.F or N.r. This rule runs just the preprocessor to convert a preprocessable Fortran 77 or Ratfor source file into a strict Fortran 77 source file. The precise command used is as follows:
$(F77) -F $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)
$(F77) -F $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)
N.o is made automatically from N.f, N.F or N.r by running the Fortran 77 compiler. The precise command used is as follows:
$(F77) -c $(AM_FFLAGS) $(FFLAGS)
$(F77) -c $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_FFLAGS) $(FFLAGS)
$(F77) -c $(AM_FFLAGS) $(FFLAGS) $(AM_RFLAGS) $(RFLAGS)
Automake currently provides limited support for creating programs and shared libraries that are a mixture of Fortran 77 and C and/or C++. However, there are many other issues related to mixing Fortran 77 with other languages that are not (currently) handled by Automake, but that are handled by other packages[5].
Automake can help in two ways:
Automatic selection of the linker depending on which combinations of source code.
Automatic selection of the appropriate linker flags (e.g. -L and -l) to pass to the automatically selected linker in order to link in the appropriate Fortran 77 intrinsic and run-time libraries.
These extra Fortran 77 linker flags are supplied in the output variable FLIBS by the AC_F77_LIBRARY_LDFLAGS Autoconf macro supplied with newer versions of Autoconf (Autoconf version 2.13 and later). .
If Automake detects that a program or shared library (as mentioned in some _PROGRAMS or _LTLIBRARIES primary) contains source code that is a mixture of Fortran 77 and C and/or C++, then it requires that the macro AC_F77_LIBRARY_LDFLAGS be called in configure.in, and that either $(FLIBS) or @FLIBS@ appear in the appropriate _LDADD (for programs) or _LIBADD (for shared libraries) variables. It is the responsibility of the person writing the Makefile.am to make sure that $(FLIBS) or @FLIBS@ appears in the appropriate _LDADD or _LIBADD variable.
For example, consider the following Makefile.am:
bin_PROGRAMS = foo foo_SOURCES = main.cc foo.f foo_LDADD = libfoo.la @FLIBS@ pkglib_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = bar.f baz.c zardoz.cc libfoo_la_LIBADD = $(FLIBS)
In this case, Automake will insist that AC_F77_LIBRARY_LDFLAGS is mentioned in configure.in. Also, if @FLIBS@ hadn't been mentioned in foo_LDADD and libfoo_la_LIBADD, then Automake would have issued a warning.
The following diagram demonstrates under what conditions a particular linker is chosen by Automake.
For example, if Fortran 77, C and C++ source code were to be compiled into a program, then the C++ linker will be used. In this case, if the C or Fortran 77 linkers required any special libraries that weren't included by the C++ linker, then they must be manually added to an _LDADD or _LIBADD variable by the user writing the Makefile.am.
\ Linker source \ code \ C C++ Fortran ----------------- +---------+---------+---------+ | | | | C | x | | | | | | | +---------+---------+---------+ | | | | C++ | | x | | | | | | +---------+---------+---------+ | | | | Fortran | | | x | | | | | +---------+---------+---------+ | | | | C + C++ | | x | | | | | | +---------+---------+---------+ | | | | C + Fortran | | | x | | | | | +---------+---------+---------+ | | | | C++ + Fortran | | x | | | | | | +---------+---------+---------+ | | | | C + C++ + Fortran | | x | | | | | | +---------+---------+---------+
The current Automake support for Fortran 77 requires a recent enough version Autoconf that also includes support for Fortran 77. Full Fortran 77 support was added to Autoconf 2.13, so you will want to use that version of Autoconf or later.
[4] Much, if not most, of the information in the following sections pertaining to preprocessing Fortran 77 programs was taken almost verbatim from .
[5] For example, http://www-zeus.desy.de/~burow/cfortran/the cfortran package addresses all of these inter-language issues, and runs under nearly all Fortran 77, C and C++ compilers on nearly all platforms. However, cfortran is not yet Free Software, but it will be in the next major release.