Templates of makefiles for Fortran programs and libraries
From the simplest case to more complex cases, makefiles for a Fortran program made up with:
- only one source file;
- two source files, without included file (no need for automatic creation of dependencies);
- at least three source files, in a single directory;
- source files in several directories.
Makefiles for a Fortran library made up with:
The above makefiles contain the description of your program or library: the names of inputs files, the directories where they are, the dependencies between them. The part that depends on the compiler is the definition of variables FC, FFLAGS, CPPFLAGS, LDFLAGS and LDLIBS.
The makefiles assume that you have chosen to name your Fortran files
with suffix .[fF]
. This is convenient because make already has in
its built-in database all the rules to compile and link Fortran files
with suffix .f
. The drawback of this choice is that Fortran
compilers usually assume that the suffix .f
means fixed-source form,
so you have to find the option of your compiler that says that files
are in free-source form and add it to the variable FFLAGS. If you want
your Fortran source files to have suffix .[fF]90
, see compilation
course
The makefiles use makedepf90 for the automatic generation of dependencies.
Debugging options for GFortran version 7. Debugging options for GFortran version 11.