CFLAGS = -Wall -O4 -g

default : testlib findv pp ehrhart
	@echo "---------------------------------------------------"
	@echo "To run the test, type: "
	@echo "    cd Test; make"
	@echo "---------------------------------------------------"

testlib : main.c vector.o polyhedron.o lattice.o
	gcc $(CFLAGS) -o testlib main.c vector.o polyhedron.o lattice.o

eval_test: eval_ehrhart.o
	gcc -Wall -O4 -o eval_test eval_test.c eval_ehrhart.o
union_disjointe: union_disjointe.c vector.o polyhedron.o
	gcc $(CFLAGS) -o union_disjointe union_disjointe.c vector.o polyhedron.o
union_convex: union_convex.c vector.o polyhedron.o
	gcc $(CFLAGS) -o union_convex union_convex.c vector.o polyhedron.o
r2p: r2p.c types.h vector.h polyhedron.h
	gcc $(CFLAGS) -o r2p r2p.c vector.o polyhedron.o
c2p: c2p.c types.h vector.h polyhedron.h
	gcc $(CFLAGS) -o c2p c2p.c vector.o polyhedron.o

all: testlib findv pp ehrhart eval_test \
				union_disjointe union_convex r2p c2p
	@echo "done."


vector.o : vector.c vector.h types.h
	gcc -c $(CFLAGS) -DCHECK_OVERFLOW vector.c

vector.h: vector.c
#	echo "/* temporary vector.h */" >vector.h
#	cextract +a +w72 -H_vector_h_ -o vector.h vector.c
	
polyhedron.o: polyhedron.c vector.h polyhedron.h types.h
	gcc -c $(CFLAGS) polyhedron.c

polyhedron.h: polyhedron.c
#	echo "/* temporary polyhedron.h */" >polyhedron.h
#	cextract +a +w72 -H_polyhedron_h_ -o polyhedron.h polyhedron.c
	
lattice.o : lattice.c lattice.h vector.h polyhedron.h types.h
	gcc -c $(CFLAGS) lattice.c

lattice.h : lattice.c
#	echo "/* temporary lattice.h */" >lattice.h
#	cextract +a +w72 -H_lattice_h_ -o lattice.h lattice.c

polyparam.o : polyparam.c polyparam.h vector.h polyhedron.h types.h Makefile
	gcc -c $(CFLAGS) polyparam.c
eval_ehrhart.o: eval_ehrhart.c eval_ehrhart.h ehrhart.h types.h
	gcc -c $(CFLAGS) eval_ehrhart.c

polyparam.h : polyparam.c
#	echo "/* temporary polyparam.h */" >polyparam.h
#	cextract +a +w72 -H_polyparam_h_ -o polyparam.h polyparam.c

findv: findv.c polyparam.o polyparam.h polyhedron.o vector.o
	gcc $(CFLAGS) -o findv findv.c polyparam.o polyhedron.o vector.o

pp: pp.c polyparam.o polyparam.h polyhedron.o vector.o
	gcc $(CFLAGS) -o pp pp.c polyparam.o polyhedron.o vector.o

ehrhart: ehrhart.c polyparam.o polyparam.h eval_ehrhart.o \
			types.h polyhedron.o vector.o
	gcc $(CFLAGS) -o ehrhart ehrhart.c eval_ehrhart.o \
	                polyhedron.o vector.o polyparam.o

clean:
	-rm -f *.o
	-rm -f a.out core
	-rm -f testlib testbug findv pp ehrhart
	-rm -f eval_test union_disjointe union_convex r2p c2p
#	-rm -f polyhedron.h vector.h lattice.h polyparam.h

installshar:
	shar * >../lib.shar

installtar:
	rm -f ../polylib.tar
	tar cvf ../polylib.tar *
	rm -f ../polylib.tar.gz
	gzip ../polylib.tar
	rm -f ../polylib.uu
	uuencode ../polylib.tar.gz polylib.tar.gz >../polylib.uu
