Go to the first, previous, next, last section, table of contents.
F77
is not already
set in the environment, then check for g77
and f77
, and
then some other names. Set the output variable F77
to the name
of the compiler found.
This macro may, however, be invoked with an optional first argument
which, if specified, must be a space separated list of Fortran 77
compilers to search for. This just gives the user an opportunity to
specify an alternative search list for the Fortran 77 compiler. For
example, if you didn't like the default order, then you could invoke
AC_PROG_F77
like this:
AC_PROG_F77(fl32 f77 fort77 xlf cf77 g77 f90 xlf90)
If using g77
(the GNU Fortran 77 compiler), then
AC_PROG_F77
will set the shell variable G77
to `yes'.
If the output variable FFLAGS
was not already set in the
environment, then set it to @option{-g -02} for g77
(or @option{-O2}
where g77
does not accept @option{-g}). Otherwise, set
FFLAGS
to @option{-g} for all other Fortran 77 compilers.
F77_NO_MINUS_C_MINUS_O
if it
does not.
The following macros check for Fortran 77 compiler characteristics. To
check for characteristics not listed here, use AC_TRY_COMPILE
(see section Examining Syntax) or AC_TRY_RUN
(see section Checking Run Time Behavior),
making sure to first set the current language to Fortran 77
AC_LANG(Fortran 77)
(see section Language Choice).
FLIBS
is set to these flags.
This macro is intended to be used in those situations when it is necessary to mix, e.g. C++ and Fortran 77 source code into a single program or shared library (see section `Mixing Fortran 77 With C and C++' in GNU Automake).
For example, if object files from a C++ and Fortran 77 compiler must be linked together, then the C++ compiler/linker must be used for linking (since special C++-ish things need to happen at link time like calling global constructors, instantiating templates, enabling exception support, etc.).
However, the Fortran 77 intrinsic and run-time libraries must be linked
in as well, but the C++ compiler/linker doesn't know by default how to
add these Fortran 77 libraries. Hence, the macro
AC_F77_LIBRARY_LDFLAGS
was created to determine these Fortran 77
libraries.
The macro AC_F77_DUMMY_MAIN
or AC_F77_MAIN
will probably
also be necessary to link C/C++ with Fortran; see below.
AC_F77_LIBRARY_LDFLAGS
provide their own main
entry
function that initializes things like Fortran I/O, and which then calls
a user-provided entry function named e.g. MAIN__
to run the
user's program. The AC_F77_DUMMY_MAIN
or AC_F77_MAIN
macro figures out how to deal with this interaction.
When using Fortran for purely numerical functions (no I/O, etcetera),
users often prefer to provide their own main
and skip the Fortran
library initializations. In this case, however, one may still need to
provide a dummy MAIN__
routine in order to prevent linking errors
on some systems. AC_F77_DUMMY_MAIN
detects whether any such
routine is required for linking, and what its name is; the shell
variable F77_DUMMY_MAIN
holds this name, unknown
when no
solution was found, and none
when no such dummy main is needed.
By default, action-if-found defines F77_DUMMY_MAIN
to the
name of this routine (e.g. MAIN__
) if it is required.
@ovar{action-if-not-found} defaults to exiting with an error.
In order to link with Fortran routines, the user's C/C++ program should then include the following code to define the dummy main if it is needed:
#ifdef F77_DUMMY_MAIN # ifdef __cplusplus extern "C" # endif int F77_DUMMY_MAIN() { return 1; } #endif
Note that AC_F77_DUMMY_MAIN
is called automatically from
AC_F77_WRAPPERS
; there is generally no need to call it explicitly
unless one wants to change the default actions.
AC_F77_DUMMY_MAIN
, many Fortran libraries
allow you to provide an entry point called e.g. MAIN__
instead of
the usual main
, which is then called by a main
function in
the Fortran libraries that initializes things like Fortran I/O. The
AC_F77_MAIN
macro detects whether it is possible to
utilize such an alternate main function, and defines F77_MAIN
to
the name of the function. (If no alternate main function name is found,
F77_MAIN
is simply defined to main
.)
Thus, when calling Fortran routines from C that perform things like I/O,
one should use this macro and name the "main" function F77_MAIN
instead of main
.
F77_FUNC(name,NAME)
and
F77_FUNC_(name,NAME)
to properly mangle the names of C/C++
identifiers, and identifiers with underscores, respectively, so that
they match the name-mangling scheme used by the Fortran 77 compiler.
Fortran 77 is case-insensitive, and in order to achieve this the Fortran
77 compiler converts all identifiers into a canonical case and format.
To call a Fortran 77 subroutine from C or to write a C function that is
callable from Fortran 77, the C program must explicitly use identifiers
in the format expected by the Fortran 77 compiler. In order to do this,
one simply wraps all C identifiers in one of the macros provided by
AC_F77_WRAPPERS
. For example, suppose you have the following
Fortran 77 subroutine:
subroutine foobar(x,y) double precision x, y y = 3.14159 * x return end
You would then declare its prototype in C or C++ as:
#define FOOBAR_F77 F77_FUNC(foobar,FOOBAR) #ifdef __cplusplus extern "C" /* prevent C++ name mangling */ #endif void FOOBAR_F77(double *x, double *y);
Note that we pass both the lowercase and uppercase versions of the
function name to F77_FUNC
so that it can select the right one.
Note also that all parameters to Fortran 77 routines are passed as
pointers (see section `Mixing Fortran 77 With C and C++' in GNU Automake).
Although Autoconf tries to be intelligent about detecting the
name-mangling scheme of the Fortran 77 compiler, there may be Fortran 77
compilers that it doesn't support yet. In this case, the above code
will generate a compile-time error, but some other behavior
(e.g. disabling Fortran-related features) can be induced by checking
whether the F77_FUNC
macro is defined.
Now, to call that routine from a C program, we would do something like:
{ double x = 2.7183, y; FOOBAR_F77(&x, &y); }
If the Fortran 77 identifier contains an underscore
(e.g. foo_bar
), you should use F77_FUNC_
instead of
F77_FUNC
(with the same arguments). This is because some Fortran
77 compilers mangle names differently if they contain an underscore.
AC_F77_WRAPPERS
). shellvar is
optional; if it is not supplied, the shell variable will be simply
name. The purpose of this macro is to give the caller a way to
access the name-mangling information other than through the C
preprocessor as above; for example, to call Fortran routines from some
language other than C/C++.
Go to the first, previous, next, last section, table of contents.