Skip to main content

fortdepend

Build Status codecov

A python script to automatically generate Fortran dependencies.

Given a set of files, fortdepend automatically constructs the dependency graph for the programs and files and can write a dependency file suitable for Makefiles. fortdepend now uses pcpp, a preprocessor written in Python, so it can determine which modules will actually be used when you compile.

You can even use fortdepend to draw the graph of the module dependencies (requires graphviz)!

Complete documentation is available on ReadTheDocs.

Original script by D. Dickinson

Installation

You can install fortdepend with pip:

pip3 install --user fortdepend

Limitations

fortdepend requires Python 3.

fortdepend works by looking for matching pairs of program <name>/end program <name> and module <name>/end module <name>, and so will not work on Fortran 77-style files that just use end without the appropriate label.

Usage

Basic usage:

fortdepend -o Makefile.dep

This will look for all files ending in .f90 or .F90 in the current directory and write the output to Makefile.dep. The output will something like this:

test :  \
        moduleA.o \
        moduleB.o \
        moduleC.o \
        moduleD.o \
        programTest.o

moduleA.o :

moduleB.o :  \
        moduleA.o

moduleC.o :  \
        moduleA.o \
        moduleB.o

moduleD.o :  \
        moduleC.o

You could then get a basic makefile working by putting the following in Makefile:

.f90.o:
    gfortran -c $<

test:
    gfortran $^ -o $@

include Makefile.dep

And make test will magically build everything in the correct order!

Move advanced use

You can specify preprocessor macros with -D and search paths with -I:

fortdepend -DMACRO=42 -Isome/include/dir -o Makefile.dep

will replace instances of MACRO with 42 according to the usual C99 preprocessor rules. This can be used to conditionally use some modules or change which module is used at compile time.

Full command line arguments:

$ fortdepend --help
usage: fortdepend [-h] [-f FILES [FILES ...]] [-D NAME[=DESCRIPTION]
                  [NAME[=DESCRIPTION] ...]] [-b BUILD] [-o OUTPUT] [-g] [-v]
                  [-w] [-c] [-e EXCLUDE_FILES [EXCLUDE_FILES ...]]
                  [-i IGNORE_MODULES [IGNORE_MODULES ...]]

Generate Fortran dependencies

optional arguments:
  -h, --help            show this help message and exit
  -f FILES [FILES ...], --files FILES [FILES ...]
                        Files to process
  -D NAME[=DESCRIPTION] [NAME[=DESCRIPTION] ...]
                        Preprocessor define statements
  -I dir                Add dir to the preprocessor search path
  -b BUILD, --build BUILD
                        Build Directory (prepended to all files in output)
  -o OUTPUT, --output OUTPUT
                        Output file
  -g, --graph           Make a graph of the project
  -v, --verbose         explain what is done
  -w, --overwrite       Overwrite output file without warning
  -c, --colour          Print in colour
  -e EXCLUDE_FILES [EXCLUDE_FILES ...], --exclude-files EXCLUDE_FILES [EXCLUDE_FILES ...]
                        Files to exclude
  -i IGNORE_MODULES [IGNORE_MODULES ...], --ignore-modules IGNORE_MODULES [IGNORE_MODULES ...]
                        Modules to ignore
  --skip-programs       Don't include programs in the output file
  -n, --no-preprocessor
                        Don't use the preprocessor

Here's a slightly more advanced example of how to use fortdepend in your makefiles:

# Script to generate the dependencies
MAKEDEPEND=/path/to/fortdepend

# $(DEP_FILE) is a .dep file generated by fortdepend
DEP_FILE = my_project.dep

# Source files to compile
OBJECTS = mod_file1.f90 \
          mod_file2.f90

# Make sure everything depends on the .dep file
all: $(actual_executable) $(DEP_FILE)

# Make dependencies
.PHONY: depend
depend: $(DEP_FILE)

# The .dep file depends on the source files, so it automatically gets updated
# when you change your source
$(DEP_FILE): $(OBJECTS)
    @echo "Making dependencies!"
    cd $(SRCPATH) && $(MAKEDEPEND) -w -o /path/to/$(DEP_FILE) -f $(OBJECTS)

include $(DEP_FILE)

This will automatically rebuild the dependency file if any of the source files change. You might not like to do this if you have a lot of files and need to preprocess them!

Release files for fortdepend 2.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fortdepend 2.3.2
File Size Uploaded
fortdepend-2.3.2.tar.gz 24.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fortdepend 2.3.2
File Interpreter ABI Platform
fortdepend-2.3.2-py3-none-any.whl Python 3 none any Details

Total release size:37.2 kB

Release files / fortdepend-2.3.2.tar.gz

Download URL fortdepend-2.3.2.tar.gz
Size 24.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dfd165659315c284ecff4669e8b84471c6a1580cf42f165bdb3b837ecd6e105c
BLAKE2b-256 checksum
How to use checksums
b656a87a4418a0c298e1a200e650986ea9743974128cf1a66ce97a429226775e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release files / fortdepend-2.3.2-py3-none-any.whl

Download URL fortdepend-2.3.2-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43d77f22e3ab8096bb5c475cd1dbe8e72921521fa6b0565b9b04b7bf5d6a32be
BLAKE2b-256 checksum
How to use checksums
9d79bd987e02b66bf75bffe481e745d63538cd347cd876ef17120e257ae413e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

2.3.2 This release

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page