# @(#) $Header: Makefile,v 1.25 92/09/02 01:29:37 leres Exp $ (LBL)
#
# Copyright (c) 1988 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation, advertising
# materials, and other materials related to such redistribution and
# use acknowledge that the software was developed by the University
# of California, Berkeley.  The name of the University may not be
# used to endorse or promote products derived from this software
# without specific prior written permission.  THIS SOFTWARE IS PROVIDED
# ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
# FITNESS FOR A PARTICULAR PURPOSE.
#

# Can't use because inet_ntoa() chews it on the sparc
#CC= gcc -g -fpcc-struct-return
CC=cc -W
INCL= 
OPT= -g
DEFS= -DDEBUG
CFLAGS=	${OPT} ${INCL} ${DEFS}
SRCS=	arpwatch.c dns.c file.c inet.c pcap.c db.c ec.c report.c
AOBJS=	arpwatch.o dns.o file.o inet.o pcap.o db.o ec.o report.o
POBJS=	arpprint.o file.o ec.o
HDRS=	arpwatch.h db.h dns.h ec.h inet.h pcap.h
LIBS= 
TAGHDRS= /usr/include/net/bpf.h \
    /usr/include/netinet/if_ether.h \
    /usr/include/net/if_arp.h
ALL= arpwatch arpprint zap

arpwatch: ${AOBJS}
	${CC} -o $@ ${CFLAGS} ${AOBJS} ${LIBS}

all: ${ALL}

all: ${ALL}

arpprint: ${POBJS}
	${CC} -o $@ ${CFLAGS} ${POBJS} ${LIBS}

zap: zap.c
	${CC} -o $@ ${CFLAGS} $@.c ${LIBS}

clean:
	rm -f *.o core ${ALL} raw.ether new.ether ethers arpwatch-?.?.tar.Z

cleandir: clean
	rm -f tags .depend

depend: .depend
.depend: ${SRCS}
	mkdep -p ${INCL} ${DEFS} ${SRCS}

install: arpwatch
	install arpwatch ${DESTDIR}/usr/operator/arpwatch/arpwatch

install-man:
	install -c -m 444 arpwatch.8 ${DESTDIR}/usr/man/man8

lint: ${SRCS}
	lint ${SRCS}

tar:
	rm -f arpwatch-?.?.tar.Z
	-@dir=`/bin/pwd`; dir=`basename $$dir`; \
	    for i in README arpwatch.8 ${SRCS} ${HDRS} Makefile;\
	    do list="$$list $$dir/$$i"; done; \
	    cd .. ; set -x; tar cf - $$list | compress >$$dir/$$dir.tar.Z

# /etc/ethers generation rules
raw.ether: arpprint /usr/operator/arpwatch/arp.dat
	./arpprint -v | egrep -v '128\.3\.' | awk -f d.awk | \
	awk -f p.awk | sort -rn +3 | awk -f q.awk | \
	awk '{ printf "%s\t%s\n", $$1, $$2 }' | sort > raw.ether

new.ether: raw.ether ethers
	comm -23 raw.ether ethers | \
	awk '{ printf "%s\t%s\t# new\n", $$1, $$2 }' > new.ether

ethers:
	rsh helios cat /etc/ethers | egrep -v '^#' | sort > ethers

# Show percentages for each ip address on the 128.3.252 subnet
count:
	egrep "128\.3\.25" ${DESTDIR}/usr/operator/arpwatch/arp.dat | \
	    awk -f q.awk | awk -f a.awk 

tags:
	ctags -wtd ${SRCS} ${HDRS} ${TAGHDRS}
