#flags = -r8 -i8 -msse3 -O3 -axT -m64 -fPIC -i_dynamic -openmp
#Neuman flags
#flags = -O3 -r8 -i8 -openmp -msse3 -axSSSE3 -m64 -fPIC -i_dynamic
#Cluster_2(16.161) flags 


BLOCKSIZE?=32

TERMSPEC?=code_gen/terms.input

ifdef CHECK
flags += -fcheck=all
endif

ifdef DEBUG
flags += -g
else
flags += -O3
endif

flags += -cpp -DBLOCKSIZE=$(BLOCKSIZE) -Wall -ffree-line-length-0 -fdefault-integer-8 -fdefault-double-8 -fdefault-real-8 -march=native

compiler = mpif90


# Modules
MODULES += \
    m_openmpi.o\
    Compact.o\
    m_parameters.o\
    m_calculate.o\
    m_arrays.o\
    m_terms.o\
    post.o

# Objects
OBJ     = post_dns.o

# Data Objects
ODATA   = build_info.odata latex_equations.odata

Post_Cbar_FSD_Incomp : x-edge-cold-bc-uPrime-hybrid

x-edge-cold-bc-uPrime-hybrid : ${MODULES} ${OBJ} print_build_info.o ${ODATA}
	${compiler} -o x-edge-cold-bc-uPrime-hybrid ${flags} ${MODULES} ${OBJ} print_build_info.o ${ODATA}

${OBJ} : ${MODULES}

m_terms.f90 : code_gen/code_gen.py ${TERMSPEC} code_gen/resources/m_template.py
	python code_gen/code_gen.py ${TERMSPEC} > $@

%.o: %.f90
	${compiler} -c ${flags} $<

cleanAll: clean
	rm -f m_terms.f90

clean:
	rm -f *.o *.odata *.mod x-edge-cold-bc-uPrime-hybrid test_calculate test_compact build_info.txt latex_equations.txt

test : test_calculate
	./test_calculate

test_calculate : test_calculate.o
	${compiler} -o test_calculate ${flags} m_openmpi.o m_parameters.o Compact.o m_calculate.o test_calculate.o

test_calculate.o : m_openmpi.o m_parameters.o Compact.o m_calculate.o

test_compact : Compact.o test_compact.o
	${compiler} -o test_compact ${flags} Compact.o test_compact.o

test_compact.o : Compact.o

print_build_info.o : print_build_info.c
	gcc -c print_build_info.c

%.odata : %.txt
	ld -r -b binary -o $@ $<

build_info.txt : ${TEMSPEC}
	python code_gen/code_gen.py -b ${TERMSPEC} > $@

latex_equations.txt : ${TEMSPEC}
	python code_gen/code_gen.py -x ${TERMSPEC} > $@
