.SUFFIXES:

# 
#  If you just want to switch off the default rule for Modula 2
#  you could use
# 
%.o : %.mod

# 
# Generate .o files from free format source files (assume  
# either a .f95 or .f90 suffix).
#
%.o: %.f90
	$(F90) $(F90FLAGS) -o $@ -c $<

##########################################
# Set compiler name and flags
##########################################
F90 = gfortran
F90FLAGS = -Wall -fcheck=all -g -fbacktrace -ffpe-trap=invalid,zero,overflow
F90LINKFLAGS = $(F90FLAGS)

executables = driver

all: $(executables)

driver: driver.o chainLinkMod.o set_precision.o
	$(F90) $(F90LINKFLAGS) -o $@ $^

driver.o: chainLinkMod.o set_precision.o

chainLinkMod.o: set_precision.o

# This target is for using gcov to measure both
# statement and decision coverage. It is only
# relevant if using gfortran.

chainLinkMod.f90.gcov: driver.f90 chainLinkMod.f90 set_precision.f90
	gfortran -Wall -fprofile-arcs -ftest-coverage -c -o set_precision.o set_precision.f90
	gfortran -Wall -fprofile-arcs -ftest-coverage -c -o chainLinkMod.o chainLinkMod.f90
	gfortran -Wall -fprofile-arcs -ftest-coverage -c -o driver.o driver.f90
	gfortran -Wall -fprofile-arcs -ftest-coverage -o driverGcov driver.o set_precision.o chainLinkMod.o
	./driverGcov
	gcov -b -a chainLinkMod.f90

.PHONY: clean
clean: 
	# remove all files generated by the compiler
	# these are compiler dependent
	rm -f *.o *.d *.g90 *.mod
	# remove all executables
	rm -f $(executables) driverGcov
