#
# 1) Using your favorite editor, uncomment the appropriate lines below
#    for your FORTRAN compiler (also be sure to comment out all of the 
#    lines corresponding to the other compilers).
#
# 2) From a command line shell, run:
#    % make clean
#    % make all 
#    % make install

# *** Windows *** 
# Also make sure you change the options -O3 to -O2 below when using gfortran

# ______________________________________________________________________________

# *** ifort
# These lines are used under Mac OSX; the syntax is different under Windows

# need -heap-arrays to avoid stack overflows for big runs ... 
# export FC=ifort
# export FFLAGS= -O3 -parallel -axSSE4.2 -nologo -inline-level=2 -assume byterecl -threads -heap-arrays -I../misc
# export FFLAGS= -O3 -parallel -nologo -inline-level=2 -assume byterecl -threads -heap-arrays -I../misc
# export FFLAGS= -O3 -parallel -axSSE4.2 -nologo -inline-level=2 -assume byterecl -threads -heap-arrays -I../misc

# -parallel off for export:
# export FFLAGS= -O3 -nologo -inline-level=2 -assume byterecl -threads -heap-arrays -I../misc

# compilation diagnostics on: 
# export FFLAGS= -O2 -nologo -inline-level=2 -assume byterecl -threads -heap-arrays -I../misc -check -traceback

# profiling:
# export FFLAGS= -g -nologo -inline-level=2 -assume byterecl -threads -heap-arrays -I../misc -check -traceback

# ______________________________________________________________________________

# *** GNU Compiler Collection GFORTRAN
# -O2 was the highest level of optimization that worked under Windows
export FC=gfortran
# export FFLAGS= -march=native -Wall -std=gnu -O2 -I../misc
# export FFLAGS= -march=native -Wall -std=gnu -O3 -I../misc
# export FFLAGS= -march=native -Wall -Waliasing -Wampersand -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -std=f2008 -O3 -ffast-math -funroll-all-loops -fomit-frame-pointer -mtune=native
export FFLAGS= -march=corei7 -std=f2008 -O3 -ffast-math -funroll-all-loops -fomit-frame-pointer -mtune=native

# compilation diagnostics on: 
# export FFLAGS= -march=native -Wall -std=gnu -O -fcheck=all -I../misc

# profiling:
# export FFLAGS= -gp -Wall -std=f95 -fbounds-check

# ______________________________________________________________________________

# *** g95 
# export FC=g95
# export FFLAGS= -Wall -std=f2003 -O3 -I../misc

# compilation diagnostics on: 
# export FFLAGS= -Wall -std=f2003 -ftrace=full -fbounds-check -I../misc

# ______________________________________________________________________________

# *** Portland Group FORTRAN
# -Mnoframe caused erroneous results
# -Munroll  caused erroneous results
# these are defaults under -fast, so can't use -fast either
# export FC=pgfortran
# export FFLAGS= -Mconcur -I../misc
# export FFLAGS= -fast -I../misc
# export FFLAGS= -O2 -Munroll=c:1 -Mnoframe -Mlre -Mpre -Mvect=sse -Mcache_align -Mflushz -Mvect -I../misc
# export FFLAGS= -O2 -Mlre -Mpre -Mvect=sse -Mcache_align -Mflushz -Mvect -I../misc

# compilation diagnostics on:
# export FFLAGS= -g -Minfo=ccff -Minform=inform -C -I../misc

# ______________________________________________________________________________

export RM=rm
export CC=gcc
export CFLAGS=-g


EXECUTABLES = for3d.exe

FOR3D_OBJECTS = for3d.o params.o commons.o subs.o WriteHeader.o

all: $(EXECUTABLES)
	@echo "FOR3D built"
	@echo "*************"
	@echo " "

install: all
	for f in $(EXECUTABLES) ; do \
		echo "----- Installing $$f"; cp -p $$f ../bin; \
	done

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

# Declare implicit rules (for make utilities with missing or broken build rules)

#.SUFFIXES: .o .mod .for .f90
.SUFFIXES: .o .mod .f90

#.for.o:
#	$(FC) -c $(FFLAGS) $< 
#
.f90.o:
	$(FC) -c $(FFLAGS) $< 

.f90.mod:
	$(FC) -c $(FFLAGS) $< 

# Declare explicit dependencies (and explicit build rules as needed)

for3d.exe: $(FOR3D_OBJECTS)
	$(FC) -o $@ $(FFLAGS) $(FOR3D_OBJECTS)

commons.o commons.mod: commons.f90
	$(FC) -c $(FFLAGS) $< 

params.o params.mod: params.f90
	$(FC) -c $(FFLAGS) $< 

#for3d.o: params.mod commons.mod subs.o WriteHeader.o for3d.for
for3d.o: params.mod commons.mod subs.o WriteHeader.o for3d.f90

#subs.o: subs.for
subs.o: subs.f90
WriteHeader.o: WriteHeader.f90
