INSTALLDIR=/usr/local

CC=g++
CXXFLAGS=-O2
VPATH=src

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

objs=wiplc.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

all: $(prgsuser) $(prgsroot)

clean: 
	rm -f $(objs) $(prgsuser) $(prgsroot)

install:
	install -d -o 0 -g 0 $(INSTALLDIR)/bin $(INSTALLDIR)/sbin $(INSTALLDIR)/man/man1 $(INSTALLDIR)/man/man5 $(INSTALLDIR)/man/man8 $(INSTALLDIR)/etc
	for FILE in $(prgsuser); do                                \
	    install -s -o 0 -g 0 $$FILE $(INSTALLDIR)/bin/$$FILE;  \
	done	                                                   
	for FILE in $(prgsroot); do                                \
	    install -s -o 0 -g 0 $$FILE $(INSTALLDIR)/sbin/$$FILE; \
	done	
	for FILE in $(man8); do                                                   \
	    install -m 644 -o 0 -g 0 man/$$FILE $(INSTALLDIR)/man/man8/$$FILE; \
	done	
	for FILE in $(man5); do                                                   \
	    install -m 644 -o 0 -g 0 man/$$FILE $(INSTALLDIR)/man/man5/$$FILE; \
	done	
	for FILE in $(man1); do                                                   \
	    install -m 644 -o 0 -g 0 man/$$FILE $(INSTALLDIR)/man/man1/$$FILE; \
	done	
	
uninstall:
	for FILE in $(prgsuser); do          \
	    rm -f $(INSTALLDIR)/bin/$$FILE;  \
	done	                             
	for FILE in $(prgsroot); do          \
	    rm -f $(INSTALLDIR)/sbin/$$FILE; \
	done	                             
	for FILE in $(man8); do                  \
	    rm -f $(INSTALLDIR)/man/man8/$$FILE; \
	done	
	for FILE in $(man5); do                  \
	    rm -f $(INSTALLDIR)/man/man5/$$FILE; \
	done	
	for FILE in $(man1); do                  \
	    rm -f $(INSTALLDIR)/man/man1/$$FILE; \
	done	
	
wiplc:		wiplc.o common.o shmem.o sigctl.o
wiplcInetd:	wiplcInetd.o common.o shmem.o sigctl.o
wiplcExec:      wiplcExec.o common.o shmem.o sigctl.o prgcommon.o parseprg.o
wipld:		wipld.o common.o shmem.o sigctl.o pcapintf.o parseprg.o config.o logfile.o prgcommon.o
		    $(CC) $(CXXFLAGS)                                   \
		      wipld.o common.o shmem.o sigctl.o pcapintf.o      \
		      parseprg.o config.o logfile.o prgcommon.o -lpcap -o wipld

wiplc.o:	common.h shmem.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
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
		    $(CC) -I. $(CXXFLAGS) -c y.tab.c -o parseprg.o
		    rm -f y.tab.c lex.yy.c
