# Set the compiler
FORTRAN_COMPILER=gfortran

# Set the compiler options
#OPT1=" -Wuninitialized -Wimplicit-none -Wunused-vars -Wunset-vars -fbounds-check -ftrace=full -O2" --> They are for the g95 compiler

# OPT1=-g 
#OPT1=-pg -O3 
#OPT1= -O3 -g -finstrument-functions -lSaturn # Debug with saturn
#OPT1= -O3 -g 
#OPT1= -O3 -funroll-loops
#OPT1= -O3
OPT1= -O3 -funroll-loops  -ffast-math -fforce-addr -ffinite-math-only -fstrength-reduce -fexpensive-optimizations -fno-rerun-loop-opt



# Set Library flags
LIB_DIR = /usr/lib/
#LIBS    = -L/usr/lib -lblas -llapack 
LIBS = -lblas -llapack

# Set list of fortran Giv Weight files to compile
GWLIST = main.f90 length_iv.f90 end_iv.f90  eig_givweight.f90  retrievecolumn.f90 ST2.f90 ST.f90 refsor.f90 generate_representation.f90 givens.f90 constructwindow.f90 qrstep.f90

GWLIST = main.f90 length_iv.f90 end_iv.f90  eig_givweight.f90  retrievecolumn.f90 ST2.f90 ST.f90 refsor.f90 generate_representation.f90 givens.f90 constructwindow.f90




# the -c flag is for compiling
# when .o files are in the list, they are linked but not recompiled

#-----------------------------------------------------------------------
#
# make allclean
#

cleanall:
	/bin/rm -f *.o solveHelm
	/bin/rm -f *.a

#-----------------------------------------------------------------------
#  make clean


clean:
	/bin/rm -f *.o 

#-----------------------------------------------------------------------
# Compile the whole programm and link with the quasi library
all: quasi 
	$(FORTRAN_COMPILER) $(GWLIST) -o run $(LIBS) -L. -lquasi $(OPT1)


# Compile (do not link lucas quasiseparable algorithm)
# And put in a library
# We will not change these files, so there is not often the need to recompile them
quasi:
	$(FORTRAN_COMPILER) -c fastqreigf.f90  isort.f ssort.f sort_eig.f90 eig_lapack.f90 find_partition.f90 planerot.f90 fast_DS.f90 findeig.f90 fast_SS.f90 deflate_all.f90 find_p_q.f90 $(OPT1)
	ar r libquasi.a isort.o fastqreigf.o ssort.o sort_eig.o eig_lapack.o find_partition.o planerot.o fast_DS.o findeig.o fast_SS.o deflate_all.o find_p_q.o


# Compile  and link the gw algorithm
# All at once since we are modifying these routines
gw: 
	$(FORTRAN_COMPILER) $(GWLIST) -o run $(LIBS) -L. -lquasi $(OPT1)



#----------------------------------------------------------------------
