.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 .f90 suffix).
#
%.o: %.f90
	$(F95) $(F95FLAGS) -o $@ -c $<

#
# and for fixed format source (assume a .f suffix)
#
%.o: %.f
	$(F95) $(F77FLAGS) -o $@ -c $<

#
# Generate an executable file of the same filestem name as the
# source file containing the main program. For example, the
# executable driver would be generated by linking driver.o
# (obtained from driver.f or driver.f95 and containing the main
# program) with the required object files. For more details of
# how this works see the main Makefile. Assume that we link with
# the free format compiler flags.
#
%: %.o
	$(F95) $(F95LINKFLAGS) -o $@ $^ $(LIBS)

# Define the compiler and relevant flags
# NAG fortran
F95 = nagfor
F95FLAGS = -g -g90 -gline -u -nan -C=all -C=undefined -C=dangling
F77FLAGS = -g -g90 -gline -u -nan -C=all -C=undefined -C=dangling

# gfortran
#F95 = gfortran
#F95FLAGS = -Wall -fcheck=all -g -fbacktrace \
#           -ffpe-trap=invalid,zero,overflow
#F77FLAGS = -Wall -fcheck=all -g -fbacktrace \
#           -ffpe-trap=invalid,zero,overflow
#F95LINKFLAGS = $(F95FLAGS)
#F77LINKFLAGS = $(F77FLAGS)

vpath %.f90 ../Src
vpath %.f ../Support

executables = sample_main test_all

SUBS = EVAL_BSPLINE.o MQSI.o SPLINE.o REAL_PRECISION.o
LIBS = blas.o lapack.o

all: $(executables)

sample_main: sample_main.o $(SUBS)
	$(F95) $(F95LINKFLAGS) -o $@ $^ $(LIBS)

test_all: test_all.o  $(SUBS)
	$(F95) $(F95LINKFLAGS) -o $@ $^ $(LIBS)

SPLINE.o: REAL_PRECISION.o lapack.o

sample_main.o: REAL_PRECISION.o

test_all.o: REAL_PRECISION.o

MQSI.o: REAL_PRECISION.o lapack.o

EVAL_BSPLINE.o: REAL_PRECISION.o

lapack.o: blas.o

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