xref: /freebsd/contrib/libpcap/Makefile.in (revision ae1a0648b05acf798816e7b83b3c10856de5c8e5)
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)
73
74INSTALL = @INSTALL@
75INSTALL_PROGRAM = @INSTALL_PROGRAM@
76INSTALL_DATA = @INSTALL_DATA@
77RANLIB = @RANLIB@
78
79LEX = @LEX@
80BISON_BYACC = @BISON_BYACC@
81
82# Explicitly define compilation rule since SunOS 4's make doesn't like gcc.
83# Also, gcc does not remove the .o before forking 'as', which can be a
84# problem if you don't own the file but can write to the directory.
85.c.o:
86	@rm -f $@
87	$(CC) $(FULL_CFLAGS) -c $(srcdir)/$*.c
88
89PLATFORM_C_SRC =	@PLATFORM_C_SRC@
90MODULE_C_SRC =		@MODULE_C_SRC@
91REMOTE_C_SRC =		@REMOTE_C_SRC@
92COMMON_C_SRC =	pcap.c gencode.c optimize.c nametoaddr.c etherent.c \
93		fmtutils.c pcap-util.c \
94		savefile.c sf-pcap.c sf-pcapng.c pcap-common.c \
95		bpf_image.c bpf_filter.c bpf_dump.c
96GENERATED_C_SRC = scanner.c grammar.c
97LIBOBJS = @LIBOBJS@
98
99SRC =	$(PLATFORM_C_SRC) \
100	$(MODULE_C_SRC) $(REMOTE_C_SRC) $(COMMON_C_SRC) \
101	$(GENERATED_C_SRC)
102
103# We would like to say "OBJ = $(SRC:.c=.o)" but Ultrix's make cannot
104# hack the extra indirection
105OBJ =	$(PLATFORM_C_SRC:.c=.o) \
106	$(MODULE_C_SRC:.c=.o) $(REMOTE_C_SRC:.c=.o) $(COMMON_C_SRC:.c=.o) \
107	$(GENERATED_C_SRC:.c=.o) \
108	$(LIBOBJS)
109
110PUBHDR = \
111	pcap.h \
112	pcap-bpf.h \
113	pcap-namedb.h \
114	pcap/bluetooth.h \
115	pcap/bpf.h \
116	pcap/can_socketcan.h \
117	pcap/compiler-tests.h \
118	pcap/dlt.h \
119	pcap/funcattrs.h \
120	pcap/ipnet.h \
121	pcap/namedb.h \
122	pcap/nflog.h \
123	pcap/pcap-inttypes.h \
124	pcap/pcap.h \
125	pcap/sll.h \
126	pcap/socket.h \
127	pcap/usb.h \
128	pcap/vlan.h
129
130HDR = $(PUBHDR) \
131	arcnet.h \
132	atmuni31.h \
133	diag-control.h \
134	ethertype.h \
135	extract.h \
136	fmtutils.h \
137	ftmacros.h \
138	gencode.h \
139	ieee80211.h \
140	llc.h \
141	nametoaddr.h \
142	nlpid.h \
143	optimize.h \
144	pcap-common.h \
145	pcap-int.h \
146	pcap-rpcap.h \
147	pcap-types.h \
148	pcap-usb-linux-common.h \
149	pcap-util.h \
150	pflog.h \
151	portability.h \
152	ppp.h \
153	rpcap-protocol.h \
154	sf-pcap.h \
155	sf-pcapng.h \
156	sunatmpos.h \
157	thread-local.h \
158	varattrs.h
159
160GENHDR = \
161	scanner.h grammar.h
162
163TAGFILES = \
164	$(SRC) $(HDR)
165
166CLEANFILES = $(OBJ) libpcap.a libpcap.so.`cat $(srcdir)/VERSION` \
167	$(PROG)-`cat $(srcdir)/VERSION`.tar.gz $(GENERATED_C_SRC) $(GENHDR) \
168	lex.yy.c pcap-config libpcap.pc libpcap.$(DYEXT)
169
170MAN1 = pcap-config.1
171
172MAN3PCAP_EXPAND = \
173	pcap.3pcap.in \
174	pcap_compile.3pcap.in \
175	pcap_datalink.3pcap.in \
176	pcap_dump_open.3pcap.in \
177	pcap_get_tstamp_precision.3pcap.in \
178	pcap_list_datalinks.3pcap.in \
179	pcap_list_tstamp_types.3pcap.in \
180	pcap_open_dead.3pcap.in \
181	pcap_open_offline.3pcap.in \
182	pcap_set_immediate_mode.3pcap.in \
183	pcap_set_tstamp_precision.3pcap.in \
184	pcap_set_tstamp_type.3pcap.in
185
186MAN3PCAP_NOEXPAND = \
187	pcap_activate.3pcap \
188	pcap_breakloop.3pcap \
189	pcap_can_set_rfmon.3pcap \
190	pcap_close.3pcap \
191	pcap_create.3pcap \
192	pcap_datalink_name_to_val.3pcap \
193	pcap_datalink_val_to_name.3pcap \
194	pcap_dump.3pcap \
195	pcap_dump_close.3pcap \
196	pcap_dump_file.3pcap \
197	pcap_dump_flush.3pcap \
198	pcap_dump_ftell.3pcap \
199	pcap_file.3pcap \
200	pcap_fileno.3pcap \
201	pcap_findalldevs.3pcap \
202	pcap_freecode.3pcap \
203	pcap_get_required_select_timeout.3pcap \
204	pcap_get_selectable_fd.3pcap \
205	pcap_geterr.3pcap \
206	pcap_init.3pcap \
207	pcap_inject.3pcap \
208	pcap_is_swapped.3pcap \
209	pcap_lib_version.3pcap \
210	pcap_lookupdev.3pcap \
211	pcap_lookupnet.3pcap \
212	pcap_loop.3pcap \
213	pcap_major_version.3pcap \
214	pcap_next_ex.3pcap \
215	pcap_offline_filter.3pcap \
216	pcap_open_live.3pcap \
217	pcap_set_buffer_size.3pcap \
218	pcap_set_datalink.3pcap \
219	pcap_set_promisc.3pcap \
220	pcap_set_protocol_linux.3pcap \
221	pcap_set_rfmon.3pcap \
222	pcap_set_snaplen.3pcap \
223	pcap_set_timeout.3pcap \
224	pcap_setdirection.3pcap \
225	pcap_setfilter.3pcap \
226	pcap_setnonblock.3pcap \
227	pcap_snapshot.3pcap \
228	pcap_stats.3pcap \
229	pcap_statustostr.3pcap \
230	pcap_strerror.3pcap \
231	pcap_tstamp_type_name_to_val.3pcap \
232	pcap_tstamp_type_val_to_name.3pcap
233
234MAN3PCAP = $(MAN3PCAP_NOEXPAND) $(MAN3PCAP_EXPAND:.in=)
235
236MANFILE = \
237	pcap-savefile.manfile.in
238
239MANMISC = \
240	pcap-filter.manmisc.in \
241	pcap-linktype.manmisc.in \
242	pcap-tstamp.manmisc.in
243
244EXTRA_DIST = \
245	CHANGES \
246	ChmodBPF/ChmodBPF \
247	ChmodBPF/StartupParameters.plist \
248	CREDITS \
249	CMakeLists.txt \
250	INSTALL.md \
251	LICENSE \
252	Makefile.in \
253	Makefile-devel-adds \
254	README.md \
255	doc/README.aix \
256	doc/README.dag \
257	doc/README.haiku.md \
258	doc/README.hpux \
259	doc/README.linux \
260	doc/README.macos \
261	doc/README.septel \
262	doc/README.sita \
263	doc/README.solaris.md \
264	doc/README.windows.md \
265	CONTRIBUTING.md \
266	TODO \
267	VERSION \
268	aclocal.m4 \
269	autogen.sh \
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.sub \
286	configure.ac \
287	dlpisubs.c \
288	dlpisubs.h \
289	fad-getad.c \
290	fad-gifc.c \
291	fad-glifc.c \
292	grammar.y.in \
293	install-sh \
294	lbl/os-aix4.h \
295	lbl/os-aix7.h \
296	lbl/os-hpux11.h \
297	lbl/os-osf4.h \
298	lbl/os-osf5.h \
299	lbl/os-solaris2.h \
300	lbl/os-sunos4.h \
301	lbl/os-ultrix4.h \
302	libpcap.pc.in \
303	missing/asprintf.c \
304	missing/getopt.c \
305	missing/getopt.h \
306	missing/strlcat.c \
307	missing/strlcpy.c \
308	missing/strtok_r.c \
309	missing/win_asprintf.c \
310	mkdep \
311	msdos/bin2c.c \
312	msdos/makefile \
313	msdos/makefile.dj \
314	msdos/makefile.wc \
315	msdos/pkt_rx0.asm \
316	msdos/pkt_rx1.s \
317	msdos/pktdrvr.c \
318	msdos/pktdrvr.h \
319	msdos/readme.dos \
320	nomkdep \
321	org.tcpdump.chmod_bpf.plist \
322	pcap-airpcap.c \
323	pcap-airpcap.h \
324	pcap-bpf.c \
325	pcap-bt-linux.c \
326	pcap-bt-linux.h \
327	pcap-bt-monitor-linux.c \
328	pcap-bt-monitor-linux.h \
329	pcap-config.in \
330	pcap-dag.c \
331	pcap-dag.h \
332	pcap-dbus.c \
333	pcap-dbus.h \
334	pcap-dll.rc \
335	pcap-dlpi.c \
336	pcap-dos.c \
337	pcap-dos.h \
338	pcap-dpdk.c \
339	pcap-dpdk.h \
340	pcap-enet.c \
341	pcap-haiku.c \
342	pcap-int.h \
343	pcap-libdlpi.c \
344	pcap-linux.c \
345	pcap-namedb.h \
346	pcap-new.c \
347	pcap-netfilter-linux.c \
348	pcap-netfilter-linux.h \
349	pcap-netmap.c \
350	pcap-netmap.h \
351	pcap-nit.c \
352	pcap-npf.c \
353	pcap-null.c \
354	pcap-pf.c \
355	pcap-rdmasniff.c \
356	pcap-rdmasniff.h \
357	pcap-rpcap.c \
358	pcap-septel.c \
359	pcap-septel.h \
360	pcap-sita.h \
361	pcap-sita.c \
362	pcap-sita.html \
363	pcap-snf.c \
364	pcap-snf.h \
365	pcap-snit.c \
366	pcap-snoop.c \
367	pcap-tc.c \
368	pcap-tc.h \
369	pcap-usb-linux.c \
370	pcap-usb-linux.h \
371	rpcap-protocol.c \
372	rpcapd/CMakeLists.txt \
373	rpcapd/Makefile.in \
374	rpcapd/config_params.h \
375	rpcapd/daemon.h \
376	rpcapd/daemon.c \
377	rpcapd/fileconf.c \
378	rpcapd/fileconf.h \
379	rpcapd/log.h \
380	rpcapd/log.c \
381	rpcapd/org.tcpdump.rpcapd.plist \
382	rpcapd/rpcapd.c \
383	rpcapd/rpcapd.h \
384	rpcapd/rpcapd.inetd.conf \
385	rpcapd/rpcapd.manadmin.in \
386	rpcapd/rpcapd-config.manfile.in \
387	rpcapd/rpcapd.rc \
388	rpcapd/rpcapd.socket \
389	rpcapd/rpcapd.xinetd.conf \
390	rpcapd/rpcapd@.service \
391	rpcapd/win32-svc.c \
392	rpcapd/win32-svc.h \
393	sockutils.c \
394	sockutils.h \
395	sslutils.c \
396	sslutils.h \
397	scanner.l \
398	testprogs/CMakeLists.txt \
399	testprogs/Makefile.in \
400	testprogs/can_set_rfmon_test.c \
401	testprogs/capturetest.c \
402	testprogs/filtertest.c \
403	testprogs/findalldevstest.c \
404	testprogs/findalldevstest-perf.c \
405	testprogs/fuzz/CMakeLists.txt \
406	testprogs/fuzz/fuzz_both.c \
407	testprogs/fuzz/fuzz_both.options \
408	testprogs/fuzz/fuzz_filter.c \
409	testprogs/fuzz/fuzz_filter.options \
410	testprogs/fuzz/fuzz_pcap.c \
411	testprogs/fuzz/fuzz_pcap.options \
412	testprogs/fuzz/onefile.c \
413	testprogs/nonblocktest.c \
414	testprogs/opentest.c \
415	testprogs/reactivatetest.c \
416	testprogs/selpolltest.c \
417	testprogs/threadsignaltest.c \
418	testprogs/unix.h \
419	testprogs/valgrindtest.c \
420	testprogs/visopts.py \
421	testprogs/writecaptest.c
422
423TEST_DIST = `git -C "$$DIR" ls-files tests | grep -v 'tests/\..*'`
424
425RELEASE_FILES = $(COMMON_C_SRC) $(HDR) $(MAN1) $(MAN3PCAP_EXPAND) \
426	$(MAN3PCAP_NOEXPAND) $(MANFILE) $(MANMISC) $(EXTRA_DIST) \
427	$(TEST_DIST)
428
429all: libpcap.a shared $(BUILD_RPCAPD) libpcap.pc pcap-config
430
431libpcap.a: $(OBJ)
432	@rm -f $@
433	$(AR) rc $@ $(OBJ) $(ADDLARCHIVEOBJS)
434	$(RANLIB) $@
435
436shared: libpcap.$(DYEXT)
437
438libpcap.so: $(OBJ)
439	@rm -f $@
440	VER=`cat $(srcdir)/VERSION`; \
441	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
442	@V_SHLIB_CMD@ $(LDFLAGS) @V_SHLIB_OPT@ @V_SONAME_OPT@$@.$$MAJOR_VER \
443	    -o $@.$$VER $(OBJ) $(ADDLOBJS) $(LIBS)
444
445#
446# The following rule succeeds, but the result is untested.
447#
448# In macOS, the libpcap dylib has the name "libpcap.A.dylib", with its
449# full path as the install_name, and with the compatibility and current
450# version both set to 1.  The compatibility version is set to 1 so that
451# programs built with a newer version of the library will run against
452# older versions if they don't use APIs available in the newer version
453# but not in the older version.
454#
455# We also use "A" as the major version, and 1 as the compatibility version,
456# but set the current version to the value in VERSION, with any non-numeric
457# stuff stripped off (the compatibility and current version must be of the
458# form X[.Y[.Z]], with Y and Z possibly absent, and with all components
459# numeric).
460#
461libpcap.dylib: $(OBJ)
462	rm -f libpcap*.dylib
463	VER=`cat $(srcdir)/VERSION`; \
464	MAJOR_VER=A; \
465	COMPAT_VER=1; \
466	CURRENT_VER=`sed 's/[^0-9.].*$$//' $(srcdir)/VERSION`; \
467	$(CC) -dynamiclib -undefined error $(LDFLAGS) @V_LIB_LDFLAGS_FAT@ \
468	    -o libpcap.$$VER.dylib $(OBJ) $(ADDLOBJS) $(LIBS) \
469	    -install_name $(libdir)/libpcap.$$MAJOR_VER.dylib \
470	    -compatibility_version $$COMPAT_VER \
471	    -current_version $$CURRENT_VER
472
473#
474# The HP-UX linker manual says that the convention for a versioned library
475# is libXXX.{number}, not libXXX.sl.{number}.  That appears to be the case
476# on at least one HP-UX 11.00 system; libXXX.sl is a symlink to
477# libXXX.{number}.
478#
479# The manual also says "library-level versioning" (think "sonames") was
480# added in HP-UX 10.0.
481#
482# XXX - this assumes we're using the HP linker, rather than the GNU
483# linker, even with GCC.
484#
485libpcap.sl: $(OBJ)
486	@MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
487	rm -f libpcap.$$MAJOR_VER
488	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
489	ld -b $(LDFLAGS) -o libpcap.$$MAJOR_VER +h libpcap.$$MAJOR_VER \
490	    $(OBJ) $(ADDLOBJS) $(LIBS)
491
492#
493# AIX is different from everybody else.  A shared library is an archive
494# library with one or more shared-object components.  We still build a
495# normal static archive library on AIX, for the benefit of the traditional
496# scheme of building libpcap and tcpdump in subdirectories of the
497# same directory, with tcpdump statically linked with the libpcap
498# in question, but we also build a shared library as "libpcap.shareda"
499# and install *it*, rather than the static library, as "libpcap.a".
500#
501libpcap.shareda: $(OBJ)
502	@rm -f $@ shr.o
503	$(CC) $(LDFLAGS) @V_SHLIB_OPT@ -o shr.o $(OBJ) $(ADDLOBJS) $(LIBS)
504	$(AR) rc $@ shr.o
505
506#
507# For platforms that don't support shared libraries (or on which we
508# don't support shared libraries).
509#
510libpcap.none:
511
512scanner.c: $(srcdir)/scanner.l
513	$(LEX) -P pcap_ --header-file=scanner.h --nounput -o scanner.c $<
514scanner.h: scanner.c
515## Recover from the removal of $@
516	@if test -f $@; then :; else \
517		rm -f scanner.c; \
518		$(MAKE) $(MAKEFLAGS) scanner.c; \
519	fi
520
521scanner.o: scanner.c grammar.h
522	$(CC) $(FULL_CFLAGS) -c scanner.c
523
524#
525# Generate the grammar.y file.
526#
527# Some Makes, e.g. AIX Make and Solaris Make, can't handle "--file=$@.tmp:$<";
528# for example, the Solaris 9 make man page says
529#
530#	Because make assigns $< and $* as it would for implicit rules
531#	(according to the suffixes list and the directory contents),
532#	they may be unreliable when used within explicit target entries.
533#
534# and this is an explicit target entry.
535#
536# Therefore, instead of using $<, we explicitly put in $(srcdir)/grammar.y.in.
537#
538grammar.y: $(srcdir)/grammar.y.in ./config.status
539	@rm -f $@ $@.tmp
540	./config.status --file=$@.tmp:$(srcdir)/grammar.y.in
541	mv $@.tmp $@
542
543grammar.c: grammar.y
544	$(BISON_BYACC) -p pcap_ -o grammar.c -d $<
545grammar.h: grammar.c
546## Recover from the removal of $@
547	@if test -f $@; then :; else \
548		rm -f grammar.c; \
549		$(MAKE) $(MAKEFLAGS) grammar.c; \
550	fi
551
552grammar.o: grammar.c scanner.h
553	$(CC) $(FULL_CFLAGS) -c grammar.c
554
555gencode.o: $(srcdir)/gencode.c grammar.h scanner.h
556	$(CC) $(FULL_CFLAGS) -c $(srcdir)/gencode.c
557
558asprintf.o: $(srcdir)/missing/asprintf.c
559	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/asprintf.c
560
561snprintf.o: $(srcdir)/missing/snprintf.c
562	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/snprintf.c
563
564strlcat.o: $(srcdir)/missing/strlcat.c
565	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcat.c
566
567strlcpy.o: $(srcdir)/missing/strlcpy.c
568	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strlcpy.c
569
570strtok_r.o: $(srcdir)/missing/strtok_r.c
571	$(CC) $(FULL_CFLAGS) -o $@ -c $(srcdir)/missing/strtok_r.c
572
573#
574# Generate the libpcap.pc file.
575#
576# Some Makes, e.g. AIX Make and Solaris Make, can't handle "--file=$@.tmp:$<";
577# for example, the Solaris 9 make man page says
578#
579#	Because make assigns $< and $* as it would for implicit rules
580#	(according to the suffixes list and the directory contents),
581#	they may be unreliable when used within explicit target entries.
582#
583# and this is an explicit target entry.
584#
585# Therefore, instead of using $<, we explicitly put in $(srcdir)/libpcap.pc.in.
586#
587libpcap.pc: $(srcdir)/libpcap.pc.in ./config.status
588	@rm -f $@ $@.tmp
589	./config.status --file=$@.tmp:$(srcdir)/libpcap.pc.in
590	mv $@.tmp $@
591
592#
593# Generate the pcap-config script.  See above.
594#
595pcap-config: $(srcdir)/pcap-config.in ./config.status
596	@rm -f $@ $@.tmp
597	./config.status --file=$@.tmp:$(srcdir)/pcap-config.in
598	mv $@.tmp $@
599	chmod a+x $@
600
601#
602# Remote pcap daemon.
603#
604build-rpcapd: libpcap.a
605	(cd rpcapd; $(MAKE))
606
607#
608# Test programs - not built by default, and not installed.
609#
610testprogs: FORCE libpcap.a
611	(cd testprogs; $(MAKE) CFLAGS="$(CFLAGS)")
612
613FORCE:
614
615install: install-shared install-archive libpcap.pc pcap-config @INSTALL_RPCAPD@
616	[ -d $(DESTDIR)$(libdir) ] || \
617	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
618	[ -d $(DESTDIR)$(includedir) ] || \
619	    (mkdir -p $(DESTDIR)$(includedir); chmod 755 $(DESTDIR)$(includedir))
620	[ -d $(DESTDIR)$(includedir)/pcap ] || \
621	    (mkdir -p $(DESTDIR)$(includedir)/pcap; chmod 755 $(DESTDIR)$(includedir)/pcap)
622	[ -d $(DESTDIR)$(mandir)/man1 ] || \
623	    (mkdir -p $(DESTDIR)$(mandir)/man1; chmod 755 $(DESTDIR)$(mandir)/man1)
624	[ -d $(DESTDIR)$(mandir)/man3 ] || \
625	    (mkdir -p $(DESTDIR)$(mandir)/man3; chmod 755 $(DESTDIR)$(mandir)/man3)
626	[ -d $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@ ] || \
627	    (mkdir -p $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@; chmod 755 $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@)
628	[ -d $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@ ] || \
629	    (mkdir -p $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@; chmod 755 $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@)
630	for i in $(PUBHDR); do \
631		$(INSTALL_DATA) $(srcdir)/$$i \
632		    $(DESTDIR)$(includedir)/$$i; done
633	[ -d $(DESTDIR)$(bindir) ] || \
634	    (mkdir -p $(DESTDIR)$(bindir); chmod 755 $(DESTDIR)$(bindir))
635	$(INSTALL_PROGRAM) pcap-config $(DESTDIR)$(bindir)/pcap-config
636	[ -d $(DESTDIR)$(libdir)/pkgconfig ] || \
637	    (mkdir -p $(DESTDIR)$(libdir)/pkgconfig; chmod 755 $(DESTDIR)$(libdir)/pkgconfig)
638	$(INSTALL_DATA) libpcap.pc $(DESTDIR)$(libdir)/pkgconfig/libpcap.pc
639	for i in $(MAN1); do \
640		$(INSTALL_DATA) $(srcdir)/$$i \
641		    $(DESTDIR)$(mandir)/man1/$$i; done
642	for i in $(MAN3PCAP_NOEXPAND); do \
643		$(INSTALL_DATA) $(srcdir)/$$i \
644		    $(DESTDIR)$(mandir)/man3/$$i; done
645	for i in $(MAN3PCAP_EXPAND:.in=); do \
646		$(INSTALL_DATA) $$i \
647		    $(DESTDIR)$(mandir)/man3/$$i; done
648	(cd $(DESTDIR)$(mandir)/man3 && \
649	rm -f pcap_datalink_val_to_description.3pcap && \
650	$(LN_S) pcap_datalink_val_to_name.3pcap \
651		 pcap_datalink_val_to_description.3pcap && \
652	rm -f pcap_datalink_val_to_description_or_dlt.3pcap && \
653	$(LN_S) pcap_datalink_val_to_name.3pcap \
654		 pcap_datalink_val_to_description_or_dlt.3pcap && \
655	rm -f pcap_dump_fopen.3pcap && \
656	$(LN_S) pcap_dump_open.3pcap pcap_dump_fopen.3pcap && \
657	rm -f pcap_freealldevs.3pcap && \
658	$(LN_S) pcap_findalldevs.3pcap pcap_freealldevs.3pcap && \
659	rm -f pcap_perror.3pcap && \
660	$(LN_S) pcap_geterr.3pcap pcap_perror.3pcap && \
661	rm -f pcap_sendpacket.3pcap && \
662	$(LN_S) pcap_inject.3pcap pcap_sendpacket.3pcap && \
663	rm -f pcap_free_datalinks.3pcap && \
664	$(LN_S) pcap_list_datalinks.3pcap pcap_free_datalinks.3pcap && \
665	rm -f pcap_free_tstamp_types.3pcap && \
666	$(LN_S) pcap_list_tstamp_types.3pcap pcap_free_tstamp_types.3pcap && \
667	rm -f pcap_dispatch.3pcap && \
668	$(LN_S) pcap_loop.3pcap pcap_dispatch.3pcap && \
669	rm -f pcap_minor_version.3pcap && \
670	$(LN_S) pcap_major_version.3pcap pcap_minor_version.3pcap && \
671	rm -f pcap_next.3pcap && \
672	$(LN_S) pcap_next_ex.3pcap pcap_next.3pcap && \
673	rm -f pcap_open_dead_with_tstamp_precision.3pcap && \
674	$(LN_S) pcap_open_dead.3pcap \
675		 pcap_open_dead_with_tstamp_precision.3pcap && \
676	rm -f pcap_open_offline_with_tstamp_precision.3pcap && \
677	$(LN_S) pcap_open_offline.3pcap pcap_open_offline_with_tstamp_precision.3pcap && \
678	rm -f pcap_fopen_offline.3pcap && \
679	$(LN_S) pcap_open_offline.3pcap pcap_fopen_offline.3pcap && \
680	rm -f pcap_fopen_offline_with_tstamp_precision.3pcap && \
681	$(LN_S) pcap_open_offline.3pcap pcap_fopen_offline_with_tstamp_precision.3pcap && \
682	rm -f pcap_tstamp_type_val_to_description.3pcap && \
683	$(LN_S) pcap_tstamp_type_val_to_name.3pcap pcap_tstamp_type_val_to_description.3pcap && \
684	rm -f pcap_getnonblock.3pcap && \
685	$(LN_S) pcap_setnonblock.3pcap pcap_getnonblock.3pcap)
686	for i in $(MANFILE); do \
687		$(INSTALL_DATA) `echo $$i | sed 's/.manfile.in/.manfile/'` \
688		    $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@/`echo $$i | sed 's/.manfile.in/.@MAN_FILE_FORMATS@/'`; done
689	for i in $(MANMISC); do \
690		$(INSTALL_DATA) `echo $$i | sed 's/.manmisc.in/.manmisc/'` \
691		    $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@/`echo $$i | sed 's/.manmisc.in/.@MAN_MISC_INFO@/'`; done
692
693install-shared: install-shared-$(DYEXT)
694install-shared-so: libpcap.so
695	[ -d $(DESTDIR)$(libdir) ] || \
696	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
697	VER=`cat $(srcdir)/VERSION`; \
698	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
699	$(INSTALL_PROGRAM) libpcap.so.$$VER $(DESTDIR)$(libdir)/libpcap.so.$$VER; \
700	ln -sf libpcap.so.$$VER $(DESTDIR)$(libdir)/libpcap.so.$$MAJOR_VER; \
701	ln -sf libpcap.so.$$MAJOR_VER $(DESTDIR)$(libdir)/libpcap.so
702install-shared-dylib: libpcap.dylib
703	[ -d $(DESTDIR)$(libdir) ] || \
704	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
705	VER=`cat $(srcdir)/VERSION`; \
706	MAJOR_VER=A; \
707	$(INSTALL_PROGRAM) libpcap.$$VER.dylib $(DESTDIR)$(libdir)/libpcap.$$VER.dylib; \
708	ln -sf libpcap.$$VER.dylib $(DESTDIR)$(libdir)/libpcap.$$MAJOR_VER.dylib; \
709	ln -sf libpcap.$$MAJOR_VER.dylib $(DESTDIR)$(libdir)/libpcap.dylib
710install-shared-sl: libpcap.sl
711	[ -d $(DESTDIR)$(libdir) ] || \
712	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
713	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
714	$(INSTALL_PROGRAM) libpcap.$$MAJOR_VER $(DESTDIR)$(libdir)
715	ln -sf libpcap.$$MAJOR_VER $(DESTDIR)$(libdir)/libpcap.sl
716#
717# AIX shared libraries are weird.  They're archive libraries
718# with one or more shared object components.
719#
720install-shared-shareda: libpcap.shareda
721	[ -d $(DESTDIR)$(libdir) ] || \
722	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
723	$(INSTALL_PROGRAM) libpcap.shareda $(DESTDIR)$(libdir)/libpcap.a
724install-shared-none:
725
726install-archive: install-archive-$(DYEXT)
727#
728# Most platforms have separate suffixes for shared and
729# archive libraries, so we install both.
730#
731install-archive-so install-archive-dylib install-archive-sl install-archive-none: libpcap.a
732	[ -d $(DESTDIR)$(libdir) ] || \
733	    (mkdir -p $(DESTDIR)$(libdir); chmod 755 $(DESTDIR)$(libdir))
734	$(INSTALL_DATA) libpcap.a $(DESTDIR)$(libdir)/libpcap.a
735	$(RANLIB) $(DESTDIR)$(libdir)/libpcap.a
736#
737# AIX, however, doesn't, so we don't install the archive
738# library on AIX.
739#
740install-archive-shareda:
741
742install-rpcapd:
743	(cd rpcapd; $(MAKE) DESTDIR=$(DESTDIR) install)
744
745uninstall: uninstall-shared uninstall-rpcapd
746	rm -f $(DESTDIR)$(libdir)/libpcap.a
747	for i in $(PUBHDR); do \
748		rm -f $(DESTDIR)$(includedir)/$$i; done
749	-rmdir $(DESTDIR)$(includedir)/pcap
750	rm -f $(DESTDIR)/$(libdir)/pkgconfig/libpcap.pc
751	rm -f $(DESTDIR)/$(bindir)/pcap-config
752	for i in $(MAN1); do \
753		rm -f $(DESTDIR)$(mandir)/man1/$$i; done
754	for i in $(MAN3PCAP); do \
755		rm -f $(DESTDIR)$(mandir)/man3/$$i; done
756	rm -f $(DESTDIR)$(mandir)/man3/pcap_datalink_val_to_description.3pcap
757	rm -f $(DESTDIR)$(mandir)/man3/pcap_datalink_val_to_description_or_dlt.3pcap
758	rm -f $(DESTDIR)$(mandir)/man3/pcap_dump_fopen.3pcap
759	rm -f $(DESTDIR)$(mandir)/man3/pcap_freealldevs.3pcap
760	rm -f $(DESTDIR)$(mandir)/man3/pcap_perror.3pcap
761	rm -f $(DESTDIR)$(mandir)/man3/pcap_sendpacket.3pcap
762	rm -f $(DESTDIR)$(mandir)/man3/pcap_free_datalinks.3pcap
763	rm -f $(DESTDIR)$(mandir)/man3/pcap_free_tstamp_types.3pcap
764	rm -f $(DESTDIR)$(mandir)/man3/pcap_dispatch.3pcap
765	rm -f $(DESTDIR)$(mandir)/man3/pcap_minor_version.3pcap
766	rm -f $(DESTDIR)$(mandir)/man3/pcap_next.3pcap
767	rm -f $(DESTDIR)$(mandir)/man3/pcap_open_dead_with_tstamp_precision.3pcap
768	rm -f $(DESTDIR)$(mandir)/man3/pcap_open_offline_with_tstamp_precision.3pcap
769	rm -f $(DESTDIR)$(mandir)/man3/pcap_fopen_offline.3pcap
770	rm -f $(DESTDIR)$(mandir)/man3/pcap_fopen_offline_with_tstamp_precision.3pcap
771	rm -f $(DESTDIR)$(mandir)/man3/pcap_getnonblock.3pcap
772	rm -f $(DESTDIR)$(mandir)/man3/pcap_tstamp_type_val_to_description.3pcap
773	for i in $(MANFILE); do \
774		rm -f $(DESTDIR)$(mandir)/man@MAN_FILE_FORMATS@/`echo $$i | sed 's/.manfile.in/.@MAN_FILE_FORMATS@/'`; done
775	for i in $(MANMISC); do \
776		rm -f $(DESTDIR)$(mandir)/man@MAN_MISC_INFO@/`echo $$i | sed 's/.manmisc.in/.@MAN_MISC_INFO@/'`; done
777
778uninstall-shared: uninstall-shared-$(DYEXT)
779uninstall-shared-so:
780	VER=`cat $(srcdir)/VERSION`; \
781	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
782	rm -f $(DESTDIR)$(libdir)/libpcap.so.$$VER; \
783	rm -f $(DESTDIR)$(libdir)/libpcap.so.$$MAJOR_VER; \
784	rm -f $(DESTDIR)$(libdir)/libpcap.so
785uninstall-shared-dylib:
786	VER=`cat $(srcdir)/VERSION`; \
787	MAJOR_VER=A; \
788	rm -f $(DESTDIR)$(libdir)/libpcap.$$VER.dylib; \
789	rm -f $(DESTDIR)$(libdir)/libpcap.$$MAJOR_VER.dylib; \
790	rm -f $(DESTDIR)$(libdir)/libpcap.dylib
791uninstall-shared-sl:
792	MAJOR_VER=`sed 's/\([0-9][0-9]*\)\..*/\1/' $(srcdir)/VERSION`; \
793	rm -f $(DESTDIR)$(libdir)/libpcap.$$MAJOR_VER; \
794	rm -f $(DESTDIR)$(libdir)/libpcap.sl
795uninstall-shared-shareda:
796	rm -f $(DESTDIR)$(libdir)/libpcap.a
797uninstall-shared-none:
798
799uninstall-rpcapd:
800	(cd rpcapd; $(MAKE) DESTDIR=$(DESTDIR) uninstall)
801
802clean:
803	rm -f $(CLEANFILES) config.h.in~ configure~ configure.ac~
804	(cd rpcapd; $(MAKE) clean)
805	(cd testprogs; $(MAKE) clean)
806
807distclean: clean
808	rm -f Makefile grammar.y config.cache config.log config.status \
809	    config.h os-proto.h libpcap.pc pcap-config stamp-h stamp-h.in
810	rm -f $(MAN3PCAP_EXPAND:.in=) $(MANFILE:.in=) $(MANMISC:.in=)
811	rm -rf autom4te.cache
812	(cd rpcapd; $(MAKE) distclean)
813	(cd testprogs; $(MAKE) distclean)
814
815extags: $(TAGFILES)
816	ctags $(TAGFILES)
817
818tags: $(TAGFILES)
819	ctags -wtd $(TAGFILES)
820
821#
822# Use git archive piped to tar to construct a subdirectory whose name
823# is libpcap-{release}, containing all the checked-in source files,
824# and then run autoreconf in that directory to generate the configure
825# script and other files from that source. Then remove autom4te.cache,
826# construct the release tarball from that subdirectory, and remove
827# the subdirectory.
828#
829# The --format=tar is to force git archive to write a non-compressed
830# archive, in case the platform's tar command doesn't have built-in
831# decompression.
832#
833# The ^{tree} is there to force git archive not to write out the
834# "helpful" global extended pax header with a commit ID, as not all
835# versions of tar can handle that (Solaris tar can't, for example).
836# (It turns HEAD, or a tag, both of which are apparently "tree-ish"es,
837# into a tree; apparently, unlike HEAD, or a tag, which have a commit
838# ID associated with them, the tree associated with them doesn't have
839# a commit ID, so no commit ID is available to write, and thus
840# git archive doesn't write one.)
841#
842releasetar:
843	@TAG=$(PROG)-`cat VERSION` && \
844	if [ ! -d .git ]; then echo 'Not in a git clone, stop.'; exit 1; fi && \
845	TMPTESTFILE=`mktemp -t tmptestfile_XXXXXXXX` && \
846	rm -f "$$TMPTESTFILE" && \
847	AUTORECONF_DIR=`dirname "$$TMPTESTFILE"`/"$(PROG)"_build_autoreconf_$$$$ && \
848	DIR=`pwd` && \
849	rm -rf "$$AUTORECONF_DIR" && \
850	mkdir "$$AUTORECONF_DIR" && \
851	cd "$$AUTORECONF_DIR" && \
852	if git -C "$$DIR" show-ref --tags --quiet --verify -- "refs/tags/$$TAG"; then \
853	    (git -C "$$DIR" archive --format=tar --prefix="$$TAG"/ "$$TAG^{tree}" $(RELEASE_FILES) | \
854	     tar xf -) && \
855	    echo "Archive build from tag $$TAG."; \
856	else \
857	    (git -C "$$DIR" archive --format=tar --prefix="$$TAG"/ "HEAD^{tree}" $(RELEASE_FILES) | \
858	     tar xf -) && \
859	    echo "No $$TAG tag. Archive build from HEAD."; \
860	fi && \
861	(cd "$$TAG" && "$${AUTORECONF:-autoreconf}" && rm -rf autom4te.cache) && \
862	tar cf "$$DIR/$$TAG".tar "$$TAG" && \
863	rm -f "$$DIR/$$TAG".tar.gz && \
864	gzip --best "$$DIR/$$TAG".tar && \
865	cd "$$DIR" && \
866	rm -rf "$$AUTORECONF_DIR"
867
868releasecheck: releasetar
869	@TAG=$(PROG)-`cat VERSION` && \
870	INSTALL_DIR=/tmp/install_"$$TAG"_$$$$ && \
871	DIR=`pwd` && \
872	cd /tmp && \
873	rm -rf "$$TAG" && \
874	rm -rf "$$INSTALL_DIR" && \
875	tar xf "$$DIR"/"$$TAG".tar.gz && \
876	cd "$$TAG" && \
877	echo "[$@] $$ touch .devel" && \
878	touch .devel && \
879	echo "[$@] $$ ./configure --enable-remote --quiet --prefix=$$INSTALL_DIR" && \
880	./configure --enable-remote --quiet --prefix="$$INSTALL_DIR" && \
881	echo '[$@] $$ $(MAKE) -s all testprogs' && \
882	$(MAKE) -s all testprogs && \
883	echo '[$@] $$ $(MAKE) -s install' && \
884	$(MAKE) -s install && \
885	cd .. && \
886	rm -rf "$$TAG" && \
887	rm -rf "$$INSTALL_DIR" && \
888	tar xf "$$DIR"/"$$TAG".tar.gz && \
889	cd "$$TAG" && \
890	echo "[$@] $$ touch .devel" && \
891	touch .devel && \
892	mkdir build && \
893	cd build && \
894	echo '[$@] $$ cmake -DENABLE_REMOTE=yes [...] ..' && \
895	cmake -DENABLE_REMOTE=yes \
896	    -DCMAKE_INSTALL_PREFIX="$$INSTALL_DIR" \
897	    -DCMAKE_MESSAGE_LOG_LEVEL=NOTICE \
898	    -DCMAKE_RULE_MESSAGES=OFF \
899	    -DCMAKE_INSTALL_MESSAGE=NEVER \
900	    .. && \
901	echo '[$@] $$ $(MAKE) -s all testprogs' && \
902	$(MAKE) -s all testprogs && \
903	echo '[$@] $$ $(MAKE) -s install' && \
904	$(MAKE) -s install && \
905	cd ../.. && \
906	rm -rf "$$TAG" && \
907	rm -rf "$$INSTALL_DIR" && \
908	echo '[$@] Done.'
909
910whitespacecheck:
911	@# trailing space(s)?
912	@if git grep -I -n ' $$' $$(git ls-files|grep -v '^tests/'); then \
913	    echo 'Error: Trailing space(s).'; \
914	    exit 1; \
915	fi
916	@# trailing tab(s)?
917	@if git grep -I -n '	$$' $$(git ls-files|grep -v '^tests/'); then \
918	    echo 'Error: Trailing tabs(s).'; \
919	    exit 1; \
920	fi
921	@# space(s) before tab(s)?
922	@if git grep -I -n '[ ][	]' $$(git ls-files|grep -v '^tests/'); then \
923	    echo 'Error: space(s) before tab(s).'; \
924	    exit 1; \
925	fi
926
927depend:	$(GENERATED_C_SRC) $(GENHDR)
928	$(MKDEP) -c $(CC) -m "$(DEPENDENCY_CFLAG)" -s "$(srcdir)" $(CFLAGS) $(DEFS) $(INCLS) $(SRC)
929	(cd rpcapd; $(MAKE) depend)
930	(cd testprogs; $(MAKE) depend)
931
932shellcheck:
933	shellcheck -f gcc -e SC2006 autogen.sh build.sh build_matrix.sh build_common.sh mkdep .ci-coverity-scan-build.sh
934