Automatic Make recipes generation

Great work! This is a very worthwhile project.

It would be a nice project to expose the fpm module scanner as a Make target dependency generator, or vice-versa, allow mk-fdeps to be used from fpm. In fpm the module dependency scanning is accomplished here: fpm_source_parsing.f90

There is a long “tradition” of writing tools like makedepend or mkdep. Major Make texts dedicate entire chapters to the use of such tools:

The make dependency topic was a perennial topic on comp.lang.fortran in the 90s (when Fortran modules were introduced). It also pops up regularly here on Fortran Discourse. See some of my previous posts:

I’ve compiled a table of existing tools below (in no particular order)

Tool Implemented in Comment
makedepf90 C, Lex By Erik Edelmann from CSC (Finnish IT Center for Science)
fpt Fortran Commercial tool from SimCon (by @Jcollins)
AUTOMAKE ? From the PlusFORT toolkit (by @apple3feet)
mkmf Perl Developed at NOAA GFDL
makemake Perl
makedepf08.awk Awk
gen-deps.awk Awk Form the Fortran-lang Make tutorial
FF08Depends Fortran By Ian Harvey
ifx -gen-dep ? Built-in (Intel Fortran compiler)
nagfor =depend ? Built-in (NAG compiler)
ftnmgen ? HPE Cray Compiler Environment
fdep Perl From the ELPA project
fort_depend.py Python By @zedthree
run-fortran Python
mkhelper Python, Shell
fortdep Python By @gronki
f90_mod_deps.py Python
fake Bash
findent ? Can also generate dependency information
CMake C++/C (?) uses an extended version of makedepf90, more information here
fpm Fortran doesn’t expose Makefile target generation
mk-fdeps Fortran Topic of this thread

A couple more tools are listed at the Fortran Wiki Build Tools page and @Beliavsky’s Fortran Tools list. guess that SCons and Meson also have their own Fortran module dependency scanners. AFAIK, IDEs like SimplyFortran and Code::Blocks (CBFortran?) also support Makefile generation. Many large Fortran projects (e.g. CPMD) still maintain custom scripts. It’s a bit of a tragedy that this has been re-invented so many times, likely due to a mix of “Not Invented Here” syndrome and also a historical lack of centralized tooling in the Fortran world.

Most of these tools eventually struggle with the same issue, as Brad King (Kitware) noted:

My concern with trying to parse the module function grammar is that it is huge and any partial implementation will inevitably run into cases it doesn’t handle and then the solution will be “just add this one little bit more” repeated over and over.

Eventually the tools fall into disrepair or fail on newer features like submodules. In the same thread, but a different post, Brad King noted:

In the long term, I’d like to see Fortran compilers adopt the approach we’ve proposed for C++ module dependencies in P1689r4.

The situation in Fortran mirrors the C/UNIX world. As Eric Raymond writes in TAOUP,

Each different makefile generator tackles these objectives in a slightly different way. Probably a dozen or more generators have been attempted, but most proved inadequate or too difficult to drive or both, and only a few are still in live use.

C++20 module dependencies are in a similar (broken?) state. Here is one view of the C++ module problems: Nibble Stew: We need to seriously think about what to do with C++ modules (HN discussion available here)

Will we ever reach that “long-term” solution, where the module dependency scanners are flexible, robust, and widely available? What can we do differently as a community?

7 Likes