1#  Copyright (c) 1993, 1994, 1995, 1996
2#	The Regents of the University of California.  All rights reserved.
3#
4#  Redistribution and use in source and binary forms, with or without
5#  modification, are permitted provided that: (1) source code distributions
6#  retain the above copyright notice and this paragraph in its entirety, (2)
7#  distributions including binary code include the above copyright notice and
8#  this paragraph in its entirety in the documentation or other materials
9#  provided with the distribution, and (3) all advertising materials mentioning
10#  features or use of this software display the following acknowledgement:
11#  ``This product includes software developed by the University of California,
12#  Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13#  the University nor the names of its contributors may be used to endorse
14#  or promote products derived from this software without specific prior
15#  written permission.
16#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17#  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19
20#
21# Various configurable paths (remember to edit Makefile.in, not Makefile)
22#
23
24# Top level hierarchy
25prefix = @prefix@
26exec_prefix = @exec_prefix@
27datarootdir = @datarootdir@
28# Pathname of directory to install the configure program
29bindir = @bindir@
30# Pathname of directory to install the rpcapd daemon
31sbindir = @sbindir@
32# Pathname of directory to install the include files
33includedir = @includedir@
34# Pathname of directory to install the library
35libdir =  @libdir@
36# Pathname of directory to install the man pages
37mandir = @mandir@
38
39# VPATH
40srcdir = @srcdir@
41top_srcdir = @top_srcdir@
42VPATH = @srcdir@
43
44#
45# You shouldn't need to edit anything below.
46#
47
48LD = /usr/bin/ld
49CC = @CC@
50AR = @AR@
51LN_S = @LN_S@
52MKDEP = @MKDEP@
53CCOPT = @V_CCOPT@
54SHLIB_CCOPT = @V_SHLIB_CCOPT@
55INCLS = -I. @V_INCLS@
56DEFS = -DBUILDING_PCAP -Dpcap_EXPORTS @DEFS@ @V_DEFS@
57ADDLOBJS = @ADDLOBJS@
58ADDLARCHIVEOBJS = @ADDLARCHIVEOBJS@
59LIBS = @LIBS@
60CROSSFLAGS=
61CFLAGS = @CFLAGS@   ${CROSSFLAGS}
62LDFLAGS = @LDFLAGS@ ${CROSSFLAGS}
63DYEXT = @DYEXT@
64RPATH = @RPATH@
65DEPENDENCY_CFLAG = @DEPENDENCY_CFLAG@
66PROG=libpcap
67PTHREAD_LIBS=@PTHREAD_LIBS@
68BUILD_RPCAPD=@BUILD_RPCAPD@
69INSTALL_RPCAPD=@INSTALL_RPCAPD@
70
71# Standard CFLAGS for building members of a shared library
72FULL_CFLAGS = $(CCOPT) @V_LIB_CCOPT_FAT@ $(SHLIB_CCOPT) $(INCLS) $(DEFS) $(CFLAGS)
73CXXFLAGS = $(CCOPT) @V_LIB_CCOPT_FAT@ $(SHLIB_CCOPT) $(INCLS) $(DEFS) $(CFLAGS)
74
75INSTALL = @INSTALL@
76INSTALL_PROGRAM = @INSTALL_PROGRAM@
77INSTALL_DATA = @INSTALL_DATA@
78RANLIB = @RANLIB@
79
80LEX = @LEX@
81BISON_BYACC = @BISON_BYACC@
82
83# Explicitly define compilation rule since SunOS 4's make doesn't like gcc.
84# Also, gcc does not remove the .o before forking 'as', which can be a
85# problem if you don't own the file but can write to the directory.
86.c.o:
87	@rm -f $@
88	$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
89
90PLATFORM_C_SRC =	@PLATFORM_C_SRC@
91PLATFORM_CXX_SRC =	@PLATFORM_CXX_SRC@
92MODULE_C_SRC =		@MODULE_C_SRC@
93REMOTE_C_SRC =		@REMOTE_C_SRC@
94COMMON_C_SRC =	pcap.c gencode.c optimize.c nametoaddr.c etherent.c \
95		fmtutils.c pcap-util.c \
96		savefile.c sf-pcap.c sf-pcapng.c pcap-common.c \
97		pcap-usb-linux-common.c bpf_image.c bpf_filter.c bpf_dump.c
98GENERATED_C_SRC = scanner.c grammar.c
99LIBOBJS = @LIBOBJS@
100
101SRC =	$(PLATFORM_C_SRC) $(PLATFORM_CXX_SRC) \
102	$(MODULE_C_SRC) $(REMOTE_C_SRC) $(COMMON_C_SRC) \
103	$(GENERATED_C_SRC)
104
105# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
106# hack the extra indirection, and we have to handle PLATFORM_CXX_SRC
107# differently from the defines for C source
108OBJ =	$(PLATFORM_C_SRC:.c=.o) $(PLATFORM_CXX_SRC:.cpp=.o) \
109	$(MODULE_C_SRC:.c=.o) $(REMOTE_C_SRC:.c=.o) $(COMMON_C_SRC:.c=.o) \
110	$(GENERATED_C_SRC:.c=.o) \
111	$(LIBOBJS)
112
113PUBHDR = \
114	pcap.h \
115	pcap-bpf.h \
116	pcap-namedb.h \
117	pcap/bluetooth.h \
118	pcap/bpf.h \
119	pcap/can_socketcan.h \
120	pcap/compiler-tests.h \
121	pcap/dlt.h \
122	pcap/funcattrs.h \
123	pcap/ipnet.h \
124	pcap/namedb.h \
125	pcap/nflog.h \
126	pcap/pcap-inttypes.h \
127	pcap/pcap.h \
128	pcap/sll.h \
129	pcap/socket.h \
130	pcap/usb.h \
131	pcap/vlan.h
132
133HDR = $(PUBHDR) \
134	arcnet.h \
135	atmuni31.h \
136	diag-control.h \
137	ethertype.h \
138	extract.h \
139	fmtutils.h \
140	ftmacros.h \
141	gencode.h \
142	ieee80211.h \
143	llc.h \
144	nametoaddr.h \
145	nlpid.h \
146	optimize.h \
147	pcap-common.h \
148	pcap-int.h \
149	pcap-rpcap.h \
150	pcap-types.h \
151	pcap-usb-linux-common.h \
152	pcap-util.h \
153	pflog.h \
154	portability.h \
155	ppp.h \
156	rpcap-protocol.h \
157	sf-pcap.h \
158	sf-pcapng.h \
159	sunatmpos.h \
160	varattrs.h
161
162GENHDR = \
163	scanner.h grammar.h
164
165TAGFILES = \
166	$(SRC) $(HDR)
167
168CLEANFILES = $(OBJ) libpcap.a libpcap.so.`cat $(srcdir)/VERSION` \
169	$(PROG)-`cat $(srcdir)/VERSION`.tar.gz $(GENERATED_C_SRC) $(GENHDR) \
170	lex.yy.c pcap-config libpcap.pc
171
172MAN1 = pcap-config.1
173
174MAN3PCAP_EXPAND = \
175	pcap.3pcap.in \
176	pcap_compile.3pcap.in \
177	pcap_datalink.3pcap.in \
178	pcap_dump_open.3pcap.in \
179	pcap_get_tstamp_precision.3pcap.in \
180	pcap_list_datalinks.3pcap.in \
181	pcap_list_tstamp_types.3pcap.in \
182	pcap_open_dead.3pcap.in \
183	pcap_open_offline.3pcap.in \
184	pcap_set_immediate_mode.3pcap.in \
185	pcap_set_tstamp_precision.3pcap.in \
186	pcap_set_tstamp_type.3pcap.in
187
188MAN3PCAP_NOEXPAND = \
189	pcap_activate.3pcap \
190	pcap_breakloop.3pcap \
191	pcap_can_set_rfmon.3pcap \
192	pcap_close.3pcap \
193	pcap_create.3pcap \
194	pcap_datalink_name_to_val.3pcap \
195	pcap_datalink_val_to_name.3pcap \
196	pcap_dump.3pcap \
197	pcap_dump_close.3pcap \
198	pcap_dump_file.3pcap \
199	pcap_dump_flush.3pcap \
200	pcap_dump_ftell.3pcap \
201	pcap_file.3pcap \
202	pcap_fileno.3pcap \
203	pcap_findalldevs.3pcap \
204	pcap_freecode.3pcap \
205	pcap_get_required_select_timeout.3pcap \
206	pcap_get_selectable_fd.3pcap \
207	pcap_geterr.3pcap \
208	pcap_init.3pcap \
209	pcap_inject.3pcap \
210	pcap_is_swapped.3pcap \
211	pcap_lib_version.3pcap \
212	pcap_lookupdev.3pcap \
213	pcap_lookupnet.3pcap \
214	pcap_loop.3pcap \
215	pcap_major_version.3pcap \
216	pcap_next_ex.3pcap \
217	pcap_offline_filter.3pcap \
218	pcap_open_live.3pcap \
219	pcap_set_buffer_size.3pcap \
220	pcap_set_datalink.3pcap \
221	pcap_set_promisc.3pcap \
222	pcap_set_protocol_linux.3pcap \
223	pcap_set_rfmon.3pcap \
224	pcap_set_snaplen.3pcap \
225	pcap_set_timeout.3pcap \
226	pcap_setdirection.3pcap \
227	pcap_setfilter.3pcap \
228	pcap_setnonblock.3pcap \
229	pcap_snapshot.3pcap \
230	pcap_stats.3pcap \
231	pcap_statustostr.3pcap \
232	pcap_strerror.3pcap \
233	pcap_tstamp_type_name_to_val.3pcap \
234	pcap_tstamp_type_val_to_name.3pcap
235
236MAN3PCAP = $(MAN3PCAP_NOEXPAND) $(MAN3PCAP_EXPAND:.in=)
237
238MANFILE = \
239	pcap-savefile.manfile.in
240
241MANMISC = \
242	pcap-filter.manmisc.in \
243	pcap-linktype.manmisc.in \
244	pcap-tstamp.manmisc.in
245
246EXTRA_DIST = \
247	CHANGES \
248	ChmodBPF/ChmodBPF \
249	ChmodBPF/StartupParameters.plist \
250	CREDITS \
251	CMakeLists.txt \
252	INSTALL.md \
253	LICENSE \
254	Makefile.in \
255	Makefile-devel-adds \
256	README.md \
257	doc/README.Win32.md \
258	doc/README.aix \
259	doc/README.dag \
260	doc/README.hpux \
261	doc/README.linux \
262	doc/README.macos \
263	doc/README.septel \
264	doc/README.sita \
265	doc/README.solaris.md \
266	CONTRIBUTING.md \
267	TODO \
268	VERSION \
269	aclocal.m4 \
270	charconv.c \
271	charconv.h \
272	chmod_bpf \
273	cmake_uninstall.cmake.in \
274	cmakeconfig.h.in \
275	cmake/Modules/FindAirPcap.cmake \
276	cmake/Modules/FindDAG.cmake \
277	cmake/Modules/Finddpdk.cmake \
278	cmake/Modules/FindFseeko.cmake \
279	cmake/Modules/FindLFS.cmake \
280	cmake/Modules/FindPacket.cmake \
281	cmake/Modules/FindSNF.cmake \
282	cmake/Modules/FindTC.cmake \
283	cmake/have_siocglifconf.c \
284	config.guess \
285	config.h.in \
286	config.sub \
287	configure \
288	configure.ac \
289	dlpisubs.c \
290	dlpisubs.h \
291	fad-getad.c \
292	fad-gifc.c \
293	fad-glifc.c \
294	grammar.y.in \
295	install-sh \
296	lbl/os-aix4.h \
297	lbl/os-aix7.h \
298	lbl/os-hpux11.h \
299	lbl/os-osf4.h \
300	lbl/os-osf5.h \
301	lbl/os-solaris2.h \
302	lbl/os-sunos4.h \
303	lbl/os-ultrix4.h \
304	libpcap.pc.in \
305	missing/asprintf.c \
306	missing/getopt.c \
307	missing/getopt.h \
308	missing/strlcat.c \
309	missing/strlcpy.c \
310	missing/strtok_r.c \
311	missing/win_asprintf.c \
312	mkdep \
313	msdos/bin2c.c \
314	msdos/makefile \
315	msdos/makefile.dj \
316	msdos/makefile.wc \
317	msdos/pkt_rx0.asm \
318	msdos/pkt_rx1.s \
319	msdos/pktdrvr.c \
320	msdos/pktdrvr.h \
321	msdos/readme.dos \
322	nomkdep \
323	org.tcpdump.chmod_bpf.plist \
324	pcap-airpcap.c \
325	pcap-airpcap.h \
326	pcap-bpf.c \
327	pcap-bt-linux.c \
328	pcap-bt-linux.h \
329	pcap-bt-monitor-linux.c \
330	pcap-bt-monitor-linux.h \
331	pcap-config.in \
332	pcap-dag.c \
333	pcap-dag.h \
334	pcap-dbus.c \
335	pcap-dbus.h \
336	pcap-dll.rc \
337	pcap-dlpi.c \
338	pcap-dos.c \
339	pcap-dos.h \
340	pcap-dpdk.c \
341	pcap-dpdk.h \
342	pcap-enet.c \
343	pcap-haiku.cpp \
344	pcap-int.h \
345	pcap-libdlpi.c \
346	pcap-linux.c \
347	pcap-namedb.h \
348	pcap-new.c \
349	pcap-netfilter-linux.c \
350	pcap-netfilter-linux.h \
351	pcap-netmap.c \
352	pcap-netmap.h \
353	pcap-nit.c \
354	pcap-npf.c \
355	pcap-null.c \
356	pcap-pf.c \
357	pcap-rdmasniff.c \
358	pcap-rdmasniff.h \
359	pcap-rpcap.c \
360	pcap-rpcap-int.h \
361	pcap-septel.c \
362	pcap-septel.h \
363	pcap-sita.h \
364	pcap-sita.c \
365	pcap-sita.html \
366	pcap-snf.c \
367	pcap-snf.h \
368	pcap-snit.c \
369	pcap-snoop.c \
370	pcap-tc.c \
371	pcap-tc.h \
372	pcap-usb-linux.c \
373	pcap-usb-linux.h \
374	rpcap-protocol.c \
375	rpcapd/CMakeLists.txt \
376	rpcapd/Makefile.in \
377	rpcapd/config_params.h \
378	rpcapd/daemon.h \
379	rpcapd/daemon.c \
380	rpcapd/fileconf.c \
381	rpcapd/fileconf.h \
382	rpcapd/log.h \
383	rpcapd/log.c \
384	rpcapd/org.tcpdump.rpcapd.plist \
385	rpcapd/rpcapd.c \
386	rpcapd/rpcapd.h \
387	rpcapd/rpcapd.inetd.conf \
388	rpcapd/rpcapd.manadmin.in \
389	rpcapd/rpcapd-config.manfile.in \
390	rpcapd/rpcapd.rc \
391	rpcapd/rpcapd.socket \
392	rpcapd/rpcapd.xinetd.conf \
393	rpcapd/rpcapd@.service \
394	rpcapd/win32-svc.c \
395	rpcapd/win32-svc.h \
396	sockutils.c \
397	sockutils.h \
398	sslutils.c \
399	sslutils.h \
400	scanner.l \
401	testprogs/CMakeLists.txt \
402	testprogs/Makefile.in \
403	testprogs/can_set_rfmon_test.c \
404	testprogs/capturetest.c \
405	testprogs/filtertest.c \
406	testprogs/findalldevstest.c \
407	testprogs/findalldevstest-perf.c \
408	testprogs/fuzz/CMakeLists.txt \
409	testprogs/fuzz/fuzz_both.c \
410	testprogs/fuzz/fuzz_both.options \
411	testprogs/fuzz/fuzz_filter.c \
412	testprogs/fuzz/fuzz_filter.options \
413	testprogs/fuzz/fuzz_pcap.c \
414	testprogs/fuzz/fuzz_pcap.options \
415	testprogs/fuzz/onefile.c \
416	testprogs/nonblocktest.c \
417	testprogs/opentest.c \
418	testprogs/reactivatetest.c \
419	testprogs/selpolltest.c \
420	testprogs/threadsignaltest.c \
421	testprogs/unix.h \
422	testprogs/valgrindtest.c \
423	testprogs/visopts.py \
424	testprogs/writecaptest.c
425
426TEST_DIST = `git ls-files tests | grep -v 'tests/\..*'`
427
428RELEASE_FILES = $(COMMON_C_SRC) $(HDR) $(MAN1) $(MAN3PCAP_EXPAND) \
429	$(MAN3PCAP_NOEXPAND) $(MANFILE) $(MANMISC) $(EXTRA_DIST) \
430	$(TEST_DIST)
431
432all: libpcap.a shared $(BUILD_RPCAPD) libpcap.pc pcap-config
433
434libpcap.a: $(OBJ)
435	@rm -f $@
436	$(AR) rc $@ $(OBJ) $(ADDLARCHIVEOBJS)
437	$(RANLIB) $@
438
439shared: libpcap.$(DYEXT)
440
441libpcap.so: $(OBJ)
442	@rm -f $@
443	VER=`cat $(srcdir)/VERSION`; \
444	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
445	@V_SHLIB_CMD@ $(LDFLAGS) @V_SHLIB_OPT@ @V_SONAME_OPT@$@.$$MAJOR_VER \
446	    -o $@.$$VER $(OBJ) $(ADDLOBJS) $(LIBS)
447
448#
449# The following rule succeeds, but the result is untested.
450#
451# In macOS, the libpcap dylib has the name "libpcap.A.dylib", with its
452# full path as the install_name, and with the compatibility and current
453# version both set to 1.  The compatibility version is set to 1 so that
454# programs built with a newer version of the library will run against
455# older versions if they don't use APIs available in the newer version
456# but not in the older version.
457#
458# We also use "A" as the major version, and 1 as the compatibility version,
459# but set the current version to the value in VERSION, with any non-numeric
460# stuff stripped off (the compatibility and current version must be of the
461# form X[.Y[.Z]], with Y and Z possibly absent, and with all components
462# numeric).
463#
464libpcap.dylib: $(OBJ)
465	rm -f libpcap*.dylib
466	VER=`cat $(srcdir)/VERSION`; \
467	MAJOR_VER=A; \
468	COMPAT_VER=1; \
469	CURRENT_VER=`sed 's/[^0-9.].*$$//' $(srcdir)/VERSION`; \
470	$(CC) -dynamiclib -undefined error $(LDFLAGS) @V_LIB_LDFLAGS_FAT@ \
471	    -o libpcap.$$VER.dylib $(OBJ) $(ADDLOBJS) $(LIBS) \
472	    -install_name $(libdir)/libpcap.$$MAJOR_VER.dylib \
473	    -compatibility_version $$COMPAT_VER \
474	    -current_version $$CURRENT_VER
475
476#
477# The HP-UX linker manual says that the convention for a versioned library
478# is libXXX.{number}, not libXXX.sl.{number}.  That appears to be the case
479# on at least one HP-UX 11.00 system; libXXX.sl is a symlink to
480# libXXX.{number}.
481#
482# The manual also says "library-level versioning" (think "sonames") was
483# added in HP-UX 10.0.
484#
485# XXX - this assumes we're using the HP linker, rather than the GNU
486# linker, even with GCC.
487#
488libpcap.sl: $(OBJ)
489	@MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
490	rm -f libpcap.$$MAJOR_VER
491	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
492	ld -b $(LDFLAGS) -o libpcap.$$MAJOR_VER +h libpcap.$$MAJOR_VER \
493	    $(OBJ) $(ADDLOBJS) $(LIBS)
494
495#
496# AIX is different from everybody else.  A shared library is an archive
497# library with one or more shared-object components.  We still build a
498# normal static archive library on AIX, for the benefit of the traditional
499# scheme of building libpcap and tcpdump in subdirectories of the
500# same directory, with tcpdump statically linked with the libpcap
501# in question, but we also build a shared library as "libpcap.shareda"
502# and install *it*, rather than the static library, as "libpcap.a".
503#
504libpcap.shareda: $(OBJ)
505	@rm -f $@ shr.o
506	$(CC) $(LDFLAGS) @V_SHLIB_OPT@ -o shr.o $(OBJ) $(ADDLOBJS) $(LIBS)
507	$(AR) rc $@ shr.o
508
509#
510# For platforms that don't support shared libraries (or on which we
511# don't support shared libraries).
512#
513libpcap.none:
514
515scanner.c: $(srcdir)/scanner.l
516	$(LEX) -P pcap_ --header-file=scanner.h --nounput -o scanner.c $<
517scanner.h: scanner.c
518## Recover from the removal of $@
519	@if test -f $@; then :; else \
520		rm -f scanner.c; \
521		$(MAKE) $(MAKEFLAGS) scanner.c; \
522	fi
523
524scanner.o: scanner.c grammar.h
525	$(CC) $(FULL_CFLAGS) -c scanner.c
526
527#
528# Generate the grammar.y file.
529#
530# Some Makes, e.g. AIX Make and Solaris Make, can't handle "--file=$@.tmp:$<";
531# for example, the Solaris 9 make man page says
532#
533#	Because make assigns $< and $* as it would for implicit rules
534#	(according to the suffixes list and the directory contents),
535#	they may be unreliable when used within explicit target entries.
536#
537# and this is an explicit target entry.
538#
539# Therefore, instead of using $<, we explicitly put in $(srcdir)/libpcap.pc.in.
540#
541grammar.y: $(srcdir)/grammar.y.in ./config.status
542	@rm -f $@ $@.tmp
543	./config.status --file=$@.tmp:$(srcdir)/grammar.y.in
544	mv $@.tmp $@
545
546grammar.c: grammar.y
547	$(BISON_BYACC) -p pcap_ -o grammar.c -d $<
548grammar.h: grammar.c
549## Recover from the removal of $@
550	@if test -f $@; then :; else \
551		rm -f grammar.c; \
552		$(MAKE) $(MAKEFLAGS) grammar.c; \
553	fi
554
555grammar.o: grammar.c scanner.h
556	$(CC) $(FULL_CFLAGS) -c grammar.c
557
558gencode.o: $(srcdir)/gencode.c grammar.h scanner.h
559	$(CC) $(FULL_CFLAGS) -c $(srcdir)/gencode.c
560
561asprintf.o: $(srcdir)/missing/asprintf.c
562	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/asprintf.c
563
564snprintf.o: $(srcdir)/missing/snprintf.c
565	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c
566
567strlcat.o: $(srcdir)/missing/strlcat.c
568	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcat.c
569
570strlcpy.o: $(srcdir)/missing/strlcpy.c
571	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcpy.c
572
573strtok_r.o: $(srcdir)/missing/strtok_r.c
574	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strtok_r.c
575
576#
577# Generate the libpcap.pc file.
578#
579# Some Makes, e.g. AIX Make and Solaris Make, can't handle "--file=$@.tmp:$<";
580# for example, the Solaris 9 make man page says
581#
582#	Because make assigns $< and $* as it would for implicit rules
583#	(according to the suffixes list and the directory contents),
584#	they may be unreliable when used within explicit target entries.
585#
586# and this is an explicit target entry.
587#
588# Therefore, instead of using $<, we explicitly put in $(srcdir)/libpcap.pc.in.
589#
590libpcap.pc: $(srcdir)/libpcap.pc.in ./config.status
591	@rm -f $@ $@.tmp
592	./config.status --file=$@.tmp:$(srcdir)/libpcap.pc.in
593	mv $@.tmp $@
594
595#
596# Generate the pcap-config script.  See above.
597#
598pcap-config: $(srcdir)/pcap-config.in ./config.status
599	@rm -f $@ $@.tmp
600	./config.status --file=$@.tmp:$(srcdir)/pcap-config.in
601	mv $@.tmp $@
602	chmod a+x $@
603
604#
605# Remote pcap daemon.
606#
607build-rpcapd: libpcap.a
608	(cd rpcapd; $(MAKE))
609
610#
611# Test programs - not built by default, and not installed.
612#
613testprogs: FORCE
614	(cd testprogs; $(MAKE))
615
616FORCE:
617
618install: install-shared install-archive libpcap.pc pcap-config @INSTALL_RPCAPD@
619	[ -d $(DESTDIR)$(libdir) ] || \
620	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
621	[ -d $(DESTDIR)$(includedir) ] || \
622	    (mkdir -p $(DESTDIR)$(includedir); chmod 755 $(DESTDIR)$(includedir))
623	[ -d $(DESTDIR)$(includedir)/pcap ] || \
624	    (mkdir -p $(DESTDIR)$(includedir)/pcap; chmod 755 $(DESTDIR)$(includedir)/pcap)
625	[ -d $(DESTDIR)$(mandir)/man1 ] || \
626	    (mkdir -p $(DESTDIR)$(mandir)/man1; chmod 755 $(DESTDIR)$(mandir)/man1)
627	[ -d $(DESTDIR)$(mandir)/man3 ] || \
628	    (mkdir -p $(DESTDIR)$(mandir)/man3; chmod 755 $(DESTDIR)$(mandir)/man3)
629	[ -d $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@ ] || \
630	    (mkdir -p $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@; chmod 755 $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@)
631	[ -d $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@ ] || \
632	    (mkdir -p $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@; chmod 755 $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@)
633	for i in $(PUBHDR); do \
634		$(INSTALL_DATA) $(srcdir)/$$i \
635		    $(DESTDIR)$(includedir)/$$i; done
636	[ -d $(DESTDIR)$(bindir) ] || \
637	    (mkdir -p $(DESTDIR)$(bindir); chmod 755 $(DESTDIR)$(bindir))
638	$(INSTALL_PROGRAM) pcap-config $(DESTDIR)$(bindir)/pcap-config
639	[ -d $(DESTDIR)$(libdir)/pkgconfig ] || \
640	    (mkdir -p $(DESTDIR)$(libdir)/pkgconfig; chmod 755 $(DESTDIR)$(libdir)/pkgconfig)
641	$(INSTALL_DATA) libpcap.pc $(DESTDIR)$(libdir)/pkgconfig/libpcap.pc
642	for i in $(MAN1); do \
643		$(INSTALL_DATA) $(srcdir)/$$i \
644		    $(DESTDIR)$(mandir)/man1/$$i; done
645	for i in $(MAN3PCAP_NOEXPAND); do \
646		$(INSTALL_DATA) $(srcdir)/$$i \
647		    $(DESTDIR)$(mandir)/man3/$$i; done
648	for i in $(MAN3PCAP_EXPAND:.in=); do \
649		$(INSTALL_DATA) $$i \
650		    $(DESTDIR)$(mandir)/man3/$$i; done
651	(cd $(DESTDIR)$(mandir)/man3 && \
652	rm -f pcap_datalink_val_to_description.3pcap && \
653	$(LN_S) pcap_datalink_val_to_name.3pcap \
654		 pcap_datalink_val_to_description.3pcap && \
655	rm -f pcap_datalink_val_to_description_or_dlt.3pcap && \
656	$(LN_S) pcap_datalink_val_to_name.3pcap \
657		 pcap_datalink_val_to_description_or_dlt.3pcap && \
658	rm -f pcap_dump_fopen.3pcap && \
659	$(LN_S) pcap_dump_open.3pcap pcap_dump_fopen.3pcap && \
660	rm -f pcap_freealldevs.3pcap && \
661	$(LN_S) pcap_findalldevs.3pcap pcap_freealldevs.3pcap && \
662	rm -f pcap_perror.3pcap && \
663	$(LN_S) pcap_geterr.3pcap pcap_perror.3pcap && \
664	rm -f pcap_sendpacket.3pcap && \
665	$(LN_S) pcap_inject.3pcap pcap_sendpacket.3pcap && \
666	rm -f pcap_free_datalinks.3pcap && \
667	$(LN_S) pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap && \
668	rm -f pcap_free_tstamp_types.3pcap && \
669	$(LN_S) pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap && \
670	rm -f pcap_dispatch.3pcap && \
671	$(LN_S) pcap_loop.3pcap pcap_dispatch.3pcap && \
672	rm -f pcap_minor_version.3pcap && \
673	$(LN_S) pcap_major_version.3pcap pcap_minor_version.3pcap && \
674	rm -f pcap_next.3pcap && \
675	$(LN_S) pcap_next_ex.3pcap pcap_next.3pcap && \
676	rm -f pcap_open_dead_with_tstamp_precision.3pcap && \
677	$(LN_S) pcap_open_dead.3pcap \
678		 pcap_open_dead_with_tstamp_precision.3pcap && \
679	rm -f pcap_open_offline_with_tstamp_precision.3pcap && \
680	$(LN_S) pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap && \
681	rm -f pcap_fopen_offline.3pcap && \
682	$(LN_S) pcap_open_offline.3pcap pcap_fopen_offline.3pcap && \
683	rm -f pcap_fopen_offline_with_tstamp_precision.3pcap && \
684	$(LN_S) pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap && \
685	rm -f pcap_tstamp_type_val_to_description.3pcap && \
686	$(LN_S) pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap && \
687	rm -f pcap_getnonblock.3pcap && \
688	$(LN_S) pcap_setnonblock.3pcap pcap_getnonblock.3pcap)
689	for i in $(MANFILE); do \
690		$(INSTALL_DATA) `echo $$i | sed 's/.manfile.in/.manfile/'` \
691		    $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@/`echo $$i | sed 's/.manfile.in/.@MAN_FILE_FORMATS@/'`; done
692	for i in $(MANMISC); do \
693		$(INSTALL_DATA) `echo $$i | sed 's/.manmisc.in/.manmisc/'` \
694		    $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@/`echo $$i | sed 's/.manmisc.in/.@MAN_MISC_INFO@/'`; done
695
696install-shared: install-shared-$(DYEXT)
697install-shared-so: libpcap.so
698	[ -d $(DESTDIR)$(libdir) ] || \
699	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
700	VER=`cat $(srcdir)/VERSION`; \
701	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
702	$(INSTALL_PROGRAM) libpcap.so.$$VER $(DESTDIR)$(libdir)/libpcap.so.$$VER; \
703	ln -sf libpcap.so.$$VER $(DESTDIR)$(libdir)/libpcap.so.$$MAJOR_VER; \
704	ln -sf libpcap.so.$$MAJOR_VER $(DESTDIR)$(libdir)/libpcap.so
705install-shared-dylib: libpcap.dylib
706	[ -d $(DESTDIR)$(libdir) ] || \
707	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
708	VER=`cat $(srcdir)/VERSION`; \
709	MAJOR_VER=A; \
710	$(INSTALL_PROGRAM) libpcap.$$VER.dylib $(DESTDIR)$(libdir)/libpcap.$$VER.dylib; \
711	ln -sf libpcap.$$VER.dylib $(DESTDIR)$(libdir)/libpcap.$$MAJOR_VER.dylib; \
712	ln -sf libpcap.$$MAJOR_VER.dylib $(DESTDIR)$(libdir)/libpcap.dylib
713install-shared-sl: libpcap.sl
714	[ -d $(DESTDIR)$(libdir) ] || \
715	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
716	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
717	$(INSTALL_PROGRAM) libpcap.$$MAJOR_VER $(DESTDIR)$(libdir)
718	ln -sf libpcap.$$MAJOR_VER $(DESTDIR)$(libdir)/libpcap.sl
719install-shared-shareda: libpcap.shareda
720	#
721	# AIX shared libraries are weird.  They're archive libraries
722	# with one or more shared object components.
723	#
724	[ -d $(DESTDIR)$(libdir) ] || \
725	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
726	$(INSTALL_PROGRAM) libpcap.shareda $(DESTDIR)$(libdir)/libpcap.a
727install-shared-none:
728
729install-archive: install-archive-$(DYEXT)
730install-archive-so install-archive-dylib install-archive-sl install-archive-none: libpcap.a
731	#
732	# Most platforms have separate suffixes for shared and
733	# archive libraries, so we install both.
734	#
735	[ -d $(DESTDIR)$(libdir) ] || \
736	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
737	$(INSTALL_DATA) libpcap.a $(DESTDIR)$(libdir)/libpcap.a
738	$(RANLIB) $(DESTDIR)$(libdir)/libpcap.a
739install-archive-shareda:
740	#
741	# AIX, however, doesn't, so we don't install the archive
742	# library on AIX.
743	#
744
745install-rpcapd:
746	(cd rpcapd; $(MAKE) DESTDIR=$(DESTDIR) install)
747
748uninstall: uninstall-shared uninstall-rpcapd
749	rm -f $(DESTDIR)$(libdir)/libpcap.a
750	for i in $(PUBHDR); do \
751		rm -f $(DESTDIR)$(includedir)/$$i; done
752	-rmdir $(DESTDIR)$(includedir)/pcap
753	rm -f $(DESTDIR)/$(libdir)/pkgconfig/libpcap.pc
754	rm -f $(DESTDIR)/$(bindir)/pcap-config
755	for i in $(MAN1); do \
756		rm -f $(DESTDIR)$(mandir)/man1/$$i; done
757	for i in $(MAN3PCAP); do \
758		rm -f $(DESTDIR)$(mandir)/man3/$$i; done
759	rm -f $(DESTDIR)$(mandir)/man3/pcap_datalink_val_to_description.3pcap
760	rm -f $(DESTDIR)$(mandir)/man3/pcap_datalink_val_to_description_or_dlt.3pcap
761	rm -f $(DESTDIR)$(mandir)/man3/pcap_dump_fopen.3pcap
762	rm -f $(DESTDIR)$(mandir)/man3/pcap_freealldevs.3pcap
763	rm -f $(DESTDIR)$(mandir)/man3/pcap_perror.3pcap
764	rm -f $(DESTDIR)$(mandir)/man3/pcap_sendpacket.3pcap
765	rm -f $(DESTDIR)$(mandir)/man3/pcap_free_datalinks.3pcap
766	rm -f $(DESTDIR)$(mandir)/man3/pcap_free_tstamp_types.3pcap
767	rm -f $(DESTDIR)$(mandir)/man3/pcap_dispatch.3pcap
768	rm -f $(DESTDIR)$(mandir)/man3/pcap_minor_version.3pcap
769	rm -f $(DESTDIR)$(mandir)/man3/pcap_next.3pcap
770	rm -f $(DESTDIR)$(mandir)/man3/pcap_open_dead_with_tstamp_precision.3pcap
771	rm -f $(DESTDIR)$(mandir)/man3/pcap_open_offline_with_tstamp_precision.3pcap
772	rm -f $(DESTDIR)$(mandir)/man3/pcap_fopen_offline.3pcap
773	rm -f $(DESTDIR)$(mandir)/man3/pcap_fopen_offline_with_tstamp_precision.3pcap
774	rm -f $(DESTDIR)$(mandir)/man3/pcap_getnonblock.3pcap
775	rm -f $(DESTDIR)$(mandir)/man3/pcap_tstamp_type_val_to_description.3pcap
776	for i in $(MANFILE); do \
777		rm -f $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@/`echo $$i | sed 's/.manfile.in/.@MAN_FILE_FORMATS@/'`; done
778	for i in $(MANMISC); do \
779		rm -f $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@/`echo $$i | sed 's/.manmisc.in/.@MAN_MISC_INFO@/'`; done
780
781uninstall-shared: uninstall-shared-$(DYEXT)
782uninstall-shared-so:
783	VER=`cat $(srcdir)/VERSION`; \
784	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
785	rm -f $(DESTDIR)$(libdir)/libpcap.so.$$VER; \
786	rm -f $(DESTDIR)$(libdir)/libpcap.so.$$MAJOR_VER; \
787	rm -f $(DESTDIR)$(libdir)/libpcap.so
788uninstall-shared-dylib:
789	VER=`cat $(srcdir)/VERSION`; \
790	MAJOR_VER=A; \
791	rm -f $(DESTDIR)$(libdir)/libpcap.$$VER.dylib; \
792	rm -f $(DESTDIR)$(libdir)/libpcap.$$MAJOR_VER.dylib; \
793	rm -f $(DESTDIR)$(libdir)/libpcap.dylib
794uninstall-shared-sl:
795	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
796	rm -f $(DESTDIR)$(libdir)/libpcap.$$MAJOR_VER; \
797	rm -f $(DESTDIR)$(libdir)/libpcap.sl
798uninstall-shared-shareda:
799	rm -f $(DESTDIR)$(libdir)/libpcap.a
800uninstall-shared-none:
801
802uninstall-rpcapd:
803	(cd rpcapd; $(MAKE) DESTDIR=$(DESTDIR) uninstall)
804
805clean:
806	rm -f $(CLEANFILES)
807	(cd rpcapd; $(MAKE) clean)
808	(cd testprogs; $(MAKE) clean)
809
810distclean: clean
811	rm -f Makefile grammar.y config.cache config.log config.status \
812	    config.h config.h.in~ configure~ configure.ac~ \
813	    net os-proto.h libpcap.pc pcap-config stamp-h stamp-h.in
814	rm -f $(MAN3PCAP_EXPAND:.in=) $(MANFILE:.in=) $(MANMISC:.in=)
815	rm -rf autom4te.cache
816	(cd rpcapd; $(MAKE) distclean)
817	(cd testprogs; $(MAKE) distclean)
818
819extags: $(TAGFILES)
820	ctags $(TAGFILES)
821
822tags: $(TAGFILES)
823	ctags -wtd $(TAGFILES)
824
825releasetar:
826	@TAG=$(PROG)-`cat VERSION` && \
827	if git show-ref --tags --quiet --verify -- "refs/tags/$$TAG"; then \
828	    git archive --prefix="$$TAG"/ -o "$$TAG".tar.gz "$$TAG" \
829	    $(RELEASE_FILES) && \
830	    echo "Archive build from tag $$TAG."; \
831	else \
832	    git archive --prefix="$$TAG"/ -o "$$TAG".tar.gz HEAD \
833	    $(RELEASE_FILES) && \
834	    echo "No $$TAG tag. Archive build from HEAD."; \
835	fi
836
837depend:	$(GENERATED_C_SRC) $(GENHDR)
838	$(MKDEP) -c "$(CC)" -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
839	(cd rpcapd; $(MAKE) depend)
840	(cd testprogs; $(MAKE) depend)
841
842shellcheck:
843	shellcheck -f gcc -e SC2006 build.sh build_matrix.sh build_common.sh
844