# Next one is always good, but is not the default.  See Gnu make document.
.DELETE_ON_ERROR:
# The code uses implicit declarations throughout, so -Wimplicit is no
# good.
# The compiler generates spurious notes about "unused variable
# 'cont'", so -Wunused is no good.
# -Wsurprising complains about -a*b, so that's no good.
# We need -fno-automatic, at least for kend in caguts.f.
# We mark mainFixed.f as non-writable because I keep accidentally
# editing it when I'm fixing bugs.
# -fbounds-check is good when debugging.
# Invoke perl explicitly to run fixinclude without any hint about what
# path to use.  This is most likely to work on a foreign system.

# It's good to be able to generate multiple executables with multiple
# compilers to be able to track down compiler optimization bugs.
# For example:
#    make fullbuild G77=g77 
#    make fullbuild G77=g77-3.2 SUFFIX=3.2
# Then run brennermd2.95 and brennermd3.2 and compare the outputs.

ifndef G77
   G77:=g77
endif
export G77

ifndef SUFFIX
   SUFFIX:=
endif
export SUFFIX

G77_WITH_OPTS = $(G77) -W -fno-automatic

# The slow part here is inovking g77.
brennermd$(SUFFIX): mainFixed$(SUFFIX).o paramFixed$(SUFFIX).o
	@#For production:
	$(G77_WITH_OPTS) mainFixed$(SUFFIX).o paramFixed$(SUFFIX).o -o brennermd$(SUFFIX)
	@#For debugging:
	@#g77 -g -fdebug-kludge -fbounds-check -W -fno-automatic $(shell pwd)/mainFixed.f -o brennermd

SEARCHPATH := . ../.. ../../Include ../Bond_Order ../Tight_Binding \
              ../Lennard_Jones

# Always try regenerating mainFixed.f.  The fixinclude script does the
# right thing if the file is unchanged.
.PHONY: mainFixed.f
mainFixed.f:
	perl fixinclude mainFixed.f main.f $(SEARCHPATH)

.PHONY: paramFixed.f
paramFixed.f:
	perl fixinclude paramFixed.f ../Bond_Order/param.f $(SEARCHPATH)

# Don't optimize paramFixed.o.  G77 3.2 compiler bug.
paramFixed$(SUFFIX).o: paramFixed.f
	$(G77_WITH_OPTS) -c $(shell pwd)/paramFixed.f -o paramFixed$(SUFFIX).o

mainFixed$(SUFFIX).o: mainFixed.f
	$(G77_WITH_OPTS) -O2 -c $(shell pwd)/mainFixed.f -o mainFixed$(SUFFIX).o

.PHONY: clean
clean:
	-rm -f mainFixed.f paramFixed.f *.o brennermd*
