GMKPATH = ..
include $(GMKPATH)/Makefile.config

CFLAGS = -I.. -I../libem -I ../nlib -I$(MAGIC_INCDIR) -I$(MILTER_INCDIR) $(COPT)
LDFLAGS = $(LDFL) -L$(MILTER_LIBDIR) -lci_milter -L.. -lemfw -lfwall $(AUXLIB)

BINOBJS = squid-gw squid-log squid-top
PCBOBJS = squid-gw.restart
MANOBJS = squid-gw.8
TB1OBJS = chkversion maketable
TB2OBJS = testurl testhttp testhtml testmatch
SGWOBJS = squid-gw.o http.o html.o url.o cookies.o connect.o utils.o
SLGOBJS = squid-log.o
STPOBJS = squid-top.o url.o utils.o
CKVOBJS = chkversion.o
TUROBJS = testurl.o url.o utils.o
THTOBJS = testhttp.o http.o url.o cookies.o connect.o utils.o
THMOBJS = testhtml.o html.o url.o cookies.o http.o connect.o utils.o
TMAOBJS = testmatch.o utils.o
MTBOBJS = maketable.o
TABOBJS = http-ctype.h html-ctype.h url-ctype.h http-req.h http-res.h http-con.h  \
          html-attr.h html-entity.h html-meta.h html-rel.h html-tag.h html-type.h \
          url-scheme.h
ALLOBJS = $(CKVOBJS) $(MTBOBJS) $(TB1OBJS) $(TABOBJS) 				  \
          $(TUROBJS) $(THTOBJS) $(THMOBJS) $(TMAOBJS) $(TB2OBJS)		  \
          $(SGWOBJS) $(SLGOBJS) $(STPOBJS) $(BINOBJS) $(MANOBJS)

all: $(ALLOBJS)

$(TUROBJS) $(THTOBJS) $(THMOBJS) $(TMAOBJS): $(TB1OBJS) $(TABOBJS)
$(SGWOBJS): $(TB2OBJS)

squid-gw: $(SGWOBJS) ../libemfw.a ../libfwall.a
	$(OFWTKLINK) $(SGWOBJS)
	mv -f squid-gw squid-gw.tmp
	./squid-gw.tmp -check
	mv -f squid-gw.tmp squid-gw

squid-log: $(SLGOBJS) ../libemfw.a ../libfwall.a
	$(OFWTKLINK) $(SLGOBJS)

squid-top: $(STPOBJS) ../libemfw.a ../libfwall.a 
	$(OFWTKLINK) $(STPOBJS)

chkversion: $(CKVOBJS) ../libemfw.a
	$(OFWTKLINK) $(CKVOBJS)
	./chkversion

testurl: $(TUROBJS) ../libfwall.a ../libemfw.a
	$(OFWTKLINK) $(TUROBJS)
	./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

testhttp: $(THTOBJS) ../libfwall.a ../libemfw.a 
	$(OFWTKLINK) $(THTOBJS)
	./http-reg tests/http/*.inp

testhtml: $(THMOBJS) ../libfwall.a ../libemfw.a
	$(OFWTKLINK) $(THMOBJS)
	./html-reg tests/html/*.inp

testmatch: $(TMAOBJS) ../libemfw.a 
	$(OFWTKLINK) $(TMAOBJS)
	./testmatch <tests/match/reg01.inp

maketable: $(MTBOBJS)
	$(OFWTKLINK) $(MTBOBJS)

$(TABOBJS): $(TB1OBJS)
	./maketable -t http >http-ctype.h
	./maketable -t html >html-ctype.h
	./maketable -t url >url-ctype.h
	../libem/maketable -h request 200 <http-req.tab >http-req.h
	../libem/maketable -h response 200 <http-res.tab >http-res.h
	../libem/maketable -h connect 20 <http-con.tab >http-con.h
	../libem/maketable -h attr 600 <html-attr.tab >html-attr.h
	../libem/maketable -h -c entity 300 <html-entity.tab >html-entity.h
	../libem/maketable -h meta 50 <html-meta.tab >html-meta.h
	../libem/maketable -h rel 50 <html-rel.tab >html-rel.h
	../libem/maketable -h tag 300 <html-tag.tab >html-tag.h
	../libem/maketable -h type 50 <html-type.tab >html-type.h
	../libem/maketable -h scheme 40 <url-scheme.tab >url-scheme.h
