# compiler
FC  = gfortran

# compile flags
FCFLAGS = -g -fbacktrace -fno-align-commons -fcheck=all -Wconversion -Wextra \
       -Wconversion-extra -pedantic -fbounds-check -std=f2008 -funroll-loops \
       -ftree-vectorize -march=native  -Wsurprising 
# link flags
FLFLAGS =

# Suffix-rules:  Begin by throwing away all old suffix-
# rules, and then create new ones for compiling 
# *.f90-files.
.SUFFIXES:
.SUFFIXES: .f90 .o 


PGM = f01 f02 f03 f04 f05 f06 f07 f08 f09 f10 f11 f12

all : $(PGM)

f01 :  f01.o
f02 :  f02.o
f03 :  f03.o
f04.o : foo_mod.o
f04 :  f04.o foo_mod.o
f05 :  f05.o
f06 :  f06.o
f07 :  f07.o
f08 :  f08.o
f09 :  f09.o
f10 :  f10.o
f11 :  f11.o
f12 :  f12.o

# General rule for building prog from prog.o; $^ (GNU extension) is
# used in order to list additional object files on which the
# executable depends
%: %.o
		$(FC) $(FCFLAGS) -o $@ $^ $(LDFLAGS)

# General rules for building prog.o from prog.f90 or prog.F90; $< is
# used in order to list only the first prerequisite (the source file)
# and not the additional prerequisites such as module or include files
%.o: %.f90
	$(FC) $(FCFLAGS) -c $<

%.o: %.F90
		$(FC) $(FCFLAGS) -c $<

# Utility targets
.PHONY: clean veryclean

clean:
	rm -f *.o *.mod *.MOD

veryclean: clean
		rm -f *~ $(PROGRAMS)
