###### Makefile for ellipFor driver programs ######
## Instructions ##
# GNU Fortran: make gfortran
# Intel Fortran: make ifx
### Note for ifx compiler accessed via Intel oneAPI ###
# The appropriate script must be run in the terminal prior to using GNU Make
# e.g., source /opt/intel/oneapi/setvars.sh

# GNU Fortran
gfortran: FC = gfortran
gfortran: FOPTS = -flto -O3 -std=f2018
gfortran: ellipFor_test_driver test_material_driver
gfortran:
	echo $(FC) $(FOPTS)

# GNU Fortran Debug Mode
gfortran_debug: FC = gfortran
gfortran_debug: FOPTS = -Wall -std=f2018 -ffree-line-length-132 -g -fbacktrace -ffpe-trap='invalid,overflow,zero,underflow' -fbounds-check
gfortran_debug: ellipFor_test_driver test_material_driver
gfortran_debug:
	echo $(FC) $(FOPTS)

# Intel Fortran
ifx: FC = ifx
ifx: FOPTS = -ipo -O3
ifx: ellipFor_test_driver test_material_driver
ifx:
	echo $(FC) $(FOPTS)

# Use vpath patterns to pick up source files from
# other directory.
#
vpath %.f90 ../Src

# Generate .o files from free format source files (assume  
# either a .f95 or .f90 suffix).
#
%.o: %.f90
	$(FC) $(FOPTS) -o $@ -c $<

#
# Generate an executable file of the same filestem name as the
# source file containing the main program. 
%: %.o
	$(F95) $(FOPTS) -o $@ $^

executables = test_material_driver ellipFor_test_driver

all: $(executables)

test_material_driver: kind_parameters.o xelbdj2_all_routines.o xgscd_routines.o elliptic.o test_material_driver.o 
	$(FC)  -o $@ $^

test_material_driver.o:  kind_parameters.o elliptic.o

ellipFor_test_driver: kind_parameters.o xelbdj2_all_routines.o xgscd_routines.o elliptic.o ellipFor_test_driver.o 
	$(FC)  -o $@ $^

ellipFor_test_driver.o: kind_parameters.o elliptic.o

elliptic.o: kind_parameters.o xelbdj2_all_routines.o xgscd_routines.o

xgscd_routines.o:  kind_parameters.o

xelbdj2_all_routines.o: kind_parameters.o

kind_parameters.o: 

clean:
	rm -f *.mod *.o 
	rm -f $(executables)
