makedepf90(1) | General Commands Manual | makedepf90(1) |
makedepf90 - creates Makefile dependency list for Fortran source files.
makedepf90 [-h] [-V] [-W|-Wmissing] [-Wconfused] [-m fmt] [-u modulename] [-d file] [-r rule] [-R file rule] [-fixed|-free] [-o name-of-executable] [-coco] [-D NAME] [-b|-B path] [-I PATH1:PATH2:...] [-nosrc] sourcefile(s)
makedepf90 is a program for automatic creation of dependency lists and compilation rules for Makefiles.
The original idea was to provide the same functionality for Fortran as
gcc -MM *.c
does for C. Nowadays makedepf90 actually supersedes this functionality, making me wonder if I should extend makedepf90 to support C and C++ too ;-).
makedepf90 supports both modules, include:s, cpp(1) #include:s, f90ppr(1) $include:s and coco(1) ??includes and set-files.
makedepf90 reads Fortran source files given on the command line, and writes a dependency list to stdout; for every file it writes a line with the following format:
targets : prerequisites
Targets are the files that will be the result of compiling the file with the -c option, and prerequisites are files that are needed to compile the file. In addition, makedepf90 can optionally create the dependency line and make-rule needed to link the final executable.
The files needed to compile a file, i.e the prerequisites of the file are:
Since different compilers use different naming conventions for the mod-files, listing them in the dependency list results in non-portable makefiles. Therefore it's common practise to list the object file (filename.o) corresponding to the sourcefile containing the USEd modules instead. This is the default behaviour of makedepf90. To change this, use the -m option (e.g -m "%m.mod" if your compiler names the mod files modulename.mod)
Include files not found in the working directory will not be listed in the dependency list, assuming they are part of a (seldom changing) library not part of the program. Neither will mod-files of modules whose definitions aren't found be listed by the same reason.
These options may be given anywhere, in any order, on the command line. Space between an option and its argument is optional. Options may not be grouped (-hW is not the same thing as -h -W).
Here's an example of basic makedepf90 usage together with make(1). Create a file named Makefile with the following contents:
----------------------
# FC = the compiler to use
FC=f90
# Compiler options
FFLAGS=-O
# List libraries used by the program here
LIBS=
# Suffix-rules: Begin by throwing away all old suffix-
# rules, and then create new ones for compiling
# *.f90-files.
.SUFFIXES:
.SUFFIXES: .f90 .o
.f90.o:
$(FC) -c $(FFLAGS) $<
# Include the dependency-list created by makedepf90 below
include .depend
# target 'clean' for deleting object- *.mod- and other
# unwanted files
clean:
rm -f *.o *.mod core
# Create a dependency list using makedepf90. All files
# that needs to be compiled to build the program,
# i.e all source files except include files, should
# be given on the command line to makedepf90.
#
# The argument to the '-o' option will be the name of the
# resulting program when running 'make', in this case
# 'foobar'
depend .depend:
makedepf90 -o foobar *.f90 > .depend
-----------------------
(Note that all the indented lines should be indented with tabs, not spaces)
With this makefile, the command make should perform all the commands needed to compile and link the program foobar out of all *.f90 files in the working directory.
The dependency list .depend will be (re)created if .depend doesn't exist, or if the command make depend is run. This should be done every time changes has been made to the program that affect the dependencies of the files (e.g if new source files has been added to the project).
If you are using a pre-processor, things might get more complicated. If you are lucky, your compiler supports your pre-processor and runs it on your code automatically, but if it doesn't, you have to give the commands to run the pre-processor yourself. Below is an example of an Makefile for coco(1)-users.
-----------------------
FC=f90
FFLAGS=-O
PREPROCESSOR=coco
.SUFFIXES:
.SUFFIXES: .f .f90 .o
# Files ending in .f90 are compiled directly ...
.f90.o:
$(FC) -c $(FFLAGS) $<
# ... while those ending in .f are preprocessed first.
.f.o:
$(PREPROCESSOR) $*; $(FC) -c $(FFLAGS) $*.f90
include .depend
clean:
rm -f *.o *.mod core
depend .depend:
makedepf90 -coco -o foobar *.f90 *.f > .depend
-----------------------
NOTE: Some implementations of make(1) will not execute any commands — not even make depend — with the Makefiles above unless there exists a file named .depend. To overcome this problem, either run makedepf90 manually, or begin by creating an empty .depend file with the command touch .depend.
Most error and warning messages are self explanatory, but some of them might need some further explanations:
Makedepf90's support for pre processor conditionals and macro expension (#if:s, #define:s etc) is rather weak, but should work well enough for most cases.
The include file search algorithm is broken. I may fix it some day.
make(1), f90(1), cpp(1), fpp(1), f90ppr(1), coco(1)
The makedepf90 web site is found at
http://www.iki.fi/erik.edelmann/makedepf90
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Erik Edelmann <Erik.Edelmann@iki.fi>
Tue, 17 Nov 2015 23:21:02 -0500 |