# Ways to suppress Circularity

**URL:** <https://fortran-lang.discourse.group/t/ways-to-suppress-circularity/8620>\
**Category:** Uncategorized\
**Created:** [September 18, 2024, 4:34pm UTC](https://fortran-lang.discourse.group/t/ways-to-suppress-circularity/8620 "2024-09-18T16:34:27Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [September 18, 2024, 5:05pm UTC](https://fortran-lang.discourse.group/t/ways-to-suppress-circularity/8620/2 "2024-09-18T17:05:01Z")

</div>

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

```fortran
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:

```txt
target: ... dependencies...
    rule

```

For the second type of “circularity” you may want to review the following threads:

- [Module dependencies](https://fortran-lang.discourse.group/t/module-dependencies/1194)
- [How do you generate file dependence when writing Makefile?](https://fortran-lang.discourse.group/t/how-do-you-generate-file-dependence-when-writing-makefile/2125)
- [Gfortran and .smod files](https://fortran-lang.discourse.group/t/gfortran-and-smod-files/6909)
- [Module dependencies in cmake not tracked after a module is updated](https://fortran-lang.discourse.group/t/module-dependencies-in-cmake-not-tracked-after-a-module-is-updated/4202)
- [Order of modules in a Fortran program](https://fortran-lang.discourse.group/t/order-of-modules-in-a-fortran-program/5130)

Edit: some compilers come with a built-in module scanner you can use

- Intel Fortran compiler: [`-gen-dep`](https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-2/gen-dep.html) [`-syntax-only`](https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2024-2/syntax-only.html#GUID-A25A8CAE-01BE-4565-A425-BAE46CFE631D)
- NAG Fortran compiler: [`=depend`](https://support.nag.com/nagware/np/r72_doc/nagfor.html#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](https://aoterodelaroza.github.io/devnotes/modern-fortran-makefiles/)
- [An introduction to make — Fortran Programming Language](https://fortran-lang.org/learn/building_programs/project_make/#automatically-generated-dependencies)

Since GNU Make 4.3 it is also possible define [grouped targets](https://www.gnu.org/software/make/manual/html_node/Multiple-Targets.html) with the `&:` syntax, which could be used instead of dependency files.

---

_[View the full topic](https://fortran-lang.discourse.group/t/ways-to-suppress-circularity/8620)._
