1 dnl Copyright (c) 1995, 1996, 1997, 1998
2 dnl The Regents of the University of California. All rights reserved.
4 dnl Redistribution and use in source and binary forms, with or without
5 dnl modification, are permitted provided that: (1) source code distributions
6 dnl retain the above copyright notice and this paragraph in its entirety, (2)
7 dnl distributions including binary code include the above copyright notice and
8 dnl this paragraph in its entirety in the documentation or other materials
9 dnl provided with the distribution, and (3) all advertising materials mentioning
10 dnl features or use of this software display the following acknowledgement:
11 dnl ``This product includes software developed by the University of California,
12 dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 dnl the University nor the names of its contributors may be used to endorse
14 dnl or promote products derived from this software without specific prior
15 dnl written permission.
16 dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 dnl LBL autoconf macros
24 dnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
26 dnl It appears that newer versions of autoconf (2.64 and later) will,
27 dnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the
28 dnl beginning of the macro, even if the macro itself calls AC_PROG_CC.
29 dnl See the "Prerequisite Macros" and "Expanded Before Required" sections
30 dnl in the Autoconf documentation.
32 dnl This causes a steaming heap of fail in our case, as we were, in
33 dnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC,
34 dnl calling AC_PROG_CC, and then doing the tests we now do in
35 dnl AC_LBL_C_INIT. Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC,
36 dnl and AC_LBL_C_INIT at the top level.
38 AC_DEFUN(AC_LBL_C_INIT_BEFORE_CC,
40 AC_BEFORE([$0], [AC_LBL_C_INIT])
41 AC_BEFORE([$0], [AC_PROG_CC])
42 AC_BEFORE([$0], [AC_LBL_DEVEL])
43 AC_ARG_WITH(gcc, [ --without-gcc don't use gcc])
45 if test "${srcdir}" != "." ; then
48 if test "${CFLAGS+set}" = set; then
51 if test -z "$CC" -a "$with_gcc" = no ; then
58 dnl Determine which compiler we're using (cc or gcc)
59 dnl If using gcc, determine the version number
61 dnl require that it support ansi prototypes
62 dnl use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
63 dnl do that ourselves for gcc)
64 dnl add -g flags, as appropriate
65 dnl explicitly specify /usr/local/include
67 dnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
68 dnl that defines __GNUC__, which means clang, for example, counts as "gcc".
72 dnl AC_LBL_C_INIT(copt, incls)
82 AC_DEFUN(AC_LBL_C_INIT,
84 AC_BEFORE([$0], [AC_LBL_DEVEL])
85 if test "$GCC" = yes ; then
87 # -Werror forces warnings to be errors.
89 ac_lbl_cc_force_warning_errors=-Werror
91 $2="$$2 -I/usr/local/include"
92 LDFLAGS="$LDFLAGS -L/usr/local/lib"
98 # This is assumed either to be GCC or clang, both
99 # of which use -Werror to force warnings to be errors.
101 # XXX - they also both cause GCC to be set to yes,
102 # so we should never get here in the first place.
104 ac_lbl_cc_force_warning_errors=-Werror
109 # HP C, which is what we presume we're using, doesn't
110 # exit with a non-zero exit status if we hand it an
111 # invalid -W flag, can't be forced to do so even with
112 # +We, and doesn't handle GCC-style -W flags, so we
113 # don't want to try using GCC-style -W flags.
115 ac_lbl_cc_dont_try_gcc_dashW=yes
120 # Assumed to be Sun C, which requires -errwarn to force
121 # warnings to be treated as errors.
123 ac_lbl_cc_force_warning_errors=-errwarn
131 dnl Save the values of various variables that affect compilation and
132 dnl linking, and that we don't ourselves modify persistently; done
133 dnl before a test involving compiling or linking is done, so that we
134 dnl can restore those variables after the test is done.
136 AC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
138 save_CFLAGS="$CFLAGS"
140 save_LDFLAGS="$LDFLAGS"
144 dnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
146 AC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
148 CFLAGS="$save_CFLAGS"
150 LDFLAGS="$save_LDFLAGS"
154 dnl Check whether the compiler option specified as the second argument
155 dnl is supported by the compiler and, if so, add it to the macro
156 dnl specified as the first argument
158 AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
160 AC_MSG_CHECKING([whether the compiler supports the $2 option])
161 save_CFLAGS="$CFLAGS"
164 # XXX - yes, this depends on the way AC_LANG_WERROR works,
165 # but no mechanism is provided to turn AC_LANG_WERROR on
166 # *and then turn it back off*, so that we *only* do it when
167 # testing compiler options - 15 years after somebody asked
170 # https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
172 save_ac_c_werror_flag="$ac_c_werror_flag"
175 # We use AC_LANG_SOURCE() so that we can control the complete
176 # content of the program being compiled. We do not, for example,
177 # want the default "int main()" that AC_LANG_PROGRAM() generates,
178 # as it will generate a warning with -Wold-style-definition, meaning
179 # that we would treat it as not working, as the test will fail if
180 # *any* error output, including a warning due to the flag we're
181 # testing, is generated; see
183 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
184 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
186 # This may, as per those two messages, be fixed in autoconf 2.70,
187 # but we only require 2.69 or newer for now.
190 [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
193 CFLAGS="$save_CFLAGS"
198 CFLAGS="$save_CFLAGS"
200 ac_c_werror_flag="$save_ac_c_werror_flag"
204 dnl Check whether the compiler supports an option to generate
205 dnl Makefile-style dependency lines
207 dnl GCC uses -M for this. Non-GCC compilers that support this
208 dnl use a variety of flags, including but not limited to -M.
210 dnl We test whether the flag in question is supported, as older
211 dnl versions of compilers might not support it.
213 dnl We don't try all the possible flags, just in case some flag means
214 dnl "generate dependencies" on one compiler but means something else
215 dnl on another compiler.
217 dnl Most compilers that support this send the output to the standard
218 dnl output by default. IBM's XLC, however, supports -M but sends
219 dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
220 dnl to work around that, so we don't bother with XLC.
222 AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
224 AC_MSG_CHECKING([whether the compiler supports generating dependencies])
225 if test "$GCC" = yes ; then
227 # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
228 # though it's not); we assume that, in this case, the flag
231 ac_lbl_dependency_flag="-M"
234 # Not GCC or a compiler deemed to be GCC; what platform is
235 # this? (We're assuming that if the compiler isn't GCC
236 # it's the compiler from the vendor of the OS; that won't
237 # necessarily be true for x86 platforms, where it might be
238 # the Intel C compiler.)
246 ac_lbl_dependency_flag="-M"
253 ac_lbl_dependency_flag="-xM"
258 # HP's older C compilers don't support this.
259 # HP's newer C compilers support this with
260 # either +M or +Make; the older compilers
261 # interpret +M as something completely
262 # different, so we use +Make so we don't
263 # think it works with the older compilers.
265 ac_lbl_dependency_flag="+Make"
270 # Not one of the above; assume no support for
271 # generating dependencies.
273 ac_lbl_dependency_flag=""
279 # Is ac_lbl_dependency_flag defined and, if so, does the compiler
282 # Note: clang doesn't seem to exit with an error status when handed
283 # an unknown non-warning error, even if you pass it
284 # -Werror=unknown-warning-option. However, it always supports
285 # -M, so the fact that this test always succeeds with clang
288 if test ! -z "$ac_lbl_dependency_flag"; then
290 [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
291 if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
292 AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
293 DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
294 MKDEP='${top_srcdir}/mkdep'
298 # We can't run mkdep, so have "make depend" do
307 # We can't run mkdep, so have "make depend" do
312 AC_SUBST(DEPENDENCY_CFLAG)
318 dnl Look for libpcap in directories under ..; those are local versions.
319 dnl Look for an installed libpcap if there is no local version or if
320 dnl the user said not to look for a local version.
324 dnl AC_LBL_LIBPCAP(pcapdep, incls)
329 dnl $2 (incls appended)
332 AC_DEFUN(AC_LBL_LIBPCAP,
334 AC_REQUIRE([AC_PROG_EGREP])
335 AC_REQUIRE([AC_LBL_LIBRARY_NET])
337 AC_MSG_CHECKING([whether to look for a local libpcap])
338 AC_ARG_ENABLE(local-libpcap,
339 AS_HELP_STRING([--disable-local-libpcap],
340 [don't look for a local libpcap @<:@default=check for a local libpcap@:>@]),,
347 # Don't look for a local libpcap.
349 using_local_libpcap=no
355 # Look for a local pcap library.
357 AC_MSG_CHECKING(for local pcap library)
359 places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
360 $EGREP '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
361 places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
362 $EGREP '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
363 for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
364 basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//' | \
365 sed -e 's/-PRE-GIT$//' `
366 if test $lastdir = $basedir ; then
367 dnl skip alphas when an actual release is present
371 if test -r $dir/libpcap.a ; then
372 libpcap=$dir/libpcap.a
374 dnl continue and select the last one that exists
377 if test $libpcap = FAIL ; then
379 # We didn't find a local libpcap.
381 AC_MSG_RESULT(not found)
382 using_local_libpcap=no;
385 # We found a local libpcap.
387 AC_MSG_RESULT($libpcap)
388 using_local_libpcap=yes
393 if test $using_local_libpcap = no ; then
395 # We didn't find a local libpcap.
396 # First, try finding it with pkg-config.
398 PKG_CHECK_MODULE(LIBPCAP, libpcap,
401 # We found it; use the results as configuration information
404 $2="$LIBPCAP_CFLAGS $$2"
405 libpcap="$LIBPCAP_LIBS"
409 # We didn't find it; look for an installed pcap-config.
411 AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
412 if test -n "$PCAP_CONFIG" ; then
414 # Found - use it to get the include flags for
415 # libpcap and the flags to link with libpcap.
417 # If this is a vendor-supplied pcap-config, which
418 # we define as being "a pcap-config in /usr/bin
419 # or /usr/ccs/bin" (the latter is for Solaris and
420 # Sun/Oracle Studio), there are some issues. Work
423 if test \( "$PCAP_CONFIG" = "/usr/bin/pcap-config" \) -o \
424 \( "$PCAP_CONFIG" = "/usr/ccs/bin/pcap-config" \) ; then
426 # It's vendor-supplied.
432 # This is macOS or another Darwin-based OS.
434 # That means that /usr/bin/pcap-config it
435 # may provide -I/usr/local/include with --cflags
436 # and -L/usr/local/lib with --libs, rather than
437 # pointing to the OS-supplied library and
438 # Xcode-supplied headers. Remember that, so we
439 # ignore those values.
441 _broken_apple_pcap_config=yes
446 # macOS Sonoma's libpcap includes stub versions
447 # of the remote-capture APIs. They are exported
448 # as "weakly linked symbols".
450 # Xcode 15 offers only a macOS Sonoma SDK, which
451 # has a .tbd file for libpcap that claims it
452 # includes those APIs. (Newer versions of macOS
453 # don't provide the system shared libraries,
454 # they only provide the dyld shared cache
455 # containing those libraries, so the OS provides
456 # SDKs that include a .tbd file to use when
459 # This means that AC_CHECK_FUNCS() will think
460 # that the remote-capture APIs are present,
461 # including pcap_open() and
462 # pcap_findalldevs_ex().
464 # However, they are *not* present in macOS
465 # Ventura and earlier, which means that building
466 # on Ventura with Xcode 15 produces executables
467 # that fail to start because one of those APIs
468 # isn't found in the system libpcap.
470 # Protecting calls to those APIs with
471 # __builtin_available() does not appear to
472 # prevent this, for some unknown reason, and it
473 # doesn't even allow the program to compile with
474 # versions of Xcode prior to Xcode 15, as the
475 # pcap.h file doesn't specify minimum OS
476 # versions for those functions.
478 # Given all that, and given that the versions of
479 # the remote-capture APIs in Sonoma are stubs
480 # that always fail, there doesn't seem to be any
481 # point in checking for pcap_open() if we're
482 # linking against the Apple libpcap.
484 # However, if we're *not* linking against the
485 # Apple libpcap, we should check for it, so that
486 # we can use it if it's present.
488 # We know this is macOS and that we're using
489 # the system-provided pcap-config to find
490 # libpcap, so we know it'll be the system
491 # libpcap, and note that we should not search
492 # for remote-capture APIs.
494 _dont_check_for_remote_apis=yes
499 # This is Solaris 2 or later, i.e. SunOS 5.x.
501 # At least on Solaris 11; there's /usr/bin/pcap-config,
502 # which reports -L/usr/lib with --libs, causing
503 # the 32-bit libraries to be found, and there's
504 # /usr/bin/{64bitarch}/pcap-config, where {64bitarch}
505 # is a name for the 64-bit version of the instruction
506 # set, which reports -L /usr/lib/{64bitarch}, causing
507 # the 64-bit libraries to be found.
509 # So if we're building 64-bit targets, we replace
510 # PCAP_CONFIG with /usr/bin/{64bitarch}; we get
511 # {64bitarch} as the output of "isainfo -n".
513 # Are we building 32-bit or 64-bit? Get the
514 # size of void *, and check that.
516 AC_CHECK_SIZEOF([void *])
517 if test ac_cv_sizeof_void_p -eq 8 ; then
518 isainfo_output=`isainfo -n`
519 if test ! -z "$isainfo_output" ; then
521 # Success - change PCAP_CONFIG.
523 PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"`
530 # Please read section 11.6 "Shell Substitutions"
531 # in the autoconf manual before doing anything
532 # to this that involves quoting. Especially note
533 # the statement "There is just no portable way to use
534 # double-quoted strings inside double-quoted back-quoted
535 # expressions (pfew!)."
537 cflags=`"$PCAP_CONFIG" --cflags`
539 # Work around macOS (and probably other Darwin) brokenness,
540 # by not adding /usr/local/include if it's from the broken
543 if test "$_broken_apple_pcap_config" = "yes" ; then
545 # Strip -I/usr/local/include with sed.
547 cflags=`echo $cflags | sed 's;-I/usr/local/include;;'`
550 libpcap=`"$PCAP_CONFIG" --libs`
552 # Work around macOS (and probably other Darwin) brokenness,
553 # by not adding /usr/local/lib if it's from the broken
556 if test "$_broken_apple_pcap_config" = "yes" ; then
558 # Strip -L/usr/local/lib with sed.
560 libpcap=`echo $libpcap | sed 's;-L/usr/local/lib;;'`
564 # Not found; look for an installed pcap.
566 AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
567 if test $libpcap = FAIL ; then
568 AC_MSG_ERROR(see the INSTALL.md file for more info)
571 dnl Some versions of Red Hat Linux put "pcap.h" in
572 dnl "/usr/include/pcap"; had the LBL folks done so,
573 dnl that would have been a good idea, but for
574 dnl the Red Hat folks to do so just breaks source
575 dnl compatibility with other systems.
577 dnl We work around this by assuming that, as we didn't
578 dnl find a local libpcap, libpcap is in /usr/lib or
579 dnl /usr/local/lib and that the corresponding header
580 dnl file is under one of those directories; if we don't
581 dnl find it in either of those directories, we check to
582 dnl see if it's in a "pcap" subdirectory of them and,
583 dnl if so, add that subdirectory to the "-I" list.
585 dnl (We now also put pcap.h in /usr/include/pcap, but we
586 dnl leave behind a /usr/include/pcap.h that includes it,
587 dnl so you can still just include <pcap.h>.)
589 AC_MSG_CHECKING(for extraneous pcap header directories)
590 if test \( ! -r /usr/local/include/pcap.h \) -a \
591 \( ! -r /usr/include/pcap.h \); then
592 if test -r /usr/local/include/pcap/pcap.h; then
593 d="/usr/local/include/pcap"
594 elif test -r /usr/include/pcap/pcap.h; then
595 d="/usr/include/pcap"
598 if test -z "$d" ; then
599 AC_MSG_RESULT(not found)
602 AC_MSG_RESULT(found -- -I$d added)
608 # We found a local libpcap. Add it to the dependencies for
614 # Look for its pcap-config script.
616 AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $local_pcap_dir)
618 if test -n "$PCAP_CONFIG"; then
620 # We don't want its --cflags or --libs output, because
621 # those presume it's installed. For the C compiler flags,
622 # we add the source directory for the local libpcap, so
623 # we pick up its header files.
625 # We do, however, want its additional libraries, as required
626 # when linking statically, because it makes calls to
627 # routines in those libraries, so we'll need to link with
628 # them, because we'll be linking statically with it.
630 # If it supports --static-pcap-only. use that, as we will be
631 # linking with a static libpcap but won't be linking
632 # statically with any of the libraries on which it depends;
633 # those libraries might not even have static versions
636 # That means we need to find out the libraries on which
637 # libpcap directly depends, so we can link with them, but we
638 # don't need to link with the libraries on which those
639 # libraries depend as, on all UN*Xes with which I'm
640 # familiar, the libraries on which a shared library depends
641 # are stored in the library and are automatically loaded by
642 # the run-time linker, without the executable having to be
643 # linked with those libraries. (This allows a library to be
644 # changed to depend on more libraries without breaking that
647 # The only way to test for that support is to see if the
648 # script contains the string "static-pcap-only"; we can't
649 # try using that flag and checking for errors, as the
650 # versions of the script that didn't have that flag wouldn't
651 # report or return an error for an unsupported command-line
652 # flag. Those older versions provided, with --static, only
653 # the libraries on which libpcap depends, not the
654 # dependencies of those libraries; the versions with
655 # --static-pcap-only provide all the dependencies with
656 # --static, for the benefit of programs that are completely
657 # statically linked, and provide only the direct
658 # dependencies with --static-pcap-only.
660 AC_MSG_CHECKING([whether $PCAP_CONFIG supports --static-pcap-only])
662 # On Solaris 10, only /usr/xpg4/bin/grep supports the -s and
663 # -q flags, so we silence it by sending the standard output
664 # and error to /dev/null. The autoconf documentation
665 # recmmends avoiding those options in favor of redirecting
668 if grep "static-pcap-only" "$PCAP_CONFIG" >/dev/null 2>&1
671 static_opt="--static-pcap-only"
674 static_opt="--static"
676 $2="-I$local_pcap_dir $$2"
677 additional_libs=`"$PCAP_CONFIG" $static_opt --additional-libs`
678 libpcap="$libpcap $additional_libs"
681 # It doesn't have a pcap-config script.
682 # Make sure it has a pcap.h file.
684 places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
685 $EGREP '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
686 places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
687 $EGREP '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
689 if test -r $local_pcap_dir/pcap.h; then
690 pcapH=$local_pcap_dir
692 for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
693 if test -r $dir/pcap.h ; then
699 if test $pcapH = FAIL ; then
700 AC_MSG_ERROR(cannot find pcap.h: see the INSTALL.md file)
704 # Force the compiler to look for header files in the
705 # directory containing pcap.h.
711 if test -z "$PKG_CONFIG" -a -z "$PCAP_CONFIG"; then
713 # We don't have pkg-config or pcap-config; find out any additional
714 # link flags we need. (If we have pkg-config or pcap-config, we
715 # assume it tells us what we need.)
721 # If libpcap is DLPI-based, we have to use /lib/pse.exp if
722 # present, as we use the STREAMS routines.
724 # (XXX - true only if we're linking with a static libpcap?)
726 pseexe="/lib/pse.exp"
727 AC_MSG_CHECKING(for $pseexe)
728 if test -f $pseexe ; then
730 LIBS="$LIBS -I:$pseexe"
734 # If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
735 # we use them to load the BPF module.
737 # (XXX - true only if we're linking with a static libpcap?)
739 LIBS="$LIBS -lodm -lcfg"
743 # libdlpi is needed for Solaris 11 and later.
744 AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
749 LIBS="$libpcap $LIBS"
752 dnl Check for "pcap_loop()", to make sure we found a working
753 dnl libpcap and have all the right other libraries with which
754 dnl to link. (Otherwise, the checks below will fail, not
755 dnl because the routines are missing from the library, but
756 dnl because we aren't linking properly with libpcap, and
757 dnl that will cause confusing errors at build time.)
759 AC_CHECK_FUNC(pcap_loop,,
763 For some reason, linking with libpcap failed.
765 This may be a result of the way you have configured the build. For
766 example, you may have specified a static build with a version of libpcap
767 that cannot be linked statically, or you may have specified something
768 that would cause a 32-bit tcpdump to be linked with a 64-bit libpcap or
771 Please check the config.log file in the build directory. It should have
772 a line that says "checking for pcap_loop"; following that will be a
773 command that links a small test program with libpcap, and following that
774 should be error messages indicating why the attempt to link failed.
776 Then check the doc/README.{platform}.md file for the platform for which
777 you're building, to see if it gives any advice.])
782 dnl If the file .devel exists:
783 dnl Add some warning flags if the compiler supports them
784 dnl If an os prototype include exists, symlink os-proto.h to it
788 dnl AC_LBL_DEVEL(copt)
792 dnl $1 (copt appended)
793 dnl HAVE_OS_PROTO_H (defined)
794 dnl os-proto.h (symlinked)
796 AC_DEFUN(AC_LBL_DEVEL,
798 if test "${LBL_CFLAGS+set}" = set; then
799 $1="$$1 ${LBL_CFLAGS}"
801 if test -f .devel ; then
803 # Skip all the warning option stuff on some compilers.
805 if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
806 AC_LBL_CHECK_COMPILER_OPT($1, -W)
807 AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
808 AC_LBL_CHECK_COMPILER_OPT($1, -Wassign-enum)
809 AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual)
810 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
811 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
812 AC_LBL_CHECK_COMPILER_OPT($1, -Wnull-pointer-subtraction)
813 AC_LBL_CHECK_COMPILER_OPT($1, -Wold-style-definition)
814 AC_LBL_CHECK_COMPILER_OPT($1, -Wpedantic)
815 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
816 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
817 AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
818 AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
819 AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
820 AC_LBL_CHECK_COMPILER_OPT($1, -Wundef)
821 AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code-return)
822 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-parameter)
823 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-variable)
824 AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
825 AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings)
827 AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
828 AC_MSG_CHECKING([whether to use an os-proto.h header])
829 os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
831 if test -f $name ; then
832 AC_MSG_RESULT([yes, at "$name"])
833 ln -s $name os-proto.h
834 AC_DEFINE(HAVE_OS_PROTO_H, 1,
835 [if there's an os-proto.h for this platform, to use additional prototypes])
842 dnl This is a simplified adaptation of AC_LBL_LIBRARY_NET from libpcap.
843 dnl In this context tcpdump needs gethostbyaddr() only.
845 AC_DEFUN(AC_LBL_LIBRARY_NET, [
846 AC_CHECK_FUNC(gethostbyaddr,,
848 AC_CHECK_LIB(socket, gethostbyaddr,
850 LIBS="-lsocket -lnsl $LIBS"
853 AC_CHECK_LIB(network, gethostbyaddr,
855 LIBS="-lnetwork $LIBS"
858 AC_MSG_ERROR([gethostbyaddr is required, but wasn't found])
864 m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
865 dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
866 dnl serial 11 (pkg-config-0.29)
868 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
869 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
871 dnl This program is free software; you can redistribute it and/or modify
872 dnl it under the terms of the GNU General Public License as published by
873 dnl the Free Software Foundation; either version 2 of the License, or
874 dnl (at your option) any later version.
876 dnl This program is distributed in the hope that it will be useful, but
877 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
878 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
879 dnl General Public License for more details.
881 dnl You should have received a copy of the GNU General Public License
882 dnl along with this program; if not, write to the Free Software
883 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
886 dnl As a special exception to the GNU General Public License, if you
887 dnl distribute this file as part of a program that contains a
888 dnl configuration script generated by Autoconf, you may include it under
889 dnl the same distribution terms that you use for the rest of that
892 dnl PKG_PREREQ(MIN-VERSION)
893 dnl -----------------------
896 dnl Verify that the version of the pkg-config macros are at least
897 dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
898 dnl installed version of pkg-config, this checks the developer's version
899 dnl of pkg.m4 when generating configure.
901 dnl To ensure that this macro is defined, also add:
902 dnl m4_ifndef([PKG_PREREQ],
903 dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
905 dnl See the "Since" comment for each macro you use to see what version
906 dnl of the macros you require.
907 m4_defun([PKG_PREREQ],
908 [m4_define([PKG_MACROS_VERSION], [0.29])
909 m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
910 [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
913 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
914 dnl ----------------------------------
917 dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
918 dnl first found in the path. Checks that the version of pkg-config found
919 dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.17.0 is
920 dnl used since that's the first version where --static was supported.
921 AC_DEFUN([PKG_PROG_PKG_CONFIG],
922 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
923 m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
924 m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
925 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
926 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
927 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
929 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
930 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
932 if test -n "$PKG_CONFIG"; then
933 _pkg_min_version=m4_default([$1], [0.17.0])
934 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
935 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
942 ])dnl PKG_PROG_PKG_CONFIG
944 dnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
945 dnl -------------------------------------------------------------------
946 dnl Check to see whether a particular module exists. Similar to
947 dnl PKG_CHECK_MODULE(), but does not set variables or print errors.
949 dnl --exists was introduced in pkg-config 0.4.0; that dates back to late
950 dnl 2000, and we require 0.17.0 or later anyway, so we won't worry about
951 dnl earlier releases that lack it.
953 AC_DEFUN([PKG_CHECK_EXISTS],
955 if test -n "$PKG_CONFIG" && \
956 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
957 m4_default([$2], [:])
958 m4_ifvaln([$3], [else
962 dnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
963 dnl ---------------------------------------------
964 dnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
965 dnl pkg-config fails, reporting the error and quitting.
966 m4_define([_PKG_CONFIG_WITH_FLAGS],
967 [if test ! -n "$$1"; then
968 $1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
969 if test "x$?" != "x0"; then
971 # That failed - report an error.
972 # Re-run the command, telling pkg-config to print an error
973 # message, capture the error message, and report it.
974 # This causes the configuration script to fail, as it means
975 # the script is almost certainly doing something wrong.
977 _PKG_SHORT_ERRORS_SUPPORTED
978 if test $_pkg_short_errors_supported = yes; then
979 _pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
981 _pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
983 AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
986 ])dnl _PKG_CONFIG_WITH_FLAGS
989 dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
990 dnl ---------------------------------------------
991 dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
992 dnl pkg_failed based on the result.
993 m4_define([_PKG_CONFIG],
994 [if test -n "$$1"; then
996 elif test -n "$PKG_CONFIG"; then
997 PKG_CHECK_EXISTS([$3],
998 [pkg_cv_[]$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
999 test "x$?" != "x0" && pkg_failed=yes ],
1006 dnl _PKG_SHORT_ERRORS_SUPPORTED
1007 dnl ---------------------------
1008 dnl Internal check to see if pkg-config supports short errors.
1009 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
1011 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1012 _pkg_short_errors_supported=yes
1014 _pkg_short_errors_supported=no
1016 ])dnl _PKG_SHORT_ERRORS_SUPPORTED
1019 dnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1020 dnl [ACTION-IF-NOT-FOUND])
1021 dnl --------------------------------------------------------------
1022 dnl Check to see whether a particular module exists and, if it
1023 dnl does, set <MODULE>_CFLAGS, <MODULE>_LIBS, and <MODULE>_LIBS_STATIC
1024 dnl to the results of --cflags, --libs, and --libs --static,
1027 AC_DEFUN([PKG_CHECK_MODULE],
1029 if test -n "$PKG_CONFIG"; then
1030 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
1031 AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
1032 AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
1034 AC_MSG_CHECKING([for $2 with pkg-config])
1035 if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
1037 # The package was found, so try to get its C flags and
1040 AC_MSG_RESULT([found])
1041 _PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
1042 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
1043 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
1044 m4_default([$3], [:])
1046 AC_MSG_RESULT([not found])
1047 m4_default([$4], [:])
1050 # No pkg-config, so obviously not found with pkg-config.
1051 m4_default([$4], [:])
1053 ])dnl PKG_CHECK_MODULE
1056 dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1057 dnl [ACTION-IF-NOT-FOUND])
1058 dnl ---------------------------------------------------------------------
1061 dnl Checks for existence of MODULE and gathers its build flags with
1062 dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
1063 dnl and VARIABLE-PREFIX_LIBS from --libs.
1064 AC_DEFUN([PKG_CHECK_MODULE_STATIC],
1066 _save_PKG_CONFIG=$PKG_CONFIG
1067 PKG_CONFIG="$PKG_CONFIG --static"
1068 PKG_CHECK_MODULE($@)
1069 PKG_CONFIG=$_save_PKG_CONFIG[]dnl
1070 ])dnl PKG_CHECK_MODULE_STATIC
1073 dnl PKG_INSTALLDIR([DIRECTORY])
1074 dnl -------------------------
1077 dnl Substitutes the variable pkgconfigdir as the location where a module
1078 dnl should install pkg-config .pc files. By default the directory is
1079 dnl $libdir/pkgconfig, but the default can be changed by passing
1080 dnl DIRECTORY. The user can override through the --with-pkgconfigdir
1082 AC_DEFUN([PKG_INSTALLDIR],
1083 [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
1084 m4_pushdef([pkg_description],
1085 [pkg-config installation directory @<:@]pkg_default[@:>@])
1086 AC_ARG_WITH([pkgconfigdir],
1087 [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
1088 [with_pkgconfigdir=]pkg_default)
1089 AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1090 m4_popdef([pkg_default])
1091 m4_popdef([pkg_description])
1092 ])dnl PKG_INSTALLDIR
1095 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1096 dnl --------------------------------
1099 dnl Substitutes the variable noarch_pkgconfigdir as the location where a
1100 dnl module should install arch-independent pkg-config .pc files. By
1101 dnl default the directory is $datadir/pkgconfig, but the default can be
1102 dnl changed by passing DIRECTORY. The user can override through the
1103 dnl --with-noarch-pkgconfigdir parameter.
1104 AC_DEFUN([PKG_NOARCH_INSTALLDIR],
1105 [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1106 m4_pushdef([pkg_description],
1107 [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1108 AC_ARG_WITH([noarch-pkgconfigdir],
1109 [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1110 [with_noarch_pkgconfigdir=]pkg_default)
1111 AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1112 m4_popdef([pkg_default])
1113 m4_popdef([pkg_description])
1114 ])dnl PKG_NOARCH_INSTALLDIR
1117 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1118 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1119 dnl -------------------------------------------
1122 dnl Retrieves the value of the pkg-config variable for the given module.
1123 AC_DEFUN([PKG_CHECK_VAR],
1125 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1127 _PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1128 AS_VAR_COPY([$1], [pkg_cv_][$1])
1130 AS_VAR_IF([$1], [""], [$5], [$4])dnl