Can you elaborate what you mean? That’s exactly what CMake does, discover module dependencies and generate a Makefile. It uses the parser from makedepf90 (originally implemented using yacc and lex), which has been extended by hand to deal with new features of Fortran such as submodules. makedepf90 is a variant of the makedepend program but for Fortran instead of C.
The authors of CMake have explained the whole procedure in an article: How CMake supports Fortran modules and its applicability to C++
Scanners for Fortran module dependencies have been re-implemented several times by now:
- Sebastian (@awvwgk) wrote an Awk script that is part of the tutorial: An introduction to make — Fortran Programming Language
- fpm includes a
parse_f_source
function which could be exposed as a makedepend-like tool - FF08Depends by Ian Harvey (in Fortran)
- there are several Perl/Python/Awk scripts in various repositories: #1 (Perl), #2 (Perl), #3 (Awk), #4 (Python), #5 (Perl), #6 (Perl) …
- ifort/ifx and nagfor expose module dependency scanning options
- fpt (from SimCon) can do it, as can some IDEs (SimplyFortran)
The question how to correctly compile source files containing modules pops up constantly on Discourse, StackOverflow, and also on comp.lang.fortran. The following are from Fortran Discourse: