Skip to main content

Automatically generate Fortran dependencies

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fortdepend-2.3.2.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

fortdepend-2.3.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file fortdepend-2.3.2.tar.gz.

File metadata

  • Download URL: fortdepend-2.3.2.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for fortdepend-2.3.2.tar.gz
Algorithm Hash digest
SHA256 dfd165659315c284ecff4669e8b84471c6a1580cf42f165bdb3b837ecd6e105c
MD5 d62adfbfc9fe78bec66b8d298fd1be35
BLAKE2b-256 b656a87a4418a0c298e1a200e650986ea9743974128cf1a66ce97a429226775e

See more details on using hashes here.

File details

Details for the file fortdepend-2.3.2-py3-none-any.whl.

File metadata

  • Download URL: fortdepend-2.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for fortdepend-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 43d77f22e3ab8096bb5c475cd1dbe8e72921521fa6b0565b9b04b7bf5d6a32be
MD5 4bd264585cc7de40aa9d5c712ccf5c21
BLAKE2b-256 9d79bd987e02b66bf75bffe481e745d63538cd347cd876ef17120e257ae413e4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page