1
2#  Copyright (c) 1988-1990 The Regents of the University of California.
3#  All rights reserved.
4#
5#  Redistribution and use in source and binary forms, with or without
6#  modification, are permitted provided that: (1) source code distributions
7#  retain the above copyright notice and this paragraph in its entirety, (2)
8#  distributions including binary code include the above copyright notice and
9#  this paragraph in its entirety in the documentation or other materials
10#  provided with the distribution, and (3) all advertising materials mentioning
11#  features or use of this software display the following acknowledgement:
12#  ``This product includes software developed by the University of California,
13#  Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14#  the University nor the names of its contributors may be used to endorse
15#  or promote products derived from this software without specific prior
16#  written permission.
17#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18#  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20#
21# @(#) $Header: /usr/staff/martinh/tcpview/RCS/Makefile,v 1.3 1992/11/17 21:59:47 martinh Exp martinh $ (UW)
22
23# Possible Options:
24#  -UCSLIP	include support for kernel slip interface
25#  -DPPP	include support for point to point protocol
26#  -DIBMRTPC	enable the MERIT additions to the Stanford Enetfilter
27#  -DNOVFPRINTF	simulate vfprintf() on systems that don't have it
28#
29# CSLIP and PPP work only under BPF.
30#
31DEFINES = -UCSLIP -DPPP
32INCLUDES = -I.. -I$(LOCALBASE)/include
33LIB =-ll
34
35# These are for the Sun4 version
36#CCOPT = -O2 -Bstatic
37#INCLUDES = -I.. -I/usr/openwin/include
38#LIB =  -lresolv
39
40XLIB= -lXm -lXt -lX11
41
42# The installed binary is owned by this group.
43GROUP = wheel
44
45# Full pathname of where to install the binaries
46BINDEST = $(PREFIX)/bin
47TCPSLICE_BINDEST = $(PREFIX)/bin #unused (FreeBSD port)
48
49# Full pathname of where to install tcpview support files
50TCPVIEW_DIR = $(PREFIX)/lib/tcpview
51FILTER_DIR = $(PREFIX)/lib/tcpview/filters
52
53# Full pathname of where to install the manual entries
54TCPDUMP_MANDEST = $(PREFIX)/man/man1/tcpdump.1
55TCPVIEW_MANDEST = $(PREFIX)/man/man1/tcpview.1
56TCPSLICE_MANDEST = $(PREFIX)/man/man1/tcpslice.1
57
58# Standard CFLAGS
59STANDARD_CFLAGS = $(CCOPT) $(DEFINES) $(INCLUDES)
60
61# CFLAGS definitions per machine vs. os
62#hp300-bsd#CFLAGS = $(STANDARD_CFLAGS)
63#mips-ultrix#CFLAGS = $(STANDARD_CFLAGS)
64#rt-bsd#CFLAGS = $(STANDARD_CFLAGS) -U__STDC__
65#sun3-sunos3#CFLAGS = $(STANDARD_CFLAGS)
66#sun3-sunos4#CFLAGS = $(STANDARD_CFLAGS)
67#sun4-sunos4#CFLAGS = $(STANDARD_CFLAGS)
68#sun4-bsd#CFLAGS = $(STANDARD_CFLAGS)
69#tahoe-bsd#CFLAGS = $(STANDARD_CFLAGS)
70#vax-bsd#CFLAGS = $(STANDARD_CFLAGS)
71#vax-ultrix#
72CFLAGS += $(STANDARD_CFLAGS)
73#mips-irix#CFLAGS = $(STANDARD_CFLAGS) -D_BSD_COMPAT
74
75SUBDIRS = hp300-bsd mips-ultrix sun?-sunos? sun4-bsd tahoe-bsd vax-bsd \
76    vax-ultrix rt-bsd mips-irix
77
78# Change these to cc/yacc if you don't have gcc, and/or bison.
79# DON'T use flex for lex
80CC = cc
81LEX = lex
82YACC = bison -y
83MAKE = make
84
85# Script (or program) that returns the machine and os types,
86# or just edit in the name yourself.
87MD=`./mdtype`
88OS=`./ostype`
89
90# Explicitly define compiliation rule since SunOS 4's make doesn't like gcc.
91# Also, gcc does not remove the .o before forking 'as', which can be a
92# problem if you don't own the file but can write to the directory.
93.c.o:
94#	rm -f $@; $(CC) $(CFLAGS) -c $*.c
95	$(CC) $(CFLAGS) -c $*.c
96
97# List all C source files here
98
99TCPDUMP_CSRC =	tcpdump.c addrtoname.c hd.c \
100	print-ether.c print-ip.c print-arp.c print-tcp.c print-udp.c \
101	print-atalk.c print-domain.c print-tftp.c print-bootp.c print-nfs.c \
102	print-icmp.c nametoaddr.c print-sl.c print-ppp.c print-rip.c \
103	print-snmp.c print-ntp.c print-null.c print-egp.c print-ospf.c \
104	print-fddi.c print-sunrpc.c savefile.c util.c etherent.c inet.c \
105	gencode.c optimize.c bpf_dump.c bpf_filter.c bpf_image.c \
106	sniffer_file.c
107
108TCPVIEW_CSRC = tcpview.c callbacks.c motifutils.c dialogs.c filter-dialog.c \
109        print-ether.c print-arp.c print-ip.c print-tcp.c print-udp.c \
110        print-nfs.c print-atalk.c print-tftp.c print-sunrpc.c print-rip.c \
111        print-icmp.c print-bootp.c print-snmp.c print-ntp.c print-domain.c \
112        print-ospf.c print-egp.c tv_addrtoname.c detail-ether.c detail-arp.c \
113        detail-ip.c detail-tcp.c detail-udp.c print-fddi.c print-ppp.c \
114        print-sl.c print-null.c gencode.c optimize.c nametoaddr.c  \
115        savefile.c tv_etherent.c sniffer_file.c hd.c \
116        util.c print.c bpf_filter.c getservent.c filter-stream.c text.c \
117        inet.c capture.c detail-rip.c detail-icmp.c detail-domain.c detail-snmp.c
118
119TCPSLICE_CSRC = \
120	tcpslice.c gwtm2secs.c search.c
121
122TCPSLICE_LINT_SRC = \
123	$(TCPSLICE_CSRC) savefile.c bpf_filter.c md.c util.c
124
125TCPDUMP_SRC =	$(TCPDUMP_CSRC) tcpgram.y tcplex.l \
126	$(TCPSLICE_CSRC)
127
128TCPVIEW_SRC =	$(TCPVIEW_CSRC) tcpgram.y tcplex.l
129
130FILTER_SRC = hex.c bgp.c generic.c telnet.c
131
132SRC =	$(TCPVIEW_SRC) $(TCPSLICE_CSRC) tcpdump.c etherent.c addrtoname.c \
133	bpf_dump.c bpf_image.c $(FILTER_SRC)
134
135MSRC =	md-hp300.c md-mips.c md-sun3.c md-sun4.c md-vax.c md-rt.c
136
137PSRC =	pcap-nit.c pcap-pf.c pcap-snit.c pcap-bpf.c pcap-enet.c
138
139OSRC =	os-sunos3.c os-sunos4.c os-bsd.c os-ultrix.c
140
141TCPDUMP_OBJ =	tcpdump.o tcpgram.o tcplex.o addrtoname.o \
142	print-ether.o print-ip.o print-arp.o print-tcp.o print-udp.o \
143	print-atalk.o print-domain.o print-tftp.o print-bootp.o print-nfs.o \
144	print-icmp.o nametoaddr.o print-sl.o print-ppp.o print-rip.o \
145	print-snmp.o print-ntp.o print-null.o print-egp.o print-ospf.o \
146	print-fddi.o print-sunrpc.o pcap.o md.o os.o \
147	savefile.o util.o etherent.o inet.o gencode.o optimize.o \
148	bpf_dump.o bpf_filter.o bpf_image.o version.o sniffer_file.o hd.o
149
150TCPVIEW_OBJ = tcpview.o version.o motifutils.o dialogs.o filter-dialog.o \
151        print-ether.o print-arp.o print-ip.o print-tcp.o print-udp.o \
152        print-nfs.o print-atalk.o print-tftp.o print-sunrpc.o print-rip.o \
153        print-icmp.o print-bootp.o print-snmp.o print-ntp.o print-domain.o \
154        print-ospf.o print-egp.o tv_addrtoname.o detail-ether.o detail-arp.o \
155        detail-ip.o detail-tcp.o detail-udp.o print-fddi.o print-ppp.o \
156        print-sl.o print-null.o gencode.o optimize.o nametoaddr.o tcpgram.o \
157        savefile.o md.o os.o tv_etherent.o sniffer_file.o hd.o \
158        util.o print.o tcplex.o bpf_filter.o getservent.o filter-stream.o text.o \
159        pcap.o inet.o capture.o callbacks.o detail-rip.o detail-icmp.o \
160	detail-domain.o detail-snmp.o
161
162TCPSLICE_OBJ = \
163	tcpslice.o gwtm2secs.o search.o savefile.o bpf_filter.o md.o util.o
164
165HDR =	interface.h appletalk.h addrtoname.h ip_icmp.h \
166	bootp.h savefile.h etherproto.h nametoaddr.h \
167	etherent.h ntp.h gencode.h extract.h ospf.h tcpview.h motif.h filter.h snmp.h
168
169MHDR =	md-hp300.h md-sun3.h md-sun4.h md-mips.h md-vax.h md-rt.h
170
171OHDR =	os-bsd.h os-sunos3.h os-sunos4.h os-ultrix.h
172
173TAGHDR=	/usr/include/netinet/in.h \
174	/usr/include/netinet/udp.h \
175	/usr/include/netinet/tcp.h \
176	/usr/include/arpa/tftp.h \
177	/usr/include/netinet/if_ether.h
178
179# These files are automatically generated.
180#
181GEN =	tokdefs.h tcpgram.c tcplex.c version.h version.c
182
183AWKS =	atime.awk packetdat.awk send-ack.awk stime.awk
184
185# "all" must come before tcpdump so we can delete it with sed
186all: submake
187
188tcpdump: $(TCPDUMP_OBJ)
189	$(CC) $(CFLAGS) -o $@ $(TCPDUMP_OBJ) $(LIB)
190
191tcpview: $(TCPVIEW_OBJ)
192	$(CC) $(CFLAGS) -o $@ $(TCPVIEW_OBJ) -L${LOCALBASE}/lib $(XLIB) $(LIB)
193
194tcpslice: $(TCPSLICE_OBJ)
195	$(CC) $(CFLAGS) -o $@ $(TCPSLICE_OBJ)
196
197FILTERS: BGP generic telnet
198
199BGP:	bgp.o hex.o
200	$(CC) $(CFLAGS) -o $@ bgp.o hex.o
201
202generic:	generic.o hex.o
203	$(CC) $(CFLAGS) -o $@ generic.o hex.o
204
205telnet:	telnet.o hex.o
206	$(CC) $(CFLAGS) -o $@ telnet.o hex.o
207
208submake: force
209	-@dir=$(MD)-$(OS)-tcpdump; \
210	if [ ! -d $$dir ]; then ${MAKE} ${MFLAGS} config1; fi; \
211	set -x; \
212	${MAKE} -C $$dir ${MFLAGS} tcpdump tcpslice
213	-@dir=$(MD)-$(OS)-tcpview; \
214	if [ ! -d $$dir ]; then ${MAKE} ${MFLAGS} config2; fi; \
215	set -x; \
216	${MAKE} -C $$dir ${MFLAGS} DEFINES="${DEFINES} -DTCPVIEW" tcpview; \
217	${MAKE} -C $$dir ${MFLAGS} FILTERS
218
219# N.B.- symbolic links are used in the subdirectory rather than VPATH
220# because at least one Sun cc compiler puts the .o in the wrong place
221# when using VPATH and it's almost impossible to get "make depend" to
222# do the right thing.
223
224config1:
225	-@md=$(MD); os=$(OS); dir=$$md-$$os-tcpdump; list=; \
226	if [ -f /dev/bpf0 ] ; then pcap="bpf"; \
227	elif [ $$os = "sunos3" ] ; then pcap="nit"; \
228	elif [ $$os = "sunos4" ] ; then pcap="snit"; \
229	elif [ $$os = "ultrix" ] ; then pcap="pf"; \
230	elif [ -f /usr/include/net/enet.h ] ; then pcap="enet"; \
231	else pcap="bpf"; fi; \
232	for i in $(TCPDUMP_SRC) $(HDR); do list="../$$i $$list"; done; \
233	set -x; mkdir $$dir; chmod ug+w $$dir; ln -s $$list $$dir; \
234	ln -s ../md-$$md.c $$dir/md.c; ln -s ../md-$$md.h $$dir/md.h; \
235	ln -s ../os-$$os.c $$dir/os.c; ln -s ../os-$$os.h $$dir/os.h; \
236	ln -s ../pcap-$$pcap.c $$dir/pcap.c; \
237	ln -s ../VERSION $$dir/VERSION; \
238	ln -s ../TCPVIEW_VERSION $$dir/TCPVIEW_VERSION; \
239	ln -s ../net $$dir/net; \
240	sed -e "/^all:/d" -e "s/^#$$dir#//" Makefile >$$dir/Makefile; \
241	chmod ug+w $$dir/Makefile; \
242	${MAKE} -C $$dir ${MFLAGS} depend1
243
244config2:
245	-@md=$(MD); os=$(OS); dir=$$md-$$os-tcpview; list=; \
246	if [ -f /dev/bpf0 ] ; then pcap="bpf"; \
247	elif [ $$os = "sunos3" ] ; then pcap="nit"; \
248	elif [ $$os = "sunos4" ] ; then pcap="snit"; \
249	elif [ $$os = "ultrix" ] ; then pcap="pf"; \
250	elif [ -f /usr/include/net/enet.h ] ; then pcap="enet"; \
251	else pcap="bpf"; fi; \
252	for i in $(TCPVIEW_SRC) $(HDR) $(FILTER_SRC); do list="../$$i $$list"; done; \
253	set -x; mkdir $$dir; chmod ug+w $$dir; ln -s $$list $$dir; \
254	ln -s ../md-$$md.c $$dir/md.c; ln -s ../md-$$md.h $$dir/md.h; \
255	ln -s ../os-$$os.c $$dir/os.c; ln -s ../os-$$os.h $$dir/os.h; \
256	ln -s ../pcap-$$pcap.c $$dir/pcap.c; \
257	ln -s ../VERSION $$dir/VERSION; \
258	ln -s ../TCPVIEW_VERSION $$dir/TCPVIEW_VERSION; \
259	sed -e "/^all:/d" -e "s/^#$$dir#//" Makefile >$$dir/Makefile; \
260	chmod ug+w $$dir/Makefile; \
261	${MAKE} -C $$dir ${MFLAGS} depend2
262
263tcplex.c: tcplex.l
264#	rm -f $@
265	$(LEX) $<
266	mv -f lex.yy.c tcplex.c
267
268tokdefs.h: tcpgram.c
269tcpgram.c: tcpgram.y
270#	rm -f tcpgram.c tokdefs.h
271	$(YACC) -d $<
272	mv y.tab.c tcpgram.c
273	mv y.tab.h tokdefs.h
274
275version.o: version.c
276version.c version.h: VERSION TCPVIEW_VERSION
277#	rm -f version.c ;
278	sed 's/.*/char version[] = "&";/' VERSION > version.c
279	sed 's/.*/char tcpview_version[] = "&";/' TCPVIEW_VERSION >> version.c
280	set `sed 's/\([0-9]*\)\.\([0-9]*\).*/\1 \2/' VERSION` ; \
281		{ echo '#define VERSION_MAJOR' $$1 ; \
282		  echo '#define VERSION_MINOR' $$2 ; } > version.h
283
284# in case mkdep doesn't work
285savefile.o: version.h
286tcpslice.o: version.h
287
288install: force
289	-mkdir -p $(TCPVIEW_DIR)
290	-mkdir -p $(FILTER_DIR)
291#	@dir=$(MD)-$(OS)-tcpdump; set -x; \
292#	cd $$dir ; \
293#	    install -m 755 -g $(GROUP) -c tcpdump $(DESTDIR)$(BINDEST); \
294#	    install -m 755 -c tcpslice $(DESTDIR)$(TCPSLICE_BINDEST)
295	@dir=$(MD)-$(OS)-tcpview; set -x; \
296	${BSD_INSTALL_PROGRAM} -c $$dir/tcpview $(BINDEST); \
297	${BSD_INSTALL_PROGRAM} -c $$dir/BGP $(FILTER_DIR); \
298	${BSD_INSTALL_PROGRAM} -c $$dir/telnet $(FILTER_DIR); \
299	${BSD_INSTALL_PROGRAM} -c $$dir/generic $(FILTER_DIR); \
300	${BSD_INSTALL_DATA} -c $$dir/../DOC/hosts $(TCPVIEW_DIR); \
301	${BSD_INSTALL_DATA} -c $$dir/../DOC/manuf $(TCPVIEW_DIR); \
302	${BSD_INSTALL_MAN} -c $$dir/../DOC/tcpview.1 $(TCPVIEW_MANDEST); \
303#	install -m 444 -c tcpdump.1 $(DESTDIR)$(TCPDUMP_MANDEST); \
304#	install -m 444 -c tcpslice.1 $(DESTDIR)$(TCPSLICE_MANDEST)
305
306lint:	force
307	lint -hbxn $(CSRC) | \
308	    grep -v 'struct/union .* never defined' | \
309	    grep -v 'possible pointer alignment problem'
310	lint -hbxn $(TCPSLICE_LINT_SRC) | \
311	    grep -v 'struct/union .* never defined' | \
312	    grep -v 'possible pointer alignment problem'
313
314# This might be futile
315lint.ultrix: force
316	lint $(CFLAGS_ULTRIX) $(CSRC) tcplex.c tcpgram.c
317
318clean:
319	rm -f *.o tcpdump tcpview tcpslice tcpdump.shar $(GEN) ; \
320	rm -rf $(SUBDIRS)
321
322TAGFILES = $(SRC) md.c os.c pcap.c $(HDR) md.h os.h $(TAGHDR)
323
324tags:	$(TAGFILES)
325	ctags -wtd $(TAGFILES)
326
327TARFILES = 	VERSION TCPVIEW_VERSION Makefile mkdep \
328		mdtype ostype ostype.awk \
329		$(SRC) $(MSRC) $(OSRC) $(PSRC) \
330		$(HDR) $(MHDR) $(OHDR) $(FILTER_SRC) \
331		SUNOS4 net
332
333tar:	force
334	@v=`cat TCPVIEW_VERSION`; dirname=tcpview-$$v; tarname=/tmp/$$dirname.tar; \
335	cd .. ; \
336	if [ ! -d $$dirname ] ; then \
337		ln -s tcpview $$dirname ; \
338	fi ; \
339	list="" ; \
340	for i in $(TARFILES) ; do list="$$list $$dirname/$$i" ; done; \
341	set -x; \
342	tar cf $$tarname $$list; \
343	tar ufhFF $$tarname $$dirname/bpf; \
344	tar ufhFF $$tarname $$dirname/DOC; \
345	tar ufhFF $$tarname $$dirname/UTIL; \
346	rm -f $$tarname.Z; \
347	compress $$tarname
348
349force:	/tmp
350depend1:	force
351	@set -x ; \
352	rm -f $(GEN) ; \
353	grep '^#include' tcpgram.y > tcpgram.c ; \
354	grep '^#include' tcplex.l > tcplex.c ; \
355	touch version.h tokdefs.h
356	-../mkdep $(DEFINES) $(INCLUDES) $(TCPDUMP_CSRC) $(TCPSLICE_CSRC) \
357		tcpgram.c tcplex.c
358	rm -f $(GEN)
359
360depend2:	force
361	@set -x ; \
362	rm -f $(GEN) ; \
363	grep '^#include' tcpgram.y > tcpgram.c ; \
364	grep '^#include' tcplex.l > tcplex.c ; \
365	touch version.h tokdefs.h
366	-../mkdep $(DEFINES) $(INCLUDES) $(TCPVIEW_CSRC) \
367		tcpgram.c tcplex.c
368	rm -f $(GEN)
369