#
# Protolog (The Internet Protocols logger)
#

#
# Modify this, if you need to and if you know what you are doing.
#

srcdir = .

prefix = /usr/local
bindir = ${prefix}/sbin
docdir = ../doc

# logdir is the directory were Protolog will put his logs
logdir = /var/log/protolog
mandir = ${prefix}/man/man8

# For system that doesn't support mkdir -p.
# If you have Linux, don't bother.

MKDIRECTORY = mkdir -p

# Mode for user binaries
BINMODE=700

# Mode for the log directory
LOGDIRMODE=700

# Compiler to use
CC=gcc

# Compiler warnings
WARNINGS= -pedantic -Wall

# Compiler flags
CCOPTS = -O2 -fomit-frame-pointer

# The makefile standards document I read says that I have to put it here...
SHELL = /bin/sh

# Clear and set suffixes 
.SUFFIXES:
.SUFFIXES: .c .o

# Install program
INSTALL = install

# Miscellaneous
PRO_VERSION  = 1.0.8
RELEASEDATE  = February 1999

# Size of the ignore host arrays
PRO_IGN_HOST = 32

# Location of sed (for my Slackware box)
SEDBIN       = /usr/bin/sed
# Use this for Redhat 5.1
# SEDBIN     = /bin/sed

# sed command
SEDCMDS      = "s/@version@/$(PRO_VERSION)/g;s/@releasedate@/$(RELEASEDATE)/g;s%@logdir@%$(logdir)%g"

TCPOBJ   = common.o plogtcp.o
UDPOBJ   = common.o plogudp.o
ICMPOBJ  = common.o plogicmp.o
IPRETOBJ = common.o ipretplog.o

all: plogtcp plogudp plogicmp ipretplog

plogtcp: $(TCPOBJ)
	$(CC) $(CCOPTS) $(TCPOBJ) -o $@

plogudp: $(UDPOBJ)
	$(CC) $(CCOPTS) $(UDPOBJ) -o $@

plogicmp: $(ICMPOBJ)
	$(CC) $(CCOPTS) $(ICMPOBJ) -o $@

ipretplog: $(IPRETOBJ)
	$(CC) $(CCOPTS) $(IPRETOBJ) -o $@

clean:
	rm -f *.o core plogtcp plogudp plogicmp ipretplog defines.h

strip:
	strip plogtcp plogudp plogicmp ipretplog

install:
	@$(MKDIRECTORY) ${bindir}
	$(INSTALL) -g root -m $(BINMODE) -o root -s ${srcdir}/plogtcp ${bindir}
	$(INSTALL) -g root -m $(BINMODE) -o root -s ${srcdir}/plogudp ${bindir}
	$(INSTALL) -g root -m $(BINMODE) -o root -s ${srcdir}/plogicmp ${bindir}
	$(INSTALL) -g root -m $(BINMODE) -o root -s ${srcdir}/ipretplog ${bindir}
	$(INSTALL) -g root -m $(BINMODE) -o root ${srcdir}/LaunchLoggers ${bindir}
	$(INSTALL) -g root -m $(BINMODE) -o root ${srcdir}/KillLoggers ${bindir}
	@echo "Installing man pages..."
	@$(MKDIRECTORY) ${mandir}
	@$(SEDBIN) $(SEDCMDS) ${docdir}/plogtcp.8.in   > ${mandir}/plogtcp.8
	@$(SEDBIN) $(SEDCMDS) ${docdir}/plogudp.8.in   > ${mandir}/plogudp.8
	@$(SEDBIN) $(SEDCMDS) ${docdir}/plogicmp.8.in  > ${mandir}/plogicmp.8
	@$(SEDBIN) $(SEDCMDS) ${docdir}/ipretplog.8.in > ${mandir}/ipretplog.8
	@chown 0.0 ${mandir}/plogtcp.8
	@chown 0.0 ${mandir}/plogudp.8
	@chown 0.0 ${mandir}/plogicmp.8
	@chown 0.0 ${mandir}/ipretplog.8
	$(MKDIRECTORY) ${logdir}
	@chmod $(LOGDIRMODE) ${logdir}
	@chown 0.0 ${logdir}
	@echo

uninstall:
	rm -f ${bindir}/plogtcp
	rm -f ${bindir}/plogudp
	rm -f ${bindir}/plogicmp
	rm -f ${bindir}/ipretplog
	rm -f ${logdir}
	rm -f ${mandir}/plogtcp.8
	rm -f ${mandir}/plogudp.8
	rm -f ${mandir}/plogicmp.8
	rm -f ${mandir}/ipretplog.8
	rm -f ${bindir}/LaunchLoggers
	rm -f ${bindir}/KillLoggers

.c.o:
	$(CC) $(CCOPTS) $(WARNINGS) -c $<

$(TCPOBJ): common.h defines.h internet.h
$(UDPOBJ): common.h defines.h internet.h
$(ICMPOBJ): common.h defines.h internet.h
$(IPRETOBJ): common.h defines.h internet.h

defines.h:
	@echo "Creating file \"defines.h\""
	@echo "/*"                                                           >> $(srcdir)/defines.h
	@echo "   Global #defines for Protolog"                              >> $(srcdir)/defines.h
	@echo "   Copyright (C) 1999 Diego Javier Grigna <diego@grigna.com>" >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "   File automatically created by the Makefile."               >> $(srcdir)/defines.h
	@echo "   Do not edit by hand, modify the Makefile instead."         >> $(srcdir)/defines.h
	@echo "*/"                                                           >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "#define PRO_VERSION    \"$(PRO_VERSION)\""                    >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "#define PRO_ICMP_RAW   \"$(logdir)/icmp.raw\""                >> $(srcdir)/defines.h
	@echo "#define PRO_ICMP_LOG   \"$(logdir)/icmp.log\""                >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "#define PRO_TCP_RAW    \"$(logdir)/tcp.raw\""                 >> $(srcdir)/defines.h
	@echo "#define PRO_TCP_LOG    \"$(logdir)/tcp.log\""                 >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "#define PRO_UDP_RAW    \"$(logdir)/udp.raw\""                 >> $(srcdir)/defines.h
	@echo "#define PRO_UDP_LOG    \"$(logdir)/udp.log\""                 >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h
	@echo "#define PRO_IGN_HOST   $(PRO_IGN_HOST)"                       >> $(srcdir)/defines.h
	@echo ""                                                             >> $(srcdir)/defines.h


