]> The Tcpdump Group git mirrors - tcpdump/blob - aclocal.m4
msdp: do some additional bounds checks.
[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" ; then
52 case "$host_os" in
53
54 bsdi*)
55 AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
56 if test $SHLICC2 = yes ; then
57 CC=shlicc2
58 export CC
59 fi
60 ;;
61 esac
62 fi
63 if test -z "$CC" -a "$with_gcc" = no ; then
64 CC=cc
65 export CC
66 fi
67 ])
68
69 dnl
70 dnl Determine which compiler we're using (cc or gcc)
71 dnl If using gcc, determine the version number
72 dnl If using cc:
73 dnl require that it support ansi prototypes
74 dnl use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
75 dnl do that ourselves for gcc)
76 dnl add -g flags, as appropriate
77 dnl explicitly specify /usr/local/include
78 dnl
79 dnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
80 dnl that defines __GNUC__, which means clang, for example, counts as "gcc".
81 dnl
82 dnl usage:
83 dnl
84 dnl AC_LBL_C_INIT(copt, incls)
85 dnl
86 dnl results:
87 dnl
88 dnl $1 (copt set)
89 dnl $2 (incls set)
90 dnl CC
91 dnl LDFLAGS
92 dnl LBL_CFLAGS
93 dnl
94 AC_DEFUN(AC_LBL_C_INIT,
95 [
96 AC_BEFORE([$0], [AC_LBL_DEVEL])
97 if test "$GCC" = yes ; then
98 #
99 # -Werror forces warnings to be errors.
100 #
101 ac_lbl_cc_force_warning_errors=-Werror
102 else
103 $2="$$2 -I/usr/local/include"
104 LDFLAGS="$LDFLAGS -L/usr/local/lib"
105
106 case "$host_os" in
107
108 darwin*)
109 #
110 # This is assumed either to be GCC or clang, both
111 # of which use -Werror to force warnings to be errors.
112 #
113 ac_lbl_cc_force_warning_errors=-Werror
114 ;;
115
116 hpux*)
117 #
118 # HP C, which is what we presume we're using, doesn't
119 # exit with a non-zero exit status if we hand it an
120 # invalid -W flag, can't be forced to do so even with
121 # +We, and doesn't handle GCC-style -W flags, so we
122 # don't want to try using GCC-style -W flags.
123 #
124 ac_lbl_cc_dont_try_gcc_dashW=yes
125 ;;
126
127 irix*)
128 #
129 # MIPS C, which is what we presume we're using, doesn't
130 # necessarily exit with a non-zero exit status if we
131 # hand it an invalid -W flag, can't be forced to do
132 # so, and doesn't handle GCC-style -W flags, so we
133 # don't want to try using GCC-style -W flags.
134 #
135 ac_lbl_cc_dont_try_gcc_dashW=yes
136 #
137 # It also, apparently, defaults to "char" being
138 # unsigned, unlike most other C implementations;
139 # I suppose we could say "signed char" whenever
140 # we want to guarantee a signed "char", but let's
141 # just force signed chars.
142 #
143 # -xansi is normally the default, but the
144 # configure script was setting it; perhaps -cckr
145 # was the default in the Old Days. (Then again,
146 # that would probably be for backwards compatibility
147 # in the days when ANSI C was Shiny and New, i.e.
148 # 1989 and the early '90's, so maybe we can just
149 # drop support for those compilers.)
150 #
151 # -g is equivalent to -g2, which turns off
152 # optimization; we choose -g3, which generates
153 # debugging information but doesn't turn off
154 # optimization (even if the optimization would
155 # cause inaccuracies in debugging).
156 #
157 $1="$$1 -xansi -signed -g3"
158 ;;
159
160 osf*)
161 #
162 # Presumed to be DEC OSF/1, Digital UNIX, or
163 # Tru64 UNIX.
164 #
165 # The DEC C compiler, which is what we presume we're
166 # using, doesn't exit with a non-zero exit status if we
167 # hand it an invalid -W flag, can't be forced to do
168 # so, and doesn't handle GCC-style -W flags, so we
169 # don't want to try using GCC-style -W flags.
170 #
171 ac_lbl_cc_dont_try_gcc_dashW=yes
172 #
173 # -g is equivalent to -g2, which turns off
174 # optimization; we choose -g3, which generates
175 # debugging information but doesn't turn off
176 # optimization (even if the optimization would
177 # cause inaccuracies in debugging).
178 #
179 $1="$$1 -g3"
180 ;;
181
182 solaris*)
183 #
184 # Assumed to be Sun C, which requires -errwarn to force
185 # warnings to be treated as errors.
186 #
187 ac_lbl_cc_force_warning_errors=-errwarn
188 ;;
189
190 ultrix*)
191 AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
192 AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
193 AC_TRY_COMPILE(
194 [#include <sys/types.h>],
195 [struct a { int b; };
196 void c(const struct a *)],
197 ac_cv_lbl_cc_const_proto=yes,
198 ac_cv_lbl_cc_const_proto=no))
199 AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
200 if test $ac_cv_lbl_cc_const_proto = no ; then
201 AC_DEFINE(const,[],
202 [to handle Ultrix compilers that don't support const in prototypes])
203 fi
204 ;;
205 esac
206 $1="$$1 -O"
207 fi
208 ])
209
210 dnl
211 dnl Save the values of various variables that affect compilation and
212 dnl linking, and that we don't ourselves modify persistently; done
213 dnl before a test involving compiling or linking is done, so that we
214 dnl can restore those variables after the test is done.
215 dnl
216 AC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
217 [
218 save_CFLAGS="$CFLAGS"
219 save_LIBS="$LIBS"
220 save_LDFLAGS="$LDFLAGS"
221 ])
222
223 dnl
224 dnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
225 dnl
226 AC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
227 [
228 CFLAGS="$save_CFLAGS"
229 LIBS="$save_LIBS"
230 LDFLAGS="$save_LDFLAGS"
231 ])
232
233 dnl
234 dnl Check whether the compiler option specified as the second argument
235 dnl is supported by the compiler and, if so, add it to the macro
236 dnl specified as the first argument
237 dnl
238 AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
239 [
240 AC_MSG_CHECKING([whether the compiler supports the $2 option])
241 save_CFLAGS="$CFLAGS"
242 CFLAGS="$CFLAGS $2"
243 #
244 # XXX - yes, this depends on the way AC_LANG_WERROR works,
245 # but no mechanism is provided to turn AC_LANG_WERROR on
246 # *and then turn it back off*, so that we *only* do it when
247 # testing compiler options - 15 years after somebody asked
248 # for it:
249 #
250 # https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
251 #
252 save_ac_c_werror_flag="$ac_c_werror_flag"
253 ac_c_werror_flag=yes
254 #
255 # We use AC_LANG_SOURCE() so that we can control the complete
256 # content of the program being compiled. We do not, for example,
257 # want the default "int main()" that AC_LANG_PROGRAM() generates,
258 # as it will generate a warning with -Wold-style-definition, meaning
259 # that we would treat it as not working, as the test will fail if
260 # *any* error output, including a warning due to the flag we're
261 # testing, is generated; see
262 #
263 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
264 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
265 #
266 # This may, as per those two messages, be fixed in autoconf 2.70,
267 # but we only require 2.69 or newer for now.
268 #
269 AC_COMPILE_IFELSE(
270 [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
271 [
272 AC_MSG_RESULT([yes])
273 CFLAGS="$save_CFLAGS"
274 $1="$$1 $2"
275 ],
276 [
277 AC_MSG_RESULT([no])
278 CFLAGS="$save_CFLAGS"
279 ])
280 ac_c_werror_flag="$save_ac_c_werror_flag"
281 ])
282
283 dnl
284 dnl Check whether the compiler supports an option to generate
285 dnl Makefile-style dependency lines
286 dnl
287 dnl GCC uses -M for this. Non-GCC compilers that support this
288 dnl use a variety of flags, including but not limited to -M.
289 dnl
290 dnl We test whether the flag in question is supported, as older
291 dnl versions of compilers might not support it.
292 dnl
293 dnl We don't try all the possible flags, just in case some flag means
294 dnl "generate dependencies" on one compiler but means something else
295 dnl on another compiler.
296 dnl
297 dnl Most compilers that support this send the output to the standard
298 dnl output by default. IBM's XLC, however, supports -M but sends
299 dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
300 dnl to work around that, so we don't bother with XLC.
301 dnl
302 AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
303 [
304 AC_MSG_CHECKING([whether the compiler supports generating dependencies])
305 if test "$GCC" = yes ; then
306 #
307 # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
308 # though it's not); we assume that, in this case, the flag
309 # would be -M.
310 #
311 ac_lbl_dependency_flag="-M"
312 else
313 #
314 # Not GCC or a compiler deemed to be GCC; what platform is
315 # this? (We're assuming that if the compiler isn't GCC
316 # it's the compiler from the vendor of the OS; that won't
317 # necessarily be true for x86 platforms, where it might be
318 # the Intel C compiler.)
319 #
320 case "$host_os" in
321
322 irix*|osf*|darwin*)
323 #
324 # MIPS C for IRIX, DEC C, and clang all use -M.
325 #
326 ac_lbl_dependency_flag="-M"
327 ;;
328
329 solaris*)
330 #
331 # Sun C uses -xM.
332 #
333 ac_lbl_dependency_flag="-xM"
334 ;;
335
336 hpux*)
337 #
338 # HP's older C compilers don't support this.
339 # HP's newer C compilers support this with
340 # either +M or +Make; the older compilers
341 # interpret +M as something completely
342 # different, so we use +Make so we don't
343 # think it works with the older compilers.
344 #
345 ac_lbl_dependency_flag="+Make"
346 ;;
347
348 *)
349 #
350 # Not one of the above; assume no support for
351 # generating dependencies.
352 #
353 ac_lbl_dependency_flag=""
354 ;;
355 esac
356 fi
357
358 #
359 # Is ac_lbl_dependency_flag defined and, if so, does the compiler
360 # complain about it?
361 #
362 # Note: clang doesn't seem to exit with an error status when handed
363 # an unknown non-warning error, even if you pass it
364 # -Werror=unknown-warning-option. However, it always supports
365 # -M, so the fact that this test always succeeds with clang
366 # isn't an issue.
367 #
368 if test ! -z "$ac_lbl_dependency_flag"; then
369 AC_LANG_CONFTEST(
370 [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
371 if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
372 AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
373 DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
374 MKDEP='${top_srcdir}/mkdep'
375 else
376 AC_MSG_RESULT([no])
377 #
378 # We can't run mkdep, so have "make depend" do
379 # nothing.
380 #
381 MKDEP=:
382 fi
383 rm -rf conftest*
384 else
385 AC_MSG_RESULT([no])
386 #
387 # We can't run mkdep, so have "make depend" do
388 # nothing.
389 #
390 MKDEP=:
391 fi
392 AC_SUBST(DEPENDENCY_CFLAG)
393 AC_SUBST(MKDEP)
394 ])
395
396 #
397 # Try compiling a sample of the type of code that appears in
398 # gencode.c with "inline", "__inline__", and "__inline".
399 #
400 # Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
401 # as it just tests whether a function returning "int" can be inlined;
402 # at least some versions of HP's C compiler can inline that, but can't
403 # inline a function that returns a struct pointer.
404 #
405 # Make sure we use the V_CCOPT flags, because some of those might
406 # disable inlining.
407 #
408 AC_DEFUN(AC_LBL_C_INLINE,
409 [AC_MSG_CHECKING(for inline)
410 save_CFLAGS="$CFLAGS"
411 CFLAGS="$V_CCOPT"
412 AC_CACHE_VAL(ac_cv_lbl_inline, [
413 ac_cv_lbl_inline=""
414 ac_lbl_cc_inline=no
415 for ac_lbl_inline in inline __inline__ __inline
416 do
417 AC_TRY_COMPILE(
418 [#define inline $ac_lbl_inline
419 static inline struct iltest *foo(void);
420 struct iltest {
421 int iltest1;
422 int iltest2;
423 };
424
425 static inline struct iltest *
426 foo()
427 {
428 static struct iltest xxx;
429
430 return &xxx;
431 }],,ac_lbl_cc_inline=yes,)
432 if test "$ac_lbl_cc_inline" = yes ; then
433 break;
434 fi
435 done
436 if test "$ac_lbl_cc_inline" = yes ; then
437 ac_cv_lbl_inline=$ac_lbl_inline
438 fi])
439 CFLAGS="$save_CFLAGS"
440 if test ! -z "$ac_cv_lbl_inline" ; then
441 AC_MSG_RESULT($ac_cv_lbl_inline)
442 else
443 AC_MSG_RESULT(no)
444 fi
445 AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
446
447 dnl
448 dnl Use pfopen.c if available and pfopen() not in standard libraries
449 dnl Require libpcap
450 dnl Look for libpcap in directories under ..; those are local versions.
451 dnl Look for an installed libpcap if there is no local version or if
452 dnl the user said not to look for a local version.
453 dnl
454 dnl usage:
455 dnl
456 dnl AC_LBL_LIBPCAP(pcapdep, incls)
457 dnl
458 dnl results:
459 dnl
460 dnl $1 (pcapdep set)
461 dnl $2 (incls appended)
462 dnl LIBS
463 dnl LBL_LIBS
464 dnl
465 AC_DEFUN(AC_LBL_LIBPCAP,
466 [
467 AC_REQUIRE([AC_PROG_EGREP])
468 AC_REQUIRE([AC_LBL_LIBRARY_NET])
469 dnl
470 dnl save a copy before locating libpcap.a
471 dnl
472 LBL_LIBS="$LIBS"
473 pfopen=/usr/examples/packetfilter/pfopen.c
474 if test -f $pfopen ; then
475 AC_CHECK_FUNCS(pfopen)
476 if test $ac_cv_func_pfopen = "no" ; then
477 AC_MSG_RESULT(Using $pfopen)
478 LIBS="$LIBS $pfopen"
479 fi
480 fi
481 libpcap=FAIL
482 AC_MSG_CHECKING([whether to look for a local libpcap])
483 AC_ARG_ENABLE(local-libpcap,
484 AS_HELP_STRING([--disable-local-libpcap],
485 [don't look for a local libpcap @<:@default=check for a local libpcap@:>@]),,
486 enableval=yes)
487 case "$enableval" in
488
489 no)
490 AC_MSG_RESULT(no)
491 #
492 # Don't look for a local libpcap.
493 #
494 using_local_libpcap=no
495 ;;
496
497 *)
498 AC_MSG_RESULT(yes)
499 #
500 # Look for a local pcap library.
501 #
502 AC_MSG_CHECKING(for local pcap library)
503 lastdir=FAIL
504 places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
505 $EGREP '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
506 places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
507 $EGREP '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
508 for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
509 basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//' | \
510 sed -e 's/-PRE-GIT$//' `
511 if test $lastdir = $basedir ; then
512 dnl skip alphas when an actual release is present
513 continue;
514 fi
515 lastdir=$dir
516 if test -r $dir/libpcap.a ; then
517 libpcap=$dir/libpcap.a
518 local_pcap_dir=$dir
519 dnl continue and select the last one that exists
520 fi
521 done
522 if test $libpcap = FAIL ; then
523 #
524 # We didn't find a local libpcap.
525 #
526 AC_MSG_RESULT(not found)
527 using_local_libpcap=no;
528 else
529 #
530 # We found a local libpcap.
531 #
532 AC_MSG_RESULT($libpcap)
533 using_local_libpcap=yes
534 fi
535 ;;
536 esac
537
538 if test $using_local_libpcap = no ; then
539 #
540 # We didn't find a local libpcap.
541 # Look for an installed pkg-config.
542 #
543 if test -n "$PKG_CONFIG" ; then
544 #
545 # We have it. Are there .pc files for libpcap?
546 #
547 # --exists was introduced in pkg-config 0.4.0; that
548 # dates back to late 2000, so we won't worry about
549 # earlier releases that lack it.
550 #
551 AC_MSG_CHECKING(whether there are .pc files for libpcap)
552 if "$PKG_CONFIG" libpcap --exists ; then
553 #
554 # Yes, so we can use pkg-config to get configuration
555 # information for libpcap.
556 #
557 AC_MSG_RESULT(yes)
558 pkg_config_usable=yes
559 else
560 #
561 # No, so we can't use pkg-config to get configuration
562 # information for libpcap.
563 #
564 AC_MSG_RESULT(no)
565 pkg_config_usable=no
566 fi
567 else
568 #
569 # We don't have it, so we obviously can't use it.
570 #
571 pkg_config_usable=no
572 fi
573 if test "$pkg_config_usable" = "yes" ; then
574 #
575 # Found both - use pkg-config to get the include flags for
576 # libpcap and the flags to link with libpcap.
577 #
578 # Please read section 11.6 "Shell Substitutions"
579 # in the autoconf manual before doing anything
580 # to this that involves quoting. Especially note
581 # the statement "There is just no portable way to use
582 # double-quoted strings inside double-quoted back-quoted
583 # expressions (pfew!)."
584 #
585 cflags=`"$PKG_CONFIG" libpcap --cflags`
586 $2="$cflags $$2"
587 libpcap=`"$PKG_CONFIG" libpcap --libs`
588 else
589 #
590 # No pkg-config
591 # Look for an installed pcap-config.
592 #
593 AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
594 if test -n "$PCAP_CONFIG" ; then
595 #
596 # Found - use it to get the include flags for
597 # libpcap and the flags to link with libpcap.
598 #
599 # If this is a vendor-supplied pcap-config, which
600 # we define as being "a pcap-config in /usr/bin
601 # or /usr/ccs/bin" (the latter is for Solaris and
602 # Sun/Oracle Studio), there are some issues. Work
603 # around them.
604 #
605 if test \( "$PCAP_CONFIG" = "/usr/bin/pcap-config" \) -o \
606 \( "$PCAP_CONFIG" = "/usr/ccs/bin/pcap-config" \) ; then
607 #
608 # It's vendor-supplied.
609 #
610 case "$host_os" in
611
612 darwin*)
613 #
614 # This is macOS or another Darwin-based OS.
615 #
616 # That means that /usr/bin/pcap-config it
617 # may provide -I/usr/local/include with --cflags
618 # and -L/usr/local/lib with --libs, rather than
619 # pointing to the OS-supplied library and
620 # Xcode-supplied headers. Remember that, so we
621 # ignore those values.
622 #
623 _broken_apple_pcap_config=yes
624
625 #
626 # Furthermore:
627 #
628 # macOS Sonoma's libpcap includes stub versions
629 # of the remote-capture APIs. They are exported
630 # as "weakly linked symbols".
631 #
632 # Xcode 15 offers only a macOS Sonoma SDK, which
633 # has a .tbd file for libpcap that claims it
634 # includes those APIs. (Newer versions of macOS
635 # don't provide the system shared libraries,
636 # they only provide the dyld shared cache
637 # containing those libraries, so the OS provides
638 # SDKs that include a .tbd file to use when
639 # linking.)
640 #
641 # This means that AC_CHECK_FUNCS() will think
642 # that the remote-capture APIs are present,
643 # including pcap_open() and
644 # pcap_findalldevs_ex().
645 #
646 # However, they are *not* present in macOS
647 # Ventura and earlier, which means that building
648 # on Ventura with Xcode 15 produces executables
649 # that fail to start because one of those APIs
650 # isn't found in the system libpcap.
651 #
652 # Protecting calls to those APIs with
653 # __builtin_available() does not appear to
654 # prevent this, for some unknown reason, and it
655 # doesn't even allow the program to compile with
656 # versions of Xcode prior to Xcode 15, as the
657 # pcap.h file doesn't specify minimum OS
658 # versions for those functions.
659 #
660 # Given all that, and given that the versions of
661 # the remote-capture APIs in Sonoma are stubs
662 # that always fail, there doesn't seem to be any
663 # point in checking for pcap_open() if we're
664 # linking against the Apple libpcap.
665 #
666 # However, if we're *not* linking against the
667 # Apple libpcap, we should check for it, so that
668 # we can use it if it's present.
669 #
670 # We know this is macOS and that we're using
671 # the system-provided pcap-config to find
672 # libpcap, so we know it'll be the system
673 # libpcap, and note that we should not search
674 # for remote-capture APIs.
675 #
676 _dont_check_for_remote_apis=yes
677 ;;
678
679 solaris*)
680 #
681 # This is Solaris 2 or later, i.e. SunOS 5.x.
682 #
683 # At least on Solaris 11; there's /usr/bin/pcap-config,
684 # which reports -L/usr/lib with --libs, causing
685 # the 32-bit libraries to be found, and there's
686 # /usr/bin/{64bitarch}/pcap-config, where {64bitarch}
687 # is a name for the 64-bit version of the instruction
688 # set, which reports -L /usr/lib/{64bitarch}, causing
689 # the 64-bit libraries to be found.
690 #
691 # So if we're building 64-bit targets, we replace
692 # PCAP_CONFIG with /usr/bin/{64bitarch}; we get
693 # {64bitarch} as the output of "isainfo -n".
694 #
695 # Are we building 32-bit or 64-bit? Get the
696 # size of void *, and check that.
697 #
698 AC_CHECK_SIZEOF([void *])
699 if test ac_cv_sizeof_void_p -eq 8 ; then
700 isainfo_output=`isainfo -n`
701 if test ! -z "$isainfo_output" ; then
702 #
703 # Success - change PCAP_CONFIG.
704 #
705 PCAP_CONFIG=`echo $PCAP_CONFIG | sed "s;/bin/;/bin/$isainfo_output/;"`
706 fi
707 fi
708 ;;
709 esac
710 fi
711 #
712 # Please read section 11.6 "Shell Substitutions"
713 # in the autoconf manual before doing anything
714 # to this that involves quoting. Especially note
715 # the statement "There is just no portable way to use
716 # double-quoted strings inside double-quoted back-quoted
717 # expressions (pfew!)."
718 #
719 cflags=`"$PCAP_CONFIG" --cflags`
720 #
721 # Work around macOS (and probably other Darwin) brokenness,
722 # by not adding /usr/local/include if it's from the broken
723 # Apple pcap-config.
724 #
725 if test "$_broken_apple_pcap_config" = "yes" ; then
726 #
727 # Strip -I/usr/local/include with sed.
728 #
729 cflags=`echo $cflags | sed 's;-I/usr/local/include;;'`
730 fi
731 $2="$cflags $$2"
732 libpcap=`"$PCAP_CONFIG" --libs`
733 #
734 # Work around macOS (and probably other Darwin) brokenness,
735 # by not adding /usr/local/lib if it's from the broken
736 # Apple pcap-config.
737 #
738 if test "$_broken_apple_pcap_config" = "yes" ; then
739 #
740 # Strip -L/usr/local/lib with sed.
741 #
742 libpcap=`echo $libpcap | sed 's;-L/usr/local/lib;;'`
743 fi
744 else
745 #
746 # Not found; look for an installed pcap.
747 #
748 AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
749 if test $libpcap = FAIL ; then
750 AC_MSG_ERROR(see the INSTALL.md file for more info)
751 fi
752 dnl
753 dnl Some versions of Red Hat Linux put "pcap.h" in
754 dnl "/usr/include/pcap"; had the LBL folks done so,
755 dnl that would have been a good idea, but for
756 dnl the Red Hat folks to do so just breaks source
757 dnl compatibility with other systems.
758 dnl
759 dnl We work around this by assuming that, as we didn't
760 dnl find a local libpcap, libpcap is in /usr/lib or
761 dnl /usr/local/lib and that the corresponding header
762 dnl file is under one of those directories; if we don't
763 dnl find it in either of those directories, we check to
764 dnl see if it's in a "pcap" subdirectory of them and,
765 dnl if so, add that subdirectory to the "-I" list.
766 dnl
767 dnl (We now also put pcap.h in /usr/include/pcap, but we
768 dnl leave behind a /usr/include/pcap.h that includes it,
769 dnl so you can still just include <pcap.h>.)
770 dnl
771 AC_MSG_CHECKING(for extraneous pcap header directories)
772 if test \( ! -r /usr/local/include/pcap.h \) -a \
773 \( ! -r /usr/include/pcap.h \); then
774 if test -r /usr/local/include/pcap/pcap.h; then
775 d="/usr/local/include/pcap"
776 elif test -r /usr/include/pcap/pcap.h; then
777 d="/usr/include/pcap"
778 fi
779 fi
780 if test -z "$d" ; then
781 AC_MSG_RESULT(not found)
782 else
783 $2="-I$d $$2"
784 AC_MSG_RESULT(found -- -I$d added)
785 fi
786 fi
787 fi
788 else
789 #
790 # We found a local libpcap. Add it to the dependencies for
791 # tcpdump.
792 #
793 $1=$libpcap
794
795 #
796 # Look for its pcap-config script.
797 #
798 AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $local_pcap_dir)
799
800 if test -n "$PCAP_CONFIG"; then
801 #
802 # We don't want its --cflags or --libs output, because
803 # those presume it's installed. For the C compiler flags,
804 # we add the source directory for the local libpcap, so
805 # we pick up its header files.
806 #
807 # We do, however, want its additional libraries, as required
808 # when linking statically, because it makes calls to
809 # routines in those libraries, so we'll need to link with
810 # them, because we'll be linking statically with it.
811 #
812 # If it supports --static-pcap-only. use that, as we will be
813 # linking with a static libpcap but won't be linking
814 # statically with any of the libraries on which it depends;
815 # those libraries might not even have static versions
816 # installed.
817 #
818 # That means we need to find out the libraries on which
819 # libpcap directly depends, so we can link with them, but we
820 # don't need to link with the libraries on which those
821 # libraries depend as, on all UN*Xes with which I'm
822 # familiar, the libraries on which a shared library depends
823 # are stored in the library and are automatically loaded by
824 # the run-time linker, without the executable having to be
825 # linked with those libraries. (This allows a library to be
826 # changed to depend on more libraries without breaking that
827 # library's ABI.)
828 #
829 # The only way to test for that support is to see if the
830 # script contains the string "static-pcap-only"; we can't
831 # try using that flag and checking for errors, as the
832 # versions of the script that didn't have that flag wouldn't
833 # report or return an error for an unsupported command-line
834 # flag. Those older versions provided, with --static, only
835 # the libraries on which libpcap depends, not the
836 # dependencies of those libraries; the versions with
837 # --static-pcap-only provide all the dependencies with
838 # --static, for the benefit of programs that are completely
839 # statically linked, and provide only the direct
840 # dependencies with --static-pcap-only.
841 #
842 if grep "static-pcap-only" "$PCAP_CONFIG" >/dev/null 2>&1
843 then
844 static_opt="--static-pcap-only"
845 else
846 static_opt="--static"
847 fi
848 $2="-I$local_pcap_dir $$2"
849 additional_libs=`"$PCAP_CONFIG" $static_opt --additional-libs`
850 libpcap="$libpcap $additional_libs"
851 else
852 #
853 # It doesn't have a pcap-config script.
854 # Make sure it has a pcap.h file.
855 #
856 places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
857 $EGREP '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
858 places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
859 $EGREP '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
860 pcapH=FAIL
861 if test -r $local_pcap_dir/pcap.h; then
862 pcapH=$local_pcap_dir
863 else
864 for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
865 if test -r $dir/pcap.h ; then
866 pcapH=$dir
867 fi
868 done
869 fi
870
871 if test $pcapH = FAIL ; then
872 AC_MSG_ERROR(cannot find pcap.h: see the INSTALL.md file)
873 fi
874
875 #
876 # Force the compiler to look for header files in the
877 # directory containing pcap.h.
878 #
879 $2="-I$pcapH $$2"
880 fi
881 fi
882
883 if test -z "$PKG_CONFIG" -a -z "$PCAP_CONFIG"; then
884 #
885 # We don't have pkg-config or pcap-config; find out any additional
886 # link flags we need. (If we have pkg-config or pcap-config, we
887 # assume it tells us what we need.)
888 #
889 case "$host_os" in
890
891 aix*)
892 #
893 # If libpcap is DLPI-based, we have to use /lib/pse.exp if
894 # present, as we use the STREAMS routines.
895 #
896 # (XXX - true only if we're linking with a static libpcap?)
897 #
898 pseexe="/lib/pse.exp"
899 AC_MSG_CHECKING(for $pseexe)
900 if test -f $pseexe ; then
901 AC_MSG_RESULT(yes)
902 LIBS="$LIBS -I:$pseexe"
903 fi
904
905 #
906 # If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
907 # we use them to load the BPF module.
908 #
909 # (XXX - true only if we're linking with a static libpcap?)
910 #
911 LIBS="$LIBS -lodm -lcfg"
912 ;;
913
914 solaris*)
915 # libdlpi is needed for Solaris 11 and later.
916 AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
917 ;;
918 esac
919 fi
920
921 LIBS="$libpcap $LIBS"
922
923 dnl
924 dnl Check for "pcap_loop()", to make sure we found a working
925 dnl libpcap and have all the right other libraries with which
926 dnl to link. (Otherwise, the checks below will fail, not
927 dnl because the routines are missing from the library, but
928 dnl because we aren't linking properly with libpcap, and
929 dnl that will cause confusing errors at build time.)
930 dnl
931 AC_CHECK_FUNC(pcap_loop,,
932 [
933 AC_MSG_ERROR(
934 [
935 1. Do you try to build a 32-bit tcpdump with a 64-bit libpcap or vice versa?
936 2. This is a bug, please follow the guidelines in CONTRIBUTING.md and include
937 the config.log file in your report. If you have downloaded libpcap from
938 tcpdump.org, and built it yourself, please also include the config.log
939 file from the libpcap source directory, the Makefile from the libpcap
940 source directory, and the output of the make process for libpcap, as
941 this could be a problem with the libpcap that was built, and we will
942 not be able to determine why this is happening, and thus will not be
943 able to fix it, without that information, as we have not been able to
944 reproduce this problem ourselves.])
945 ])
946 ])
947
948 dnl
949 dnl Check whether a given format can be used to print 64-bit integers
950 dnl
951 AC_DEFUN(AC_LBL_CHECK_64BIT_FORMAT,
952 [
953 AC_MSG_CHECKING([whether %$1x can be used to format 64-bit integers])
954 AC_RUN_IFELSE(
955 [
956 AC_LANG_SOURCE(
957 [[
958 # ifdef HAVE_INTTYPES_H
959 #include <inttypes.h>
960 # endif
961 #include <stdio.h>
962 #include <sys/types.h>
963
964 main()
965 {
966 uint64_t t = 1;
967 char strbuf[16+1];
968 sprintf(strbuf, "%016$1x", t << 32);
969 if (strcmp(strbuf, "0000000100000000") == 0)
970 exit(0);
971 else
972 exit(1);
973 }
974 ]])
975 ],
976 [
977 AC_DEFINE(PRId64, "$1d", [define if the platform doesn't define PRId64])
978 AC_DEFINE(PRIo64, "$1o", [define if the platform doesn't define PRIo64])
979 AC_DEFINE(PRIx64, "$1x", [define if the platform doesn't define PRIu64])
980 AC_DEFINE(PRIu64, "$1u", [define if the platform doesn't define PRIx64])
981 AC_MSG_RESULT(yes)
982 ],
983 [
984 AC_MSG_RESULT(no)
985 $2
986 ])
987 ])
988
989 dnl
990 dnl If the file .devel exists:
991 dnl Add some warning flags if the compiler supports them
992 dnl If an os prototype include exists, symlink os-proto.h to it
993 dnl
994 dnl usage:
995 dnl
996 dnl AC_LBL_DEVEL(copt)
997 dnl
998 dnl results:
999 dnl
1000 dnl $1 (copt appended)
1001 dnl HAVE_OS_PROTO_H (defined)
1002 dnl os-proto.h (symlinked)
1003 dnl
1004 AC_DEFUN(AC_LBL_DEVEL,
1005 [rm -f os-proto.h
1006 if test "${LBL_CFLAGS+set}" = set; then
1007 $1="$$1 ${LBL_CFLAGS}"
1008 fi
1009 if test -f .devel ; then
1010 #
1011 # Skip all the warning option stuff on some compilers.
1012 #
1013 if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
1014 AC_LBL_CHECK_COMPILER_OPT($1, -W)
1015 AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
1016 AC_LBL_CHECK_COMPILER_OPT($1, -Wassign-enum)
1017 AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual)
1018 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
1019 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
1020 AC_LBL_CHECK_COMPILER_OPT($1, -Wnull-pointer-subtraction)
1021 AC_LBL_CHECK_COMPILER_OPT($1, -Wold-style-definition)
1022 AC_LBL_CHECK_COMPILER_OPT($1, -Wpedantic)
1023 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
1024 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
1025 AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
1026 AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
1027 AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
1028 AC_LBL_CHECK_COMPILER_OPT($1, -Wundef)
1029 AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code-return)
1030 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-parameter)
1031 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-variable)
1032 AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
1033 AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings)
1034 fi
1035 AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
1036 #
1037 # We used to set -n32 for IRIX 6 when not using GCC (presumed
1038 # to mean that we're using MIPS C or MIPSpro C); it specified
1039 # the "new" faster 32-bit ABI, introduced in IRIX 6.2. I'm
1040 # not sure why that would be something to do *only* with a
1041 # .devel file; why should the ABI for which we produce code
1042 # depend on .devel?
1043 #
1044 os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
1045 name="lbl/os-$os.h"
1046 if test -f $name ; then
1047 ln -s $name os-proto.h
1048 AC_DEFINE(HAVE_OS_PROTO_H, 1,
1049 [if there's an os_proto.h for this platform, to use additional prototypes])
1050 else
1051 AC_MSG_WARN(can't find $name)
1052 fi
1053 fi])
1054
1055 dnl
1056 dnl Improved version of AC_CHECK_LIB
1057 dnl
1058 dnl Thanks to John Hawkinson (jhawk@mit.edu)
1059 dnl
1060 dnl usage:
1061 dnl
1062 dnl AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
1063 dnl ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
1064 dnl
1065 dnl results:
1066 dnl
1067 dnl LIBS
1068 dnl
1069 dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
1070 dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
1071 dnl We keep it around for reference purposes in case it's ever
1072 dnl useful in the future.
1073 dnl
1074
1075 define(AC_LBL_CHECK_LIB,
1076 [AC_MSG_CHECKING([for $2 in -l$1])
1077 dnl Use a cache variable name containing the library, function
1078 dnl name, and extra libraries to link with, because the test really is
1079 dnl for library $1 defining function $2, when linked with potinal
1080 dnl library $5, not just for library $1. Separate tests with the same
1081 dnl $1 and different $2's or $5's may have different results.
1082 ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
1083 AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
1084 [ac_save_LIBS="$LIBS"
1085 LIBS="-l$1 $5 $LIBS"
1086 AC_TRY_LINK(dnl
1087 ifelse([$2], [main], , dnl Avoid conflicting decl of main.
1088 [/* Override any gcc2 internal prototype to avoid an error. */
1089 ]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
1090 extern "C"
1091 #endif
1092 ])dnl
1093 [/* We use char because int might match the return type of a gcc2
1094 builtin and then its argument prototype would still apply. */
1095 char $2();
1096 ]),
1097 [$2()],
1098 eval "ac_cv_lbl_lib_$ac_lib_var=yes",
1099 eval "ac_cv_lbl_lib_$ac_lib_var=no")
1100 LIBS="$ac_save_LIBS"
1101 ])dnl
1102 if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
1103 AC_MSG_RESULT(yes)
1104 ifelse([$3], ,
1105 [changequote(, )dnl
1106 ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
1107 -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1108 changequote([, ])dnl
1109 AC_DEFINE_UNQUOTED($ac_tr_lib)
1110 LIBS="-l$1 $LIBS"
1111 ], [$3])
1112 else
1113 AC_MSG_RESULT(no)
1114 ifelse([$4], , , [$4
1115 ])dnl
1116 fi
1117 ])
1118
1119 dnl
1120 dnl AC_LBL_LIBRARY_NET
1121 dnl
1122 dnl This test is for network applications that need socket() and
1123 dnl gethostbyaddr() -ish functions. Under Solaris, those applications
1124 dnl need to link with "-lsocket -lnsl". Under IRIX, they need to link
1125 dnl with "-lnsl" but should *not* link with "-lsocket" because
1126 dnl libsocket.a breaks a number of things (for instance:
1127 dnl gethostbyaddr() under IRIX 5.2, and snoop sockets under most
1128 dnl versions of IRIX).
1129 dnl
1130 dnl Unfortunately, many application developers are not aware of this,
1131 dnl and mistakenly write tests that cause -lsocket to be used under
1132 dnl IRIX. It is also easy to write tests that cause -lnsl to be used
1133 dnl under operating systems where neither are necessary (or useful),
1134 dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
1135 dnl
1136 dnl This test exists so that every application developer does not test
1137 dnl this in a different, and subtly broken fashion.
1138
1139 dnl It has been argued that this test should be broken up into two
1140 dnl separate tests, one for the resolver libraries, and one for the
1141 dnl libraries necessary for using Sockets API. Unfortunately, the two
1142 dnl are carefully intertwined and allowing the autoconf user to use
1143 dnl them independently potentially results in unfortunate ordering
1144 dnl dependencies -- as such, such component macros would have to
1145 dnl carefully use indirection and be aware if the other components were
1146 dnl executed. Since other autoconf macros do not go to this trouble,
1147 dnl and almost no applications use sockets without the resolver, this
1148 dnl complexity has not been implemented.
1149 dnl
1150 dnl The check for libresolv is in case you are attempting to link
1151 dnl statically and happen to have a libresolv.a lying around (and no
1152 dnl libnsl.a).
1153 dnl
1154 AC_DEFUN(AC_LBL_LIBRARY_NET, [
1155 # Most operating systems have gethostbyaddr() in the default searched
1156 # libraries (i.e. libc):
1157 # Some OSes (eg. Solaris) place it in libnsl
1158 # Some strange OSes (SINIX) have it in libsocket:
1159 AC_SEARCH_LIBS(gethostbyaddr, network nsl socket resolv)
1160 # Unfortunately libsocket sometimes depends on libnsl and
1161 # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
1162 if test "$ac_cv_search_gethostbyaddr" = "no"
1163 then
1164 AC_CHECK_LIB(socket, gethostbyaddr,
1165 LIBS="-lsocket -lnsl $LIBS", , -lnsl)
1166 fi
1167 AC_SEARCH_LIBS(socket, socket, ,
1168 AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
1169 # DLPI needs putmsg under HPUX so test for -lstr while we're at it
1170 AC_SEARCH_LIBS(putmsg, str)
1171 ])
1172
1173 dnl Copyright (c) 1999 WIDE Project. All rights reserved.
1174 dnl
1175 dnl Redistribution and use in source and binary forms, with or without
1176 dnl modification, are permitted provided that the following conditions
1177 dnl are met:
1178 dnl 1. Redistributions of source code must retain the above copyright
1179 dnl notice, this list of conditions and the following disclaimer.
1180 dnl 2. Redistributions in binary form must reproduce the above copyright
1181 dnl notice, this list of conditions and the following disclaimer in the
1182 dnl documentation and/or other materials provided with the distribution.
1183 dnl 3. Neither the name of the project nor the names of its contributors
1184 dnl may be used to endorse or promote products derived from this software
1185 dnl without specific prior written permission.
1186 dnl
1187 dnl THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1188 dnl ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1189 dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1190 dnl ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
1191 dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1192 dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1193 dnl OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1194 dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1195 dnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1196 dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1197 dnl SUCH DAMAGE.
1198
1199 AC_DEFUN(AC_LBL_SSLEAY,
1200 [
1201 #
1202 # Find the last component of $libdir; it's not necessarily
1203 # "lib" - it might be "lib64" on, for example, x86-64
1204 # Linux systems.
1205 #
1206 # We assume the directory in which we're looking for
1207 # libcrypto has a subdirectory with that as its name.
1208 #
1209 tmplib=`echo "$libdir" | sed 's,.*/,,'`
1210
1211 #
1212 # XXX - is there a better way to check if a given library is
1213 # in a given directory than checking each of the possible
1214 # shared library suffixes?
1215 #
1216 # Are there any other suffixes we need to look for? Do we
1217 # have to worry about ".so.{version}"?
1218 #
1219 # Or should we just look for "libcrypto.*"?
1220 #
1221 if test -d "$1/$tmplib" -a \( -f "$1/$tmplib/libcrypto.a" -o \
1222 -f "$1/$tmplib/libcrypto.so" -o \
1223 -f "$1/$tmplib/libcrypto.sl" -o \
1224 -f "$1/$tmplib/libcrypto.dylib" \); then
1225 ac_cv_ssleay_path="$1"
1226 fi
1227
1228 #
1229 # Make sure we have the headers as well.
1230 #
1231 if test -d "$1/include/openssl" -a -f "$1/include/openssl/des.h"; then
1232 incdir="-I$1/include"
1233 fi
1234 ])
1235
1236 m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
1237 dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
1238 dnl serial 11 (pkg-config-0.29)
1239 dnl
1240 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
1241 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
1242 dnl
1243 dnl This program is free software; you can redistribute it and/or modify
1244 dnl it under the terms of the GNU General Public License as published by
1245 dnl the Free Software Foundation; either version 2 of the License, or
1246 dnl (at your option) any later version.
1247 dnl
1248 dnl This program is distributed in the hope that it will be useful, but
1249 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
1250 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1251 dnl General Public License for more details.
1252 dnl
1253 dnl You should have received a copy of the GNU General Public License
1254 dnl along with this program; if not, write to the Free Software
1255 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1256 dnl 02111-1307, USA.
1257 dnl
1258 dnl As a special exception to the GNU General Public License, if you
1259 dnl distribute this file as part of a program that contains a
1260 dnl configuration script generated by Autoconf, you may include it under
1261 dnl the same distribution terms that you use for the rest of that
1262 dnl program.
1263
1264 dnl PKG_PREREQ(MIN-VERSION)
1265 dnl -----------------------
1266 dnl Since: 0.29
1267 dnl
1268 dnl Verify that the version of the pkg-config macros are at least
1269 dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
1270 dnl installed version of pkg-config, this checks the developer's version
1271 dnl of pkg.m4 when generating configure.
1272 dnl
1273 dnl To ensure that this macro is defined, also add:
1274 dnl m4_ifndef([PKG_PREREQ],
1275 dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
1276 dnl
1277 dnl See the "Since" comment for each macro you use to see what version
1278 dnl of the macros you require.
1279 m4_defun([PKG_PREREQ],
1280 [m4_define([PKG_MACROS_VERSION], [0.29])
1281 m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
1282 [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
1283 ])dnl PKG_PREREQ
1284
1285 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
1286 dnl ----------------------------------
1287 dnl Since: 0.16
1288 dnl
1289 dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
1290 dnl first found in the path. Checks that the version of pkg-config found
1291 dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.17.0 is
1292 dnl used since that's the first version where --static was supported.
1293 AC_DEFUN([PKG_PROG_PKG_CONFIG],
1294 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
1295 m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
1296 m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
1297 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
1298 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
1299 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
1300
1301 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
1302 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
1303 fi
1304 if test -n "$PKG_CONFIG"; then
1305 _pkg_min_version=m4_default([$1], [0.17.0])
1306 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
1307 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
1308 AC_MSG_RESULT([yes])
1309 else
1310 AC_MSG_RESULT([no])
1311 PKG_CONFIG=""
1312 fi
1313 fi[]dnl
1314 ])dnl PKG_PROG_PKG_CONFIG
1315
1316 dnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1317 dnl -------------------------------------------------------------------
1318 dnl Since: 0.18
1319 dnl
1320 dnl Check to see whether a particular module exists. Similar to
1321 dnl PKG_CHECK_MODULE(), but does not set variables or print errors.
1322 AC_DEFUN([PKG_CHECK_EXISTS],
1323 [
1324 if test -n "$PKG_CONFIG" && \
1325 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
1326 m4_default([$2], [:])
1327 m4_ifvaln([$3], [else
1328 $3])dnl
1329 fi])
1330
1331 dnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
1332 dnl ---------------------------------------------
1333 dnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
1334 dnl pkg-config fails, reporting the error and quitting.
1335 m4_define([_PKG_CONFIG_WITH_FLAGS],
1336 [if test ! -n "$$1"; then
1337 $1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1338 if test "x$?" != "x0"; then
1339 #
1340 # That failed - report an error.
1341 # Re-run the command, telling pkg-config to print an error
1342 # message, capture the error message, and report it.
1343 # This causes the configuration script to fail, as it means
1344 # the script is almost certainly doing something wrong.
1345 #
1346 _PKG_SHORT_ERRORS_SUPPORTED
1347 if test $_pkg_short_errors_supported = yes; then
1348 _pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
1349 else
1350 _pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
1351 fi
1352 AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
1353 fi
1354 fi[]dnl
1355 ])dnl _PKG_CONFIG_WITH_FLAGS
1356
1357
1358 dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
1359 dnl ---------------------------------------------
1360 dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
1361 dnl pkg_failed based on the result.
1362 m4_define([_PKG_CONFIG],
1363 [if test -n "$$1"; then
1364 pkg_cv_[]$1="$$1"
1365 elif test -n "$PKG_CONFIG"; then
1366 PKG_CHECK_EXISTS([$3],
1367 [pkg_cv_[]$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
1368 test "x$?" != "x0" && pkg_failed=yes ],
1369 [pkg_failed=yes])
1370 else
1371 pkg_failed=untried
1372 fi[]dnl
1373 ])dnl _PKG_CONFIG
1374
1375 dnl _PKG_SHORT_ERRORS_SUPPORTED
1376 dnl ---------------------------
1377 dnl Internal check to see if pkg-config supports short errors.
1378 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
1379 [
1380 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
1381 _pkg_short_errors_supported=yes
1382 else
1383 _pkg_short_errors_supported=no
1384 fi[]dnl
1385 ])dnl _PKG_SHORT_ERRORS_SUPPORTED
1386
1387
1388 dnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1389 dnl [ACTION-IF-NOT-FOUND])
1390 dnl --------------------------------------------------------------
1391 dnl Since: 0.4.0
1392 AC_DEFUN([PKG_CHECK_MODULE],
1393 [
1394 AC_MSG_CHECKING([for $2 with pkg-config])
1395 if test -n "$PKG_CONFIG"; then
1396 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
1397 AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
1398 AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
1399
1400 if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
1401 #
1402 # The package was found, so try to get its C flags and
1403 # libraries.
1404 #
1405 AC_MSG_RESULT([found])
1406 _PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
1407 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
1408 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
1409 m4_default([$3], [:])
1410 else
1411 AC_MSG_RESULT([not found])
1412 m4_default([$4], [:])
1413 fi
1414 else
1415 # No pkg-config, so obviously not found with pkg-config.
1416 AC_MSG_RESULT([pkg-config not found])
1417 m4_default([$4], [:])
1418 fi
1419 ])dnl PKG_CHECK_MODULE
1420
1421
1422 dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
1423 dnl [ACTION-IF-NOT-FOUND])
1424 dnl ---------------------------------------------------------------------
1425 dnl Since: 0.29
1426 dnl
1427 dnl Checks for existence of MODULE and gathers its build flags with
1428 dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
1429 dnl and VARIABLE-PREFIX_LIBS from --libs.
1430 AC_DEFUN([PKG_CHECK_MODULE_STATIC],
1431 [
1432 _save_PKG_CONFIG=$PKG_CONFIG
1433 PKG_CONFIG="$PKG_CONFIG --static"
1434 PKG_CHECK_MODULE($@)
1435 PKG_CONFIG=$_save_PKG_CONFIG[]dnl
1436 ])dnl PKG_CHECK_MODULE_STATIC
1437
1438
1439 dnl PKG_INSTALLDIR([DIRECTORY])
1440 dnl -------------------------
1441 dnl Since: 0.27
1442 dnl
1443 dnl Substitutes the variable pkgconfigdir as the location where a module
1444 dnl should install pkg-config .pc files. By default the directory is
1445 dnl $libdir/pkgconfig, but the default can be changed by passing
1446 dnl DIRECTORY. The user can override through the --with-pkgconfigdir
1447 dnl parameter.
1448 AC_DEFUN([PKG_INSTALLDIR],
1449 [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
1450 m4_pushdef([pkg_description],
1451 [pkg-config installation directory @<:@]pkg_default[@:>@])
1452 AC_ARG_WITH([pkgconfigdir],
1453 [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
1454 [with_pkgconfigdir=]pkg_default)
1455 AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1456 m4_popdef([pkg_default])
1457 m4_popdef([pkg_description])
1458 ])dnl PKG_INSTALLDIR
1459
1460
1461 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1462 dnl --------------------------------
1463 dnl Since: 0.27
1464 dnl
1465 dnl Substitutes the variable noarch_pkgconfigdir as the location where a
1466 dnl module should install arch-independent pkg-config .pc files. By
1467 dnl default the directory is $datadir/pkgconfig, but the default can be
1468 dnl changed by passing DIRECTORY. The user can override through the
1469 dnl --with-noarch-pkgconfigdir parameter.
1470 AC_DEFUN([PKG_NOARCH_INSTALLDIR],
1471 [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1472 m4_pushdef([pkg_description],
1473 [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1474 AC_ARG_WITH([noarch-pkgconfigdir],
1475 [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1476 [with_noarch_pkgconfigdir=]pkg_default)
1477 AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1478 m4_popdef([pkg_default])
1479 m4_popdef([pkg_description])
1480 ])dnl PKG_NOARCH_INSTALLDIR
1481
1482
1483 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1484 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1485 dnl -------------------------------------------
1486 dnl Since: 0.28
1487 dnl
1488 dnl Retrieves the value of the pkg-config variable for the given module.
1489 AC_DEFUN([PKG_CHECK_VAR],
1490 [
1491 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1492
1493 _PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1494 AS_VAR_COPY([$1], [pkg_cv_][$1])
1495
1496 AS_VAR_IF([$1], [""], [$5], [$4])dnl
1497 ])dnl PKG_CHECK_VAR