DIR_INSTALL=/usr/local
DIR_MAN=$(DIR_INSTALL)/man
DIR_SBIN=$(DIR_INSTALL)/sbin
DIR_BIN=$(DIR_INSTALL)/bin

VPATH=src
CXXFLAGS=-O2 -g

# Hacks to make Redhat 6.0 happy:
CXXFLAGS+=-I/usr/include/pcap
CXXFLAGS+=-I/usr/include/g++-2

prgsuser=wiplc wiplcSimple wiplcExec
prgsroot=wipld wiplcInetd
man8=wipld.8 wiplcInetd.8
man5=wipllang.5
man1=wipl.1 wiplc.1 wiplcSimple.1 wiplcExec.1

objs=wiplcSimple.o wiplcInetd.o wiplcList.o common.o shmem.o sigctl.o wipld.o \
     pcapintf.o parseprg.o config.o logfile.o prgcommon.o wiplcExec.o \
     wiplc.o wiplcexpr.o proxydict.o

all: $(prgsuser) $(prgsroot)

clean: 
	rm -f $(objs) $(prgsuser) $(prgsroot) y.tab.c lex.yy.c

install:
	install -d -o 0 -g 0 $(DIR_BIN) $(DIR_SBIN) $(DIR_MAN)/man1 $(DIR_MAN)/man5 $(DIR_MAN)/man8
	for FILE in $(prgsuser); do                                \
	    install -s -o 0 -g 0 $$FILE $(DIR_BIN)/$$FILE;  \
	done	                                                   
	for FILE in $(prgsroot); do                                \
	    install -s -o 0 -g 0 $$FILE $(DIR_SBIN)/$$FILE; \
	done	
	for FILE in $(man8); do                                                   \
	    install -m 644 -o 0 -g 0 man/$$FILE $(DIR_MAN)/man8/$$FILE; \
	done	
	for FILE in $(man5); do                                                   \
	    install -m 644 -o 0 -g 0 man/$$FILE $(DIR_MAN)/man5/$$FILE; \
	done	
	for FILE in $(man1); do                                                   \
	    install -m 644 -o 0 -g 0 man/$$FILE $(DIR_MAN)/man1/$$FILE; \
	done	
	
uninstall:
	for FILE in $(prgsuser); do          \
	    rm -f $(DIR_BIN)/$$FILE;  \
	done	                             
	for FILE in $(prgsroot); do          \
	    rm -f $(DIR_SBIN)/$$FILE; \
	done	                             
	for FILE in $(man8); do                  \
	    rm -f $(DIR_MAN)/man8/$$FILE; \
	done	
	for FILE in $(man5); do                  \
	    rm -f $(DIR_MAN)/man5/$$FILE; \
	done	
	for FILE in $(man1); do                  \
	    rm -f $(DIR_MAN)/man1/$$FILE; \
	done	
	
wiplcSimple:	wiplcSimple.o common.o shmem.o sigctl.o
		    $(CXX) -o $@ $^

wiplc:		wiplc.o wiplcexpr.o common.o shmem.o sigctl.o
		    $(CXX) -o $@ $^

wiplcInetd:	wiplcInetd.o common.o shmem.o sigctl.o
		    $(CXX) -o $@ $^

wiplcExec:      wiplcExec.o common.o shmem.o sigctl.o prgcommon.o parseprg.o
		    $(CXX) -o $@ $^

wipld:		wipld.o common.o shmem.o sigctl.o pcapintf.o parseprg.o config.o logfile.o prgcommon.o proxydict.o
		    $(CXX) -o $@ $^ -lpcap 

wiplcSimple.o:	common.h shmem.h
wiplc.o:	common.h shmem.h wiplcexpr.h
wiplcInetd.o:	common.h shmem.h
wiplcList.o:	common.h shmem.h
wiplcExec.o:    common.h shmem.h prgcommon.h config.h parseprg.h
wipld.o:	common.h shmem.h pcapintf.h parseprg.h config.h logfile.h sigctl.h prgcommon.h proxydict.h proxyremap.h
prgcommon.o:    common.h parseprg.h prgcommon.h
common.o:	common.h
shmem.o:	common.h shmem.h sigctl.h
sigctl.o:	sigctl.h
logfile.o:      sigctl.h logfile.h common.h
pcapintf.o:	common.h pcapintf.h logfile.h config.h
config.o:       common.h config.h
parseprg.o:	parseprg.y parseprg.l common.h parseprg.h
		    lex $(VPATH)/parseprg.l
		    yacc $(VPATH)/parseprg.y
		    $(CXX) $(CXXFLAGS) -I. -Isrc -c y.tab.c -o parseprg.o
		    rm -f y.tab.c lex.yy.c
wiplcexpr.o:	wiplcexpr.y wiplcexpr.l common.h wiplcexpr.h
		    lex $(VPATH)/wiplcexpr.l
		    yacc $(VPATH)/wiplcexpr.y
		    $(CXX) $(CXXFLAGS) -I. -Isrc -c y.tab.c -o wiplcexpr.o
		    rm -f y.tab.c lex.yy.c
