What type of “circularity” are we talking of?
1: actual circular dependencies among modules; these are not allowed AFAIK, but submodules can be used to bypass the issue in practice
module a
use b
end module
module b
use a
end module
2: build dependencies as required by (GNU) Make. For these you need a tool (let’s call it the module scanner) which determines the dependencies between modules and expresses them in the Make syntax:
target: ... dependencies...
rule
For the second type of “circularity” you may want to review the following threads:
- Module dependencies
- How do you generate file dependence when writing Makefile?
- Gfortran and .smod files
- Module dependencies in cmake not tracked after a module is updated
- Order of modules in a Fortran program
Edit: some compilers come with a built-in module scanner you can use
- Intel Fortran compiler:
-gen-dep
-syntax-only
- NAG Fortran compiler:
=depend
however, the output slightly differs which makes it harder to write a generic Makefile supporting multiple compilers.
For external scanners you could check the one at the links below (both are in Awk and use “dependency” files):
- Writing Makefiles for Modern Fortran | Alberto Otero-de-la-Roza
- An introduction to make — Fortran Programming Language
Since GNU Make 4.3 it is also possible define grouped targets with the &:
syntax, which could be used instead of dependency files.