#  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
#  distribution and use acknowledge that the software was developed
#  by the University of California, Lawrence Berkeley Laboratory,
#  Berkeley, CA.  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.
# 
# @(#) $Header: Makefile,v 1.31 90/03/04 10:21:56 mccanne Exp $ (LBL)

# Possible Options:
#    -DCSLIP	include support for kernel slip nit interface (need LBL
#		if_sl driver and only works under Sun OS 3.5).
#    -DFLEX	scanner built with flex instead of lex
#    -DDEBUG	include some debugging code (unless you're making major
#		additions to this program, you don't need to set this)
DEFINES = -DFLEX -DDEBUG
CCOPT = -O
INCLUDES =

# Full pathname of where to install the binary
BINDEST = /usr/etc/tcpdump
# Full pathname of where to install the manual entry
MANDEST = /usr/man/manl/tcpdump.l

# These are the flags to use for Sun OS 3.x
CFLAGS_SUNOS3 = $(CCOPT) $(DEFINES) $(INCLUDES)
# These are the flags to use for Sun OS 4.0.x
CFLAGS_SUNOS4 = $(CCOPT) $(DEFINES) $(INCLUDES) -DSUNOS4 -Bstatic

# Change these to cc/lex/yacc if you don't have gcc, flex and/or bison.
# If using lex, also remove the -DFLEX from DEFINES.
#
CC = gcc -g
LEX=	flex
YACC=	bison -y

# Set the following to the CFLAGS you want to use to compile on a Sun 3.
#
CFLAGS_SUN3 = $(CFLAGS_SUNOS3) -DCSLIP
 
# Set the following to the CFLAGS you want to use to compile on a sparc.
#
CFLAGS_SUN4 = $(CFLAGS_SUNOS4)

CSRC =	tcpdump.c filter.c netstrings.c debug.c \
	ether_print.c ip_print.c arp_print.c tcp_print.c udp_print.c \
	atalk_print.c ns_print.c nfs_print.c icmp_print.c optimize.c \
	pstr.c initdevice.c sl_print.c rip_print.c opstrings.c

SRC =	$(CSRC) tcpgram.y tcplex.l

OBJ =	tcpdump.o filter.o tcpgram.o tcplex.o netstrings.o debug.o \
	ether_print.o ip_print.o arp_print.o tcp_print.o udp_print.o \
	atalk_print.o ns_print.o nfs_print.o icmp_print.o optimize.o \
	pstr.o initdevice.o sl_print.o rip_print.o opstrings.o

HDR = 	filter.h interface.h sample.h sunos4.map.h appletalk.h \
	netstrings.h tcpgram.h pstr.h

AWKS =	atime.awk packetdat.awk send-ack.awk stime.awk

all:	force
	$(MAKE) `arch`

sun3:	sun3/Makefile
	cd sun3; $(MAKE) CFLAGS="-I.. $(CFLAGS_SUN3)" tcpdump

sun3/Makefile: Makefile
	if [ ! -d sun3 ] ; then \
		mkdir sun3; \
		for i in $(SRC) ; do ln -s ../$$i sun3; done; \
	fi
	cp Makefile sun3/Makefile
	cd sun3; $(MAKE) CFLAGS="-I.. $(CFLAGS_SUN3)" depend

# N.B.- symbolic links are used in the subdirectory rather than VPATH
# because at least one Sun cc compiler puts the .o in the wrong place
# when using VPATH and it's almost impossible to get "make depend" to
# do the right thing.

sun4:	sun4/Makefile
	cd sun4; $(MAKE) CFLAGS="-I.. $(CFLAGS_SUN4)" tcpdump

sun4/Makefile: Makefile
	if [ ! -d sun4 ] ; then \
		mkdir sun4; \
		for i in $(SRC) ; do ln -s ../$$i sun4; done; \
	fi
	cp Makefile sun4/Makefile
	cd sun4; $(MAKE) CFLAGS="-I.. $(CFLAGS_SUN4)" depend

tcpdump: $(OBJ)
	$(CC) $(CFLAGS) -o $@ $(OBJ)

tcplex.o: tcplex.c tokdefs.h
tcplex.c: tcplex.l
	rm -f $@
	$(LEX) $<
	mv -f lex.yy.c tcplex.c

tokdefs.h: tcpgram.c
tcpgram.c: tcpgram.y
	rm -f tcpgram.c tokdefs.h
	$(YACC) -d $<
	mv y.tab.c tcpgram.c
	mv y.tab.h tokdefs.h

opstrings.c: ../filter.h
	../makeopstrings ../filter.h > opstrings.c

install: force
	$(MAKE) install.`arch`

install.sun3: sun3/tcpdump
	install -m 4555 sun3/tcpdump $(DESTDIR)$(BINDEST)
	install -c tcpdump.1 $(DESTDIR)$(MANDEST)

install.sun4: sun4/tcpdump
	install -m 4555 sun4/tcpdump $(DESTDIR)$(BINDEST)
	install -c tcpdump.1 $(DESTDIR)$(MANDEST)

lint:	force
	lint $(CSRC) tcplex.c tcpgram.c

clean:
	rm -f *.o tcpdump tcpdump.shar
	rm -rf sun3 sparc

TAGS:	$(SRC) $(HDR)
	etags -t $(SRC) $(HDR)

tags:	$(SRC) $(HDR)
	ctags -t $(SRC) $(HDR)

tar:	force
	tar cf /tmp/tcpdump.tar README Makefile tcpdump.1 \
		$(SRC) $(HDR) $(AWKS) makeopstrings \
		SUNOS4
	compress /tmp/tcpdump.tar

shar:	force
	shar -v -c -p X README Makefile tcpdump.1 \
		$(SRC) $(HDR) $(AWKS) >tcpdump.shar

force:	/tmp

depend:	force
	mkdep $(CFLAGS) $(CSRC)

