# The compiler
FC = gfortran

# flags for maximum performance
FCFLAGS = -O2

# flags forall (e.g. look for system .mod files) ... unused here
#FCFLAGS += -I/usr/include

# libraries needed for linking ... unused here
#LDFLAGS = -li_need_this_lib

# executables to be built within the package
PROGRAMS = pbinarymodel pspectra pdoptomog

# "make" builds all
all: $(PROGRAMS)

# dependencies
# mfunctions:
mfunctions.o: mconstants.o
# pbinarymodel:
pbinarymodel.o: mbinarymodel.o mfunctions.o mconstants.o
pbinarymodel: mbinarymodel.o mfunctions.o mconstants.o
# pspectra:
pspectra.o: mspectra.o mfunctions.o mconstants.o
pspectra: mspectra.o mfunctions.o mconstants.o
# pdoptomog:
pdoptomog.o: mdoptomog.o mfunctions.o mconstants.o
pdoptomog: mdoptomog.o mfunctions.o mconstants.o

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

# General rule for building *.o from *.f95 or *.F95; $< 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: %.f95
	$(FC) $(FCFLAGS) -c $<
%.o: %.F95
	$(FC) $(FCFLAGS) -c $<

# Utility targets
.PHONY: clean veryclean

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

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

