SHELL=/bin/bash

MAXMEM = 1024
CPPFLAGS = -D_MAXMEM='$(MAXMEM)'
FFLAGS = -c
FC  = gfortran
LD  = $(FC)

# Targets.

OBJECTS = testmemory.o MemoryManagement.o 

testmem.x: $(OBJECTS) 
	$(LD) $(OBJECTS) -o $@

clean:
	rm *.o *.mod testmem.x

# Explicit rules.

.SUFFIXES: .o .f90 .F90

.F90.o:
	@if [ $@ == 'MemoryManagement.f90' ]; then echo -e '\nSetting maximum memory available to be $(MAXMEM) MB.\n'; fi
	$(FC) $(CPPFLAGS) $(FFLAGS) $< -o $@

.f90.o:
	$(FC) $(FFLAGS) $< -o $@

.mod:
	$(FC) $<

# Dependencies.

testmemory.o: memorymanager.mod
memorymanager.mod: MemoryManagement.o
