#
# squid-gw/Makefile
#
include	../Makefile.config

CFLAGS= -I.. -I../libem $(COPT)
EMIO=../libem/emio.h

all:	version squid-gw squid-log squid-top

version: chkversion
	./chkversion

chkversion:	chkversion.o ../libemfw.a
	$(CC) $(LDFL) -o chkversion chkversion.o ../libemfw.a

SQUID_GW_OBJ=squid-gw.o http.o html.o url.o cookies.o connect.o utils.o \
	../libemfw.a ../libfwall.a
squid-gw:	run-reg $(SQUID_GW_OBJ)
	rm -f squid-gw
	$(CC) $(LDFL) -o squid-gw.tmp $(SQUID_GW_OBJ) $(AUXLIB)
	./squid-gw.tmp -check
	mv -f squid-gw.tmp squid-gw

SQUID_LOG_OBJ=squid-log.o ../libemfw.a
squid-log:	$(SQUID_LOG_OBJ)
	$(CC) $(LDFL) -o squid-log $(SQUID_LOG_OBJ) $(AUXLIB)

SQUID_TOP_OBJ=squid-top.o url.o utils.o ../libemfw.a
squid-top:	$(SQUID_TOP_OBJ)
	$(CC) $(LDFL) -o squid-top $(SQUID_TOP_OBJ) $(AUXLIB)

maketable: maketable.o
	$(CC) $(LDFL) -o maketable maketable.o

TESTHTML_OBJ=testhtml.o html.o url.o cookies.o http.o connect.o utils.o \
	../libfwall.a ../libemfw.a
testhtml:	$(TESTHTML_OBJ)
	$(CC) $(LDFL) -o testhtml $(TESTHTML_OBJ) $(AUXLIB)

TESTHTTP_OBJ=testhttp.o http.o url.o cookies.o connect.o utils.o \
	../libfwall.a ../libemfw.a
testhttp:	$(TESTHTTP_OBJ)
	$(CC) $(LDFL) -o testhttp $(TESTHTTP_OBJ) $(AUXLIB)

TESTURL_OBJ=testurl.o url.o utils.o ../libfwall.a ../libemfw.a
testurl:	$(TESTURL_OBJ)
	$(CC) $(LDFL) -o testurl $(TESTURL_OBJ) $(AUXLIB)

TESTMATCH_OBJ=testmatch.o utils.o ../libemfw.a
testmatch:	$(TESTMATCH_OBJ)
	$(CC) $(LDFL) -o testmatch $(TESTMATCH_OBJ) $(AUXLIB)

squid-gw.o: squid-gw.c squid-gw.h $(EMIO)
http.o: http.c squid-gw.h $(EMIO) tables.h http-ctype.h http-req.h http-res.h \
	http-con.h
html.o: html.c squid-gw.h $(EMIO) tables.h ../libem/fastheap.h html-ctype.h \
	html-attr.h html-entity.h html-meta.h html-rel.h html-tag.h html-type.h
url.o:	url.c tables.h $(EMIO) squid-gw.h url-ctype.h url-scheme.h
cookies.o: cookies.c squid-gw.h
connect.o: connect.c squid-gw.h
utils.o: utils.c squid-gw.h
maketable.o: maketable.c tables.h
testhtml.o: testhtml.c squid-gw.h $(EMIO)
testhttp.o: testhttp.c squid-gw.h $(EMIO)
testmatch.o: testmatch.c
testurl.o: testurl.c squid-gw.h $(EMIO)

http-ctype.h: maketable
	./maketable -t http >http-ctype.h

html-ctype.h: maketable
	./maketable -t html >html-ctype.h

url-ctype.h: maketable
	./maketable -t url >url-ctype.h

http-req.h: http-req.tab
	../libem/maketable -h request 200 <http-req.tab >http-req.h

http-res.h: http-res.tab
	../libem/maketable -h response 200 <http-res.tab >http-res.h

http-con.h: http-con.tab
	../libem/maketable -h connect 20 <http-con.tab >http-con.h

html-attr.h: html-attr.tab
	../libem/maketable -h attr 600 <html-attr.tab >html-attr.h

html-entity.h: html-entity.tab
	../libem/maketable -h -c entity 300 <html-entity.tab >html-entity.h

html-meta.h: html-meta.tab
	../libem/maketable -h meta 50 <html-meta.tab >html-meta.h

html-rel.h: html-rel.tab
	../libem/maketable -h rel 50 <html-rel.tab >html-rel.h

html-tag.h: html-tag.tab
	../libem/maketable -h tag 300 <html-tag.tab >html-tag.h

html-type.h: html-type.tab
	../libem/maketable -h type 50 <html-type.tab >html-type.h

url-scheme.h: url-scheme.tab
	../libem/maketable -h scheme 40 <url-scheme.tab >url-scheme.h

run-reg: run-reg-url run-reg-http run-reg-html run-reg-match

run-reg-url: testurl
	./testurl -p <tests/url/reg01.inp >reg.out
	@diff tests/url/reg01.exp reg.out
	@rm -f reg.out
	./testurl -c <tests/url/reg02.inp

run-reg-html: testhtml
	./html-reg tests/html/*.inp

run-reg-http: testhttp
	./http-reg tests/http/*.inp

run-reg-match: testmatch
	./testmatch <tests/match/reg01.inp

clean:
	-rm -f *.o chkversion squid-gw squid-gw.tmp squid-log squid-top
	-rm -f testhtml testhttp testmatch testurl maketable
	-rm -f reg.out reg.err reg.exp reg.inp
	-rm -f http-ctype.h http-req.h http-res.h http-con.h
	-rm -f html-ctype.h html-attr.h html-entity.h html-meta.h
	-rm -f html-rel.h html-tag.h html-type.h url-ctype.h url-scheme.h
