##############################################
#
CC=gcc
CFLAGS=-Wall -O2 # -g
LDFLAGS=-lm -lz -ljpeg # -lefence
LIB= -L./zlib-1.1.3 -L./jpeg-6b
INCLUDE= -I./zlib-1.1.3 -I./jpeg-6b

##############################################
#
CSRC1= cementinit.c cementi.c plm2pnm.c
CSRC2= file.c pnmutils.c makeLookup.c
CSRC= $(CSRC1)           
HDR= cement.h pnmutils.h file.h

OBJS= file.o pnmutils.o jpeg.o
CEMENT_OBJS= cementinit.o cementi.o plm2pnm.o

.SUFFIXES : .o .c

.c.o:   Makefile $@
	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) -DOBJECT_COMPILE -c -o $@ $<

##############################################
#
all: executables libcement.a

executables: cementinit cementi cemento plm2pnm

#ar rc libz.a adler32.o compress.o crc32.o gzio.o uncompr.o deflate.o trees.o zutil.o inflate.o infblock.o inftrees.o infcodes.o infutil.o inffast.o

libcement.a: $(CSRC) Makefile $(OBJS) $(CEMENT_OBJS) cemento.o
	ar rc $@ $(OBJS) $(CEMENT_OBJS) cemento.o

cemento.o: Makefile cementi.c
	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) -DOBJECT_COMPILE -DCEMENT_REMOVE -c -o cemento.o cementi.c
        
#pnmutils.o: pnmutils.c
#	$(CC) $(CFLAGS) $(INCLUDE) -c pnmutils.c

#file.o: file.c
#	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) -c file.c



cementinit: Makefile cementinit.c powLookup.h $(OBJS)
	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) $(OBJS) $@.c -o $@ $(LDFLAGS)

cementi: Makefile cementi.c powLookup.h $(OBJS)
	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) $(OBJS) $@.c -o $@ $(LDFLAGS)

cemento: Makefile cementi.c powLookup.h $(OBJS)
	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) -DCEMENT_REMOVE $(OBJS) cementi.c -o $@ $(LDFLAGS)

plm2pnm: Makefile plm2pnm.c powLookup.h $(OBJS)
	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) $(OBJS) $@.c -o $@ $(LDFLAGS)

ppm2all: Makefile ppm2all.c
	$(CC) $(CFLAGS) $(INCLUDE) $(LIB) writejpeg.c $@.c -o $@ $(LDFLAGS)


makeLookup: Makefile makeLookup.c
	$(CC) $(CFLAGS) $@.c -o $@ -lm

powLookup.h: Makefile makeLookup
	./makeLookup


##############################################
#
run: cementinit cementi cemento
	./trowel.pl

#	./cementinit sv035.jpg.ppm.gz 1.0 1.0 1.0 -o total.plm.gz
#	./cementi total.plm.gz sv097.jpg.ppm.gz 0 1 0
#	./plm2pnm total.plm.gz -o total.ppm.gz
#	./cementinit 1.ppm 1.0 1.0 1.0 -o total.plm ;\
#	./cementi total.plm 1.ppm 1.0 1.0 1.0 ;\
#	./cementi total.plm 1.ppm 1.0 1.0 1.0 ;\

#	./cementi total.plm v003.ppm 1.0 1.0 1.0 ;\  # cement it in
#	./cemento total.plm v003.ppm 1.0 1.0 1.0 ;\  # take it out

clean:
	rm -f *.o core
	rm -f total.ppm total.plm
	rm -f makeLookup
	rm -f cementinit cementi cemento plm2pnm libcement.a

depend:
	makedepend $(INCLUDE) $(CSRC) $(HDR)

tar: $(CSRC) Makefile $(HDR) trowel.pl
	tar -cvf cement.tar $(CSRC) $(CSRC2) $(HDR) Makefile trowel.pl cement.txt sv*gz zlib-1.1.3


##############################################
#
# DO NOT DELETE BELOW THIS LINE

