include make_inc.LINUX_P4_GCC4

# Definitions for ADOL-C
# CHANGE THIS TO YOUR ADOL-C BASE DIRECTORY
ADPATH = $(ADOLC)/include/adolc
ADPATHa = $(ADOLC)/include
ADLIBDIR = $(ADOLC)/lib
ADCFLAGS = -I$(ADPATH) -I$(ADPATHa) 
ADLIBS = -Wl,--rpath -Wl,$(ADLIBDIR) -L$(ADLIBDIR) -ladolc 


#CFLAGS= $(OPTFLAGS)
CFLAGS= -g $(OPTFLAGS) $(ADCFLAGS)
#CFLAGS= $(DEBUGFLS)
#CFLAGS= -g -pg $(OPTFLAGS)

sources = $(shell ls *.c)

%.d: %.c
	set -e; $(CC) -M $(CFLAGS) $< \
	           | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
	       [ -s $@ ] || rm -f $@

all: test_navsto_solver


test_navsto_solver_derivpaper: test_navsto_solver_derivpaper.o \
		navsto_solver.o mesh_deform.o \
		mesh.o elements.o cubature.o \
		stokesassem.o navstoassem.o assembly.o \
		sparse.o lin_solver.o \
		stokes_aux.o navsto_aux.o gen_aux.o \
		navsto_adj.o triangle/triangle.o
	$(CC) -o test_navsto_solver_derivpaper $(CFLAGS) test_navsto_solver_derivpaper.o \
	navsto_solver.o mesh_deform.o \
	mesh.o elements.o cubature.o \
	stokesassem.o navstoassem.o assembly.o \
	sparse.o lin_solver.o \
	stokes_aux.o navsto_aux.o gen_aux.o \
	navsto_adj.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)


test_navsto_solver: test_navsto_solver.o \
		navsto_solver.o mesh_deform.o \
		mesh.o elements.o cubature.o \
		stokesassem.o navstoassem.o assembly.o \
		sparse.o lin_solver.o \
		stokes_aux.o navsto_aux.o gen_aux.o \
		navsto_adj.o triangle/triangle.o 
	$(CC) -o test_navsto_solver $(CFLAGS) test_navsto_solver.o \
	navsto_solver.o mesh_deform.o \
	mesh.o elements.o cubature.o \
	stokesassem.o navstoassem.o assembly.o \
	sparse.o lin_solver.o \
	stokes_aux.o navsto_aux.o gen_aux.o \
	navsto_adj.o  triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS) $(ADLIBS) 

test_navsto_solver_bcontrol: test_navsto_solver_bcontrol.o \
		navsto_solver_bcontrol.o mesh_deform.o \
		mesh.o elements.o cubature.o \
		stokesassem.o navstoassem.o assembly.o \
		sparse.o lin_solver.o \
		stokes_aux.o navsto_aux.o gen_aux.o \
		navsto_adj.o triangle/triangle.o
	$(CC) -o test_navsto_solver_bcontrol $(CFLAGS) \
	test_navsto_solver_bcontrol.o \
	navsto_solver_bcontrol.o mesh_deform.o \
	mesh.o elements.o cubature.o \
	stokesassem.o navstoassem.o assembly.o \
	sparse.o lin_solver.o \
	stokes_aux.o navsto_aux.o gen_aux.o \
	navsto_adj.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)

test_navstoMG: test_navstoMG.o mesh.o elements.o cubature.o stokesassem.o \
	sparse.o lin_solver.o stokes_aux.o \
	navsto_aux.o navstoassem.o assembly.o \
	navsto_adj.o triangle/triangle.o
	$(CC) -o test_navstoMG $(CFLAGS) test_navstoMG.o mesh.o \
		elements.o cubature.o stokesassem.o sparse.o lin_solver.o \
		stokes_aux.o \
		navsto_aux.o navstoassem.o assembly.o \
		navsto_adj.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)

test_navstoMGval: test_navstoMG.o mesh.o elements.o cubature.o stokesassem.o \
	sparse.o lin_solver.o stokes_aux.o \
	navsto_aux.o navstoassem.o assembly.o \
	navsto_adj.o triangle/triangle.o 
	$(CC) -o test_navstoMGval $(CFLAGS) test_navstoMG.o mesh.o \
		elements.o cubature.o stokesassem.o sparse.o lin_solver.o \
		stokes_aux.o \
		navsto_aux.o navstoassem.o assembly.o \
		navsto_adj.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS) 

test_stokes2: test_stokes2.o mesh.o elements.o cubature.o stokesassem.o \
	sparse.o lin_solver.o stokes_aux.o navsto_aux.o 
	$(CC) -o test_stokes2 $(CFLAGS) -DISMAIN test_stokes2.o mesh.o \
		elements.o cubature.o stokesassem.o sparse.o lin_solver.o \
		 stokes_aux.o navsto_aux.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)

test_stokes2val: test_stokes2.o mesh.o elements.o cubature.o stokesassem.o \
	sparse.o lin_solver.o stokes_aux.o navsto_aux.o 
	$(CC) -o test_stokes2val $(CFLAGS) -DISMAIN test_stokes2.o mesh.o \
		elements.o cubature.o stokesassem.o sparse.o lin_solver.o \
		stokes_aux.o navsto_aux.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)

test_assem: test_assem.o mesh.o elements.o cubature.o assembly.o \
	sparse.o lin_solver.o triangle/triangle.o gen_aux.o
	$(CC) -o test_assem $(CFLAGS) test_assem.o mesh.o elements.o \
		cubature.o assembly.o sparse.o lin_solver.o \
		 triangle/triangle.o gen_aux.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS) 

test_assemval: test_assem.o mesh.o elements.o cubature.o assembly.o \
	sparse.o lin_solver.o triangle/triangle.o gen_aux.o
	$(CC) -o test_assemval $(CFLAGS) test_assem.o mesh.o elements.o \
		cubature.o assembly.o sparse.o lin_solver.o \
		triangle/triangle.o gen_aux.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)

para_navsto: process_parallel.c test_navstoMG.c mesh.o \
	elements.o cubature.o stokesassem.o \
	sparse.o lin_solver.o stokes_aux.o \
	navsto_aux.o navstoassem.o assembly.o \
	navsto_adj.o triangle/triangle.o 

	$(CC) -o para_navsto $(CFLAGS) process_parallel.c \
		-DPARALLEL test_navstoMG.c \
		mesh.o elements.o cubature.o stokesassem.o \
		sparse.o lin_solver.o stokes_aux.o \
		navsto_aux.o navstoassem.o assembly.o \
		navsto_adj.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) -lm $(CMPLIBS)

batch_navsto: process_parallel.o test_navstoMG.c mesh.o \
	elements.o cubature.o stokesassem.o \
	sparse.o lin_solver.o stokes_aux.o \
	navsto_aux.o navstoassem.o assembly.o \
	navsto_adj.o triangle/triangle.o 

	$(CC) -o batch_navsto $(CFLAGS) -DPARALLEL test_navstoMG.c \
		process_parallel.o \
		mesh.o elements.o cubature.o stokesassem.o \
		sparse.o lin_solver.o stokes_aux.o \
		navsto_aux.o navstoassem.o assembly.o \
		navsto_adj.o triangle/triangle.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) -lm $(CMPLIBS)


test_mesh_deform: test_mesh_deform.o mesh.o elements.o cubature.o \
	sparse.o lin_solver.o assembly.o \
	triangle/triangle.o gen_aux.o
	$(CC) -o test_mesh_deform $(CFLAGS) \
		test_mesh_deform.o mesh.o elements.o cubature.o \
		sparse.o lin_solver.o assembly.o \
		triangle/triangle.o gen_aux.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)

test_lame: test_lame.o mesh.o elements.o cubature.o \
	sparse.o lin_solver.o assembly.o \
	triangle/triangle.o gen_aux.o mesh_deform.o
	$(CC) -o test_lame $(CFLAGS) \
		test_lame.o mesh.o elements.o cubature.o \
		sparse.o lin_solver.o assembly.o \
		triangle/triangle.o gen_aux.o mesh_deform.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)




wc:
	wc *.c *.cpp datastruc.h meshdetails.h sparse_struct.h \
		feins_macros.h feins_lapack.h navsto_struct.h makefile


triangle/triangle.o: triangle/triangle.c
	cd triangle; gcc -DTRILIBRARY -O -c triangle.c; 

%.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@

clean: 
	rm -f *.o *.d core core.[0-9]* test_assem test_assemval test_stokes \
		test_stokesval test_stokes2 test_stokes2val para_navsto \
		test_navsto test_navstoval test_navstoMG test_navstoMGval \
		batch_navsto test_navsto_solver test_mesh_deform

include $(sources:.c=.d)

