# Makefile for ziproxy

# CONFIGURE: If you are using a SystemV-based operating system, such as
# Solaris, you will need to uncomment this definition.
#SYSV_LIBS =	-lnsl -lsocket

#Other possible options to put under EXTRA_CFL:
# -DNOWAIT : if compiling under cygwin (or other platforms, where no explicit
#treatment of child processes is needed). Affects only netd compilation.
# -DCONFUSEv2 : if compiling with libConfuse 2.x (please don't use 2.0 !)
EXTRA_CFL =  
# Uncomment to enable JPEG2000:
#JP2K = yes
# You can fill in root of Jasper library installation:
#JASPER = /home/somewhere/jasper
#This works only with newer GNU make. If your make doesn't like it,
#you have to edit following lines manually according to whether you 
#need JP2 or not.
 
ifdef JP2K
	EXTRA_CFL+= -DJP2K
	J2KLIB=-ljasper
	MDF=htmlmodify_jp2
	ifdef JASPER
		J2KLIB = -L$(JASPER)/lib -ljasper
		J2KINC = -I$(JASPER)/include
	endif
else
	MDF=htmlmodify
endif

CFLAGS =-ggdb $(EXTRA_CFL)

CC = gcc

#If -lgif is not found, try -lungif
LDFLAGS = -g $(SYSV_LIBS) -lgif -lpng -ljpeg -lm -lz -lconfuse 

all: netd ziproxy cfgtest imgtest

ziproxy: ziproxy.o http.o log.o text.o image.o $(MDF).o cfgfile.o
	$(CC) ziproxy.o http.o log.o text.o image.o $(MDF).o cfgfile.o $(LDFLAGS) $(J2KLIB) -o ziproxy

ziproxy.o: ziproxy.c image.h http.h log.h text.h htmlmodify.h cfgfile.h
	$(CC) $(CFLAGS) -c ziproxy.c -o ziproxy.o
	
http.o: http.c http.h
	$(CC) $(CFLAGS) -c http.c -o http.o
	
image.o: image.c image.h
	$(CC) $(CFLAGS) $(J2KINC) -c image.c -o image.o
	
log.o: log.c 
	$(CC) $(CFLAGS) $(J2KINC) -c log.c -o log.o

text.o: text.c
	$(CC) $(CFLAGS) $(J2KINC) -c text.c -o text.o

$(MDF).c: $(MDF).l
	flex -s -d -Cfa -Phtmlmodify_yy -8 -o$(MDF).c $(MDF).l
	
$(MDF).o: $(MDF).c
	$(CC) $(CFLAGS) -c $(MDF).c -o $(MDF).o 

cfgfile.o: cfgfile.c
	$(CC) $(CFLAGS) -c cfgfile.c -o cfgfile.o

netd:netd.c cfgfile.o cfgfile.h
	$(CC) $(CFLAGS) netd.c cfgfile.o $(LDFLAGS) -o netd

modifytest: modifytest.c $(MDF).o
	$(CC) $(CFLAGS) modifytest.c $(MDF).o $(LDFLAGS) -o modifytest

imgtest: image.o imgtest.c
	$(CC) $(CFLAGS) imgtest.c image.o cfgfile.o $(LDFLAGS) $(J2KLIB) -o imgtest
	
cfgtest: cfgtest.c cfgfile.o
	$(CC) $(CFLAGS) cfgtest.c cfgfile.o $(LDFLAGS) -o cfgtest

#install: all
#	rm -f $(BINDIR)/ziproxy
#	cp ziproxy $(BINDIR)
#	rm -f $(MANDIR)/ziproxy.8
#	cp ziproxy.8 $(MANDIR)

clean:
	rm -f ziproxy netd modifytest imgtest cfgtest *.o core core.* *.core
