]> The Tcpdump Group git mirrors - tcpdump/blob - aclocal.m4
CI: Add warning exemptions for Sun C (suncc-5.14) on Solaris 10
[tcpdump] / aclocal.m4
1 dnl Copyright (c) 1995, 1996, 1997, 1998
2 dnl The Regents of the University of California. All rights reserved.
3 dnl
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.
19 dnl
20 dnl LBL autoconf macros
21 dnl
22
23 dnl
24 dnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
25 dnl
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.
31 dnl
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.
37 dnl
38 AC_DEFUN(AC_LBL_C_INIT_BEFORE_CC,
39 [
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])
44 $1=""
45 if test "${srcdir}" != "." ; then
46 $1="-I$srcdir"
47 fi
48 if test "${CFLAGS+set}" = set; then
49 LBL_CFLAGS="$CFLAGS"
50 fi
51 if test -z "$CC" -a "$with_gcc" = no ; then
52 CC=cc
53 export CC
54 fi
55 ])
56
57 dnl
58 dnl Determine which compiler we're using (cc or gcc)
59 dnl If using gcc, determine the version number
60 dnl If using cc:
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
66 dnl
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".
69 dnl
70 dnl usage:
71 dnl
72 dnl AC_LBL_C_INIT(copt, incls)
73 dnl
74 dnl results:
75 dnl
76 dnl $1 (copt set)
77 dnl $2 (incls set)
78 dnl CC
79 dnl LDFLAGS
80 dnl LBL_CFLAGS
81 dnl
82 AC_DEFUN(AC_LBL_C_INIT,
83 [
84 AC_BEFORE([$0], [AC_LBL_DEVEL])
85 if test "$GCC" = yes ; then
86 #
87 # -Werror forces warnings to be errors.
88 #
89 ac_lbl_cc_force_warning_errors=-Werror
90 else
91 $2="$$2 -I/usr/local/include"
92 LDFLAGS="$LDFLAGS -L/usr/local/lib"
93
94 case "$host_os" in
95
96 darwin*)
97 #
98 # This is assumed either to be GCC or clang, both
99 # of which use -Werror to force warnings to be errors.
100 #
101 # XXX - they also both cause GCC to be set to yes,
102 # so we should never get here in the first place.
103 #
104 ac_lbl_cc_force_warning_errors=-Werror
105 ;;
106
107 hpux*)
108 #
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.
114 #
115 ac_lbl_cc_dont_try_gcc_dashW=yes
116 ;;
117
118 solaris*)
119 #
120 # Assumed to be Sun C, which requires -errwarn to force
121 # warnings to be treated as errors.
122 #
123 ac_lbl_cc_force_warning_errors=-errwarn
124 ;;
125 esac
126 $1="$$1 -O"
127 fi
128 ])
129
130 dnl
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.
135 dnl
136 AC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
137 [
138 save_CFLAGS="$CFLAGS"
139 save_LIBS="$LIBS"
140 save_LDFLAGS="$LDFLAGS"
141 ])
142
143 dnl
144 dnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
145 dnl
146 AC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
147 [
148 CFLAGS="$save_CFLAGS"
149 LIBS="$save_LIBS"
150 LDFLAGS="$save_LDFLAGS"
151 ])
152
153 dnl
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
157 dnl
158 AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
159 [
160 AC_MSG_CHECKING([whether the compiler supports the $2 option])
161 save_CFLAGS="$CFLAGS"
162 CFLAGS="$CFLAGS $2"
163 #
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
168 # for it:
169 #
170 # https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
171 #
172 save_ac_c_werror_flag="$ac_c_werror_flag"
173 ac_c_werror_flag=yes
174 #
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
182 #
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
185 #
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.
188 #
189 AC_COMPILE_IFELSE(
190 [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
191 [
192 AC_MSG_RESULT([yes])
193 CFLAGS="$save_CFLAGS"
194 $1="$$1 $2"
195 ],
196 [
197 AC_MSG_RESULT([no])
198 CFLAGS="$save_CFLAGS"
199 ])
200 ac_c_werror_flag="$save_ac_c_werror_flag"
201 ])
202
203 dnl
204 dnl Check whether the compiler supports an option to generate
205 dnl Makefile-style dependency lines
206 dnl
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.
209 dnl
210 dnl We test whether the flag in question is supported, as older
211 dnl versions of compilers might not support it.
212 dnl
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.
216 dnl
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.
221 dnl
222 AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
223 [
224 AC_MSG_CHECKING([whether the compiler supports generating dependencies])
225 if test "$GCC" = yes ; then
226 #
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
229 # would be -M.
230 #
231 ac_lbl_dependency_flag="-M"
232 else
233 #
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.)
239 #
240 case "$host_os" in
241
242 darwin*)
243 #
244 # Clang uses -M.
245 #
246 ac_lbl_dependency_flag="-M"
247 ;;
248
249 solaris*)
250 #
251 # Sun C uses -xM.
252 #
253 ac_lbl_dependency_flag="-xM"
254 ;;
255
256 hpux*)
257 #
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.
264 #
265 ac_lbl_dependency_flag="+Make"
266 ;;
267
268 *)
269 #
270 # Not one of the above; assume no support for
271 # generating dependencies.
272 #
273 ac_lbl_dependency_flag=""
274 ;;
275 esac
276 fi
277
278 #
279 # Is ac_lbl_dependency_flag defined and, if so, does the compiler
280 # complain about it?
281 #
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
286 # isn't an issue.
287 #
288 if test ! -z "$ac_lbl_dependency_flag"; then
289 AC_LANG_CONFTEST(
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'
295 else
296 AC_MSG_RESULT([no])
297 #
298 # We can't run mkdep, so have "make depend" do
299 # nothing.
300 #
301 MKDEP=:
302 fi
303 rm -rf conftest*
304 else
305 AC_MSG_RESULT([no])
306 #
307 # We can't run mkdep, so have "make depend" do
308 # nothing.
309 #
310 MKDEP=:
311 fi
312 AC_SUBST(DEPENDENCY_CFLAG)
313 AC_SUBST(MKDEP)
314 ])
315
316 dnl
317 dnl Require libpcap
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.
321 dnl
322 dnl usage:
323 dnl
324 dnl AC_LBL_LIBPCAP(pcapdep, incls)
325 dnl
326 dnl results:
327 dnl
328 dnl $1 (pcapdep set)
329 dnl $2 (incls appended)
330 dnl LIBS
331 dnl
332 AC_DEFUN(AC_LBL_LIBPCAP,
333 [
334 AC_REQUIRE([AC_PROG_EGREP])
335 AC_REQUIRE([AC_LBL_LIBRARY_NET])
336 libpcap=FAIL
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@:>@]),,
341 enableval=yes)
342 case "$enableval" in
343
344 no)
345 AC_MSG_RESULT(no)
346 #
347 # Don't look for a local libpcap.
348 #
349 using_local_libpcap=no
350 ;;
351
352 *)
353 AC_MSG_RESULT(yes)
354 #
355 # Look for a local pcap library.
356 #
357 AC_MSG_CHECKING(for local pcap library)
358 lastdir=FAIL
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
368 continue;
369 fi
370 lastdir=$dir
371 if test -r $dir/libpcap.a ; then
372 libpcap=$dir/libpcap.a
373 local_pcap_dir=$dir
374 dnl continue and select the last one that exists
375 fi
376 done
377 if test $libpcap = FAIL ; then
378 #
379 # We didn't find a local libpcap.
380 #
381 AC_MSG_RESULT(not found)
382 using_local_libpcap=no;
383 else
384 #
385 # We found a local libpcap.
386 #
387 AC_MSG_RESULT($libpcap)
388 using_local_libpcap=yes
389 fi
390 ;;
391 esac
392
393 if test $using_local_libpcap = no ; then
394 #
395 # We didn't find a local libpcap.
396 # First, try finding it with pkg-config.
397 #
398 PKG_CHECK_MODULE(LIBPCAP, libpcap,
399 [
400 #
401 # We found it; use the results as configuration information
402 # for libpcap.
403 #
404 $2="$LIBPCAP_CFLAGS $$2"
405 libpcap="$LIBPCAP_LIBS"
406 ],
407 [
408 #
409 # We didn't find it; look for an installed pcap-config.
410 #
411 AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
412 if test -n "$PCAP_CONFIG" ; then
413 #
414 # Found - use it to get the include flags for
415 # libpcap and the flags to link with libpcap.
416 #
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
421 # around them.
422 #
423 if test \( "$PCAP_CONFIG" = "/usr/bin/pcap-config" \) -o \
424 \( "$PCAP_CONFIG" = "/usr/ccs/bin/pcap-config" \) ; then
425 #
426 # It's vendor-supplied.
427 #
428 case "$host_os" in
429
430 darwin*)
431 #
432 # This is macOS or another Darwin-based OS.
433 #
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.
440 #
441 _broken_apple_pcap_config=yes
442
443 #
444 # Furthermore:
445 #
446 # macOS Sonoma's libpcap includes stub versions
447 # of the remote-capture APIs. They are exported
448 # as "weakly linked symbols".
449 #
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
457 # linking.)
458 #
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().
463 #
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.
469 #
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.
477 #
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.
483 #
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.
487 #
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.
493 #
494 _dont_check_for_remote_apis=yes
495 ;;
496
497 solaris*)
498 #
499 # This is Solaris 2 or later, i.e. SunOS 5.x.
500 #
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.
508 #
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".
512 #
513 # Are we building 32-bit or 64-bit? Get the
514 # size of void *, and check that.
515 #
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
520 #
521 # Success - change PCAP_CONFIG.
522 #
523 PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"`
524 fi
525 fi
526 ;;
527 esac
528 fi
529 #
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!)."
536 #
537 cflags=`"$PCAP_CONFIG" --cflags`
538 #
539 # Work around macOS (and probably other Darwin) brokenness,
540 # by not adding /usr/local/include if it's from the broken
541 # Apple pcap-config.
542 #
543 if test "$_broken_apple_pcap_config" = "yes" ; then
544 #
545 # Strip -I/usr/local/include with sed.
546 #
547 cflags=`echo $cflags | sed 's;-I/usr/local/include;;'`
548 fi
549 $2="$cflags $$2"
550 libpcap=`"$PCAP_CONFIG" --libs`
551 #
552 # Work around macOS (and probably other Darwin) brokenness,
553 # by not adding /usr/local/lib if it's from the broken
554 # Apple pcap-config.
555 #
556 if test "$_broken_apple_pcap_config" = "yes" ; then
557 #
558 # Strip -L/usr/local/lib with sed.
559 #
560 libpcap=`echo $libpcap | sed 's;-L/usr/local/lib;;'`
561 fi
562 else
563 #
564 # Not found; look for an installed pcap.
565 #
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)
569 fi
570 dnl
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.
576 dnl
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.
584 dnl
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>.)
588 dnl
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"
596 fi
597 fi
598 if test -z "$d" ; then
599 AC_MSG_RESULT(not found)
600 else
601 $2="-I$d $$2"
602 AC_MSG_RESULT(found -- -I$d added)
603 fi
604 fi
605 ])
606 else
607 #
608 # We found a local libpcap. Add it to the dependencies for
609 # tcpdump.
610 #
611 $1=$libpcap
612
613 #
614 # Look for its pcap-config script.
615 #
616 AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $local_pcap_dir)
617
618 if test -n "$PCAP_CONFIG"; then
619 #
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.
624 #
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.
629 #
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
634 # installed.
635 #
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
645 # library's ABI.)
646 #
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.
659 #
660 AC_MSG_CHECKING([whether $PCAP_CONFIG supports --static-pcap-only])
661 #
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
666 # to /dev/null.
667 #
668 if grep "static-pcap-only" "$PCAP_CONFIG" >/dev/null 2>&1
669 then
670 AC_MSG_RESULT([yes])
671 static_opt="--static-pcap-only"
672 else
673 AC_MSG_RESULT([no])
674 static_opt="--static"
675 fi
676 $2="-I$local_pcap_dir $$2"
677 additional_libs=`"$PCAP_CONFIG" $static_opt --additional-libs`
678 libpcap="$libpcap $additional_libs"
679 else
680 #
681 # It doesn't have a pcap-config script.
682 # Make sure it has a pcap.h file.
683 #
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]]*)?$'`
688 pcapH=FAIL
689 if test -r $local_pcap_dir/pcap.h; then
690 pcapH=$local_pcap_dir
691 else
692 for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
693 if test -r $dir/pcap.h ; then
694 pcapH=$dir
695 fi
696 done
697 fi
698
699 if test $pcapH = FAIL ; then
700 AC_MSG_ERROR(cannot find pcap.h: see the INSTALL.md file)
701 fi
702
703 #
704 # Force the compiler to look for header files in the
705 # directory containing pcap.h.
706 #
707 $2="-I$pcapH $$2"
708 fi
709 fi
710
711 if test -z "$PKG_CONFIG" -a -z "$PCAP_CONFIG"; then
712 #
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.)
716 #
717 case "$host_os" in
718
719 aix*)
720 #
721 # If libpcap is DLPI-based, we have to use /lib/pse.exp if
722 # present, as we use the STREAMS routines.
723 #
724 # (XXX - true only if we're linking with a static libpcap?)
725 #
726 pseexe="/lib/pse.exp"
727 AC_MSG_CHECKING(for $pseexe)
728 if test -f $pseexe ; then
729 AC_MSG_RESULT(yes)
730 LIBS="$LIBS -I:$pseexe"
731 fi
732
733 #
734 # If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
735 # we use them to load the BPF module.
736 #
737 # (XXX - true only if we're linking with a static libpcap?)
738 #
739 LIBS="$LIBS -lodm -lcfg"
740 ;;
741
742 solaris*)
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)
745 ;;
746 esac
747 fi
748
749 LIBS="$libpcap $LIBS"
750
751 dnl
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.)
758 dnl
759 AC_CHECK_FUNC(pcap_loop,,
760 [
761 AC_MSG_ERROR(
762 [
763 For some reason, linking with libpcap failed.
764
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
769 vice versa.
770
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.
775
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.])
778 ])
779 ])
780
781 dnl
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
785 dnl
786 dnl usage:
787 dnl
788 dnl AC_LBL_DEVEL(copt)
789 dnl
790 dnl results:
791 dnl
792 dnl $1 (copt appended)
793 dnl HAVE_OS_PROTO_H (defined)
794 dnl os-proto.h (symlinked)
795 dnl
796 AC_DEFUN(AC_LBL_DEVEL,
797 [rm -f os-proto.h
798 if test "${LBL_CFLAGS+set}" = set; then
799 $1="$$1 ${LBL_CFLAGS}"
800 fi
801 if test -f .devel ; then
802 #
803 # Skip all the warning option stuff on some compilers.
804 #
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)
826 fi
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/'`
830 name="lbl/os-$os.h"
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])
836 else
837 AC_MSG_RESULT([no])
838 fi
839 fi])
840
841 dnl
842 dnl This is a simplified adaptation of AC_LBL_LIBRARY_NET from libpcap.
843 dnl In this context tcpdump needs gethostbyaddr() only.
844 dnl
845 AC_DEFUN(AC_LBL_LIBRARY_NET, [
846 AC_CHECK_FUNC(gethostbyaddr,,
847 [
848 AC_CHECK_LIB(socket, gethostbyaddr,
849 [
850 LIBS="-lsocket -lnsl $LIBS"
851 ],
852 [
853 AC_CHECK_LIB(network, gethostbyaddr,
854 [
855 LIBS="-lnetwork $LIBS"
856 ],
857 [
858 AC_MSG_ERROR([gethostbyaddr is required, but wasn't found])
859 ])
860 ], -lnsl)
861 ])
862 ])
863
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)
867 dnl
868 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
869 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
870 dnl
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.
875 dnl
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.
880 dnl
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
884 dnl 02111-1307, USA.
885 dnl
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
890 dnl program.
891
892 dnl PKG_PREREQ(MIN-VERSION)
893 dnl -----------------------
894 dnl Since: 0.29
895 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.
900 dnl
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])])
904 dnl
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])])
911 ])dnl PKG_PREREQ
912
913 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
914 dnl ----------------------------------
915 dnl Since: 0.16
916 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])
928
929 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
930 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
931 fi
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
936 AC_MSG_RESULT([yes])
937 else
938 AC_MSG_RESULT([no])
939 PKG_CONFIG=""
940 fi
941 fi[]dnl
942 ])dnl PKG_PROG_PKG_CONFIG
943
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.
948 dnl
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.
952 dnl
953 AC_DEFUN([PKG_CHECK_EXISTS],
954 [
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
959 $3])dnl
960 fi])
961
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
970 #
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.
976 #
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`
980 else
981 _pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
982 fi
983 AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
984 fi
985 fi[]dnl
986 ])dnl _PKG_CONFIG_WITH_FLAGS
987
988
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
995 pkg_cv_[]$1="$$1"
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 ],
1000 [pkg_failed=yes])
1001 else
1002 pkg_failed=untried
1003 fi[]dnl
1004 ])dnl _PKG_CONFIG
1005
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],
1010 [
1011 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1012 _pkg_short_errors_supported=yes
1013 else
1014 _pkg_short_errors_supported=no
1015 fi[]dnl
1016 ])dnl _PKG_SHORT_ERRORS_SUPPORTED
1017
1018
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,
1025 dnl respectively.
1026 dnl
1027 AC_DEFUN([PKG_CHECK_MODULE],
1028 [
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
1033
1034 AC_MSG_CHECKING([for $2 with pkg-config])
1035 if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
1036 #
1037 # The package was found, so try to get its C flags and
1038 # libraries.
1039 #
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], [:])
1045 else
1046 AC_MSG_RESULT([not found])
1047 m4_default([$4], [:])
1048 fi
1049 else
1050 # No pkg-config, so obviously not found with pkg-config.
1051 m4_default([$4], [:])
1052 fi
1053 ])dnl PKG_CHECK_MODULE
1054
1055
1056 dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1057 dnl [ACTION-IF-NOT-FOUND])
1058 dnl ---------------------------------------------------------------------
1059 dnl Since: 0.29
1060 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],
1065 [
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
1071
1072
1073 dnl PKG_INSTALLDIR([DIRECTORY])
1074 dnl -------------------------
1075 dnl Since: 0.27
1076 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
1081 dnl parameter.
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
1093
1094
1095 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1096 dnl --------------------------------
1097 dnl Since: 0.27
1098 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
1115
1116
1117 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1118 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1119 dnl -------------------------------------------
1120 dnl Since: 0.28
1121 dnl
1122 dnl Retrieves the value of the pkg-config variable for the given module.
1123 AC_DEFUN([PKG_CHECK_VAR],
1124 [
1125 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1126
1127 _PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1128 AS_VAR_COPY([$1], [pkg_cv_][$1])
1129
1130 AS_VAR_IF([$1], [""], [$5], [$4])dnl
1131 ])dnl PKG_CHECK_VAR