include make_inc.$(ARCHI)


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

sources = $(shell ls *.c)

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




all: test_navsto_solver

test_navsto_solver_derivpaper: test_navsto_solver_derivpaper.o linsolve_umfpack.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 linsolve_umfpack.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 linsolve_umfpack.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 linsolve_umfpack.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_bcontrol: test_navsto_solver_bcontrol.o linsolve_umfpack.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) linsolve_umfpack.o \
	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 linsolve_umfpack.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  linsolve_umfpack.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  linsolve_umfpack.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 linsolve_umfpack.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 linsolve_umfpack.o \
	sparse.o lin_solver.o stokes_aux.o navsto_aux.o 
	$(CC) -o test_stokes2 $(CFLAGS) -DISMAIN test_stokes2.o mesh.o linsolve_umfpack.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 linsolve_umfpack.o \
	sparse.o lin_solver.o stokes_aux.o navsto_aux.o 
	$(CC) -o test_stokes2val $(CFLAGS) -DISMAIN test_stokes2.o mesh.o linsolve_umfpack.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 linsolve_umfpack.o \
	sparse.o lin_solver.o triangle/triangle.o gen_aux.o
	$(CC) -o test_assem $(CFLAGS) test_assem.o mesh.o elements.o linsolve_umfpack.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 linsolve_umfpack.o \
	sparse.o lin_solver.o triangle/triangle.o gen_aux.o
	$(CC) -o test_assemval $(CFLAGS) test_assem.o mesh.o elements.o linsolve_umfpack.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 linsolve_umfpack.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 linsolve_umfpack.o \
		-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 linsolve_umfpack.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 linsolve_umfpack.o \
		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 linsolve_umfpack.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 linsolve_umfpack.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 linsolve_umfpack.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 linsolve_umfpack.o \
		sparse.o lin_solver.o assembly.o \
		triangle/triangle.o gen_aux.o mesh_deform.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS)

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

test_sparse_cache_effects: test_sparse_cache_effects.o linsolve_umfpack.o \
	sparse.o 
	$(CC) -o test_sparse_cache_effects $(CFLAGS) \
		test_sparse_cache_effects.o sparse.o linsolve_umfpack.o \
		$(LOCALLIBDIRS) $(LAPACKLIBS) \
		-lm $(CMPLIBS) 

test_convection_diffusion: test_convection_diffusion.o mesh.o elements.o \
	cubature.o linsolve_umfpack.o \
	sparse.o lin_solver.o assembly.o assem_conv_diff.o \
	triangle/triangle.o gen_aux.o mesh_deform.o
	$(CC) -o test_convection_diffusion $(CFLAGS) \
		test_convection_diffusion.o mesh.o elements.o \
		cubature.o linsolve_umfpack.o \
		sparse.o lin_solver.o assembly.o assem_conv_diff.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; $(CC) -DTRILIBRARY -O -c triangle.c; 


%.o : %.c
	$(CC) -c $(CFLAGS) $(LOCALINCDIRS) $< -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 \
		test_sparse_cache_effects test_lame \
		triangle/triangle.o

include $(sources:.c=.d)

