How to create a makefile for a Fortran program using modules
<p>The challenge is to create a makefile which takes a list of modules and does not require me to sort out precendence. For example, the modules are</p>

<pre><code>mod allocations.f08     mod precision definitions.f08   mod unit values.f08
mod blocks.f08          mod shared.f08                  mod parameters.f08
mod timers.f08
</code></pre>

<p>The main program is <code>characterize.f08</code>. The error message is</p>

<p><code>Fatal Error: Can't open module file ‘mprecisiondefinitions.mod’ for reading at (1): No such file or directory</code></p>

<p>The first statement in the main program is <code>use mPrecisionDefinitions</code>, the module defined in <code>mod precision definitions.f08</code>.</p>

<p>The following makefile, based upon <a href="https://stackoverflow.com/questions/5871780/creating-a-fortran-makefile">Creating a FORTRAN makefile</a>, is:</p>

<pre><code># compiler
FC := /usr/local/bin/gfortran

# compile flags
FCFLAGS = -g -c -Wall -Wextra -Wconversion -Og -pedantic -fcheck=bounds -fmax-errors=5
# link flags
FLFLAGS =

# source files and objects
SRCS = $(patsubst %.f08, %.o, $(wildcard *.f08))

# program name
PROGRAM = a.out

all: $(PROGRAM)

$(PROGRAM): $(SRCS)
    $(FC) $(FLFLAGS) -o $@ $^

%.mod: %.f08
    $(FC) $(FCFLAGS) -o $@ $&lt;

%.o: %.f08
    $(FC) $(FCFLAGS) -o $@ $&lt;

clean:
    rm -f *.o *.mod
</code></pre>