Debian Codegraph @

m4/ax_check_pcap.m4

raw
1 # SYNOPSIS
2 #
3 # AX_CHECK_PCAP([action-if-found[, action-if-not-found]]
4 #
5 # DESCRIPTION
6 #
7 # Look for libpcap in a number of default locations, or in a provided location
8 # (via --with-pcap=). Sets
9 # PCAP_CFLAGS
10 # PCAP_LDFLAGS
11 # PCAP_LIBS
12 #
13 # and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
14 #
15 # LICENSE
16 #
17 # Copyright (c) 2021 Eivind Naess <[email protected]>
18 #
19 # Copying and distribution of this file, with or without modification, are
20 # permitted in any medium without royalty provided the copyright notice
21 # and this notice are preserved. This file is offered as-is, without any
22 # warranty.
23
24 #serial 1
25
26 AC_DEFUN([AX_CHECK_PCAP], [
27 AC_ARG_WITH([pcap],
28 [AS_HELP_STRING([--with-pcap=DIR],
29 [With libpcap support, see https://www.tcpdump.org])],
30 [
31 case "$withval" in
32 "" | y | ye | yes)
33 pcapdirs="/usr/local /usr/lib /usr"
34 ;;
35 n | no)
36 with_pcap="no"
37 ;;
38 *)
39 pcapdirs="$withval"
40 ;;
41 esac
42 ])
43
44 if [ test "x${with_pcap}" != "xno" ] ; then
45 PCAP_LIBS="-lpcap"
46 for pcapdir in $pcapdirs; do
47 AC_MSG_CHECKING([for pcap.h in $pcapdir])
48 if test -f "$pcapdir/include/pcap.h"; then
49 PCAP_CFLAGS="-I$pcapdir/include"
50 PCAP_LDFLAGS="-L$pcapdir/lib"
51 AC_MSG_RESULT([yes])
52 break
53 else
54 AC_MSG_RESULT([no])
55 fi
56 done
57
58 # try the preprocessor and linker with our new flags,
59 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
60
61 AC_MSG_CHECKING([if compiling and linking against libpcap works])
62
63 save_LIBS="$LIBS"
64 save_LDFLAGS="$LDFLAGS"
65 save_CPPFLAGS="$CPPFLAGS"
66 LDFLAGS="$PCAP_LDFLAGS $LDFLAGS"
67 LIBS="$PCAP_LIBS $LIBS"
68 CPPFLAGS="$PCAP_CFLAGS $CPPFLAGS"
69 AC_LINK_IFELSE(
70 [AC_LANG_PROGRAM(
71 [@%:@include <pcap.h>],
72 [pcap_create(0,0);])],
73 [
74 AC_MSG_RESULT([yes])
75 with_pcap=yes
76 $1
77 ], [
78 AC_MSG_RESULT([no])
79 with_pcap="no"
80 $2
81 ])
82 CPPFLAGS="$save_CPPFLAGS"
83 LDFLAGS="$save_LDFLAGS"
84 LIBS="$save_LIBS"
85
86 AC_SUBST([PCAP_CFLAGS])
87 AC_SUBST([PCAP_LIBS])
88 AC_SUBST([PCAP_LDFLAGS])
89 fi
90
91 AM_CONDITIONAL(WITH_PCAP, test "x${with_pcap}" != "xno")
92 ])
93