]> The Tcpdump Group git mirrors - libpcap/blob - aclocal.m4
CI: Call print_so_deps() on rpcapd in remote enabled build
[libpcap] / 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 AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT])
86 if test "$GCC" = yes ; then
87 #
88 # -Werror forces warnings to be errors.
89 #
90 ac_lbl_cc_force_warning_errors=-Werror
91
92 #
93 # Try to have the compiler default to hiding symbols,
94 # so that only symbols explicitly exported with
95 # PCAP_API will be visible outside (shared) libraries.
96 #
97 AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
98 else
99 $2="$$2 -I/usr/local/include"
100 LDFLAGS="$LDFLAGS -L/usr/local/lib"
101
102 case "$host_os" in
103
104 darwin*)
105 #
106 # This is assumed either to be GCC or clang, both
107 # of which use -Werror to force warnings to be errors.
108 #
109 ac_lbl_cc_force_warning_errors=-Werror
110
111 #
112 # Try to have the compiler default to hiding symbols,
113 # so that only symbols explicitly exported with
114 # PCAP_API will be visible outside (shared) libraries.
115 #
116 AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
117 ;;
118
119 hpux*)
120 #
121 # HP C, which is what we presume we're using, doesn't
122 # exit with a non-zero exit status if we hand it an
123 # invalid -W flag, can't be forced to do so even with
124 # +We, and doesn't handle GCC-style -W flags, so we
125 # don't want to try using GCC-style -W flags.
126 #
127 ac_lbl_cc_dont_try_gcc_dashW=yes
128 ;;
129
130 solaris*)
131 #
132 # Assumed to be Sun C, which requires -errwarn to force
133 # warnings to be treated as errors.
134 #
135 ac_lbl_cc_force_warning_errors=-errwarn
136
137 #
138 # Try to have the compiler default to hiding symbols,
139 # so that only symbols explicitly exported with
140 # PCAP_API will be visible outside (shared) libraries.
141 #
142 AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden)
143 ;;
144 esac
145 $1="$$1 -O"
146 fi
147 ])
148
149 dnl
150 dnl Save the values of various variables that affect compilation and
151 dnl linking, and that we don't ourselves modify persistently; done
152 dnl before a test involving compiling or linking is done, so that we
153 dnl can restore those variables after the test is done.
154 dnl
155 AC_DEFUN(AC_LBL_SAVE_CHECK_STATE,
156 [
157 save_CFLAGS="$CFLAGS"
158 save_LIBS="$LIBS"
159 save_LDFLAGS="$LDFLAGS"
160 ])
161
162 dnl
163 dnl Restore the values of variables saved by AC_LBL_SAVE_CHECK_STATE.
164 dnl
165 AC_DEFUN(AC_LBL_RESTORE_CHECK_STATE,
166 [
167 CFLAGS="$save_CFLAGS"
168 LIBS="$save_LIBS"
169 LDFLAGS="$save_LDFLAGS"
170 ])
171
172 dnl
173 dnl Check whether the compiler option specified as the second argument
174 dnl is supported by the compiler and, if so, add it to the macro
175 dnl specified as the first argument
176 dnl
177 dnl If a third argument is supplied, treat it as C code to be compiled
178 dnl with the flag in question, and the "treat warnings as errors" flag
179 dnl set, and don't add the flag to the first argument if the compile
180 dnl fails; this is for warning options cause problems that can't be
181 dnl worked around. If a third argument is supplied, a fourth argument
182 dnl should also be supplied; it's a message describing what the test
183 dnl program is checking.
184 dnl
185 AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
186 [
187 AC_MSG_CHECKING([whether the compiler supports the $2 option])
188 save_CFLAGS="$CFLAGS"
189 CFLAGS="$CFLAGS $2"
190 #
191 # XXX - yes, this depends on the way AC_LANG_WERROR works,
192 # but no mechanism is provided to turn AC_LANG_WERROR on
193 # *and then turn it back off*, so that we *only* do it when
194 # testing compiler options - 15 years after somebody asked
195 # for it:
196 #
197 # https://autoconf.gnu.narkive.com/gTAVmfKD/how-to-cancel-flags-set-by-ac-lang-werror
198 #
199 save_ac_c_werror_flag="$ac_c_werror_flag"
200 ac_c_werror_flag=yes
201 #
202 # We use AC_LANG_SOURCE() so that we can control the complete
203 # content of the program being compiled. We do not, for example,
204 # want the default "int main()" that AC_LANG_PROGRAM() generates,
205 # as it will generate a warning with -Wold-style-definition, meaning
206 # that we would treat it as not working, as the test will fail if
207 # *any* error output, including a warning due to the flag we're
208 # testing, is generated; see
209 #
210 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
211 # https://www.postgresql.org/message-id/2192993.1591682589%40sss.pgh.pa.us
212 #
213 # This may, as per those two messages, be fixed in autoconf 2.70,
214 # but we only require 2.69 or newer for now.
215 #
216 AC_COMPILE_IFELSE(
217 [AC_LANG_SOURCE([[int main(void) { return 0; }]])],
218 [
219 AC_MSG_RESULT([yes])
220 can_add_to_cflags=yes
221 #
222 # The compile supports this; do we have some C code for
223 # which the warning should *not* appear?
224 # We test the fourth argument because the third argument
225 # could contain quotes, breaking the test.
226 #
227 if test "x$4" != "x"
228 then
229 CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
230 AC_MSG_CHECKING(whether $2 $4)
231 AC_COMPILE_IFELSE(
232 [AC_LANG_SOURCE($3)],
233 [
234 #
235 # Not a problem.
236 #
237 AC_MSG_RESULT(no)
238 ],
239 [
240 #
241 # A problem.
242 #
243 AC_MSG_RESULT(yes)
244 can_add_to_cflags=no
245 ])
246 fi
247 CFLAGS="$save_CFLAGS"
248 if test x"$can_add_to_cflags" = "xyes"
249 then
250 $1="$$1 $2"
251 fi
252 ],
253 [
254 AC_MSG_RESULT([no])
255 CFLAGS="$save_CFLAGS"
256 ])
257 ac_c_werror_flag="$save_ac_c_werror_flag"
258 ])
259
260 dnl
261 dnl Check whether the compiler supports an option to generate
262 dnl Makefile-style dependency lines
263 dnl
264 dnl GCC uses -M for this. Non-GCC compilers that support this
265 dnl use a variety of flags, including but not limited to -M.
266 dnl
267 dnl We test whether the flag in question is supported, as older
268 dnl versions of compilers might not support it.
269 dnl
270 dnl We don't try all the possible flags, just in case some flag means
271 dnl "generate dependencies" on one compiler but means something else
272 dnl on another compiler.
273 dnl
274 dnl Most compilers that support this send the output to the standard
275 dnl output by default. IBM's XLC, however, supports -M but sends
276 dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
277 dnl to work around that, so we don't bother with XLC.
278 dnl
279 AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
280 [
281 AC_MSG_CHECKING([whether the compiler supports generating dependencies])
282 if test "$GCC" = yes ; then
283 #
284 # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
285 # though it's not); we assume that, in this case, the flag
286 # would be -M.
287 #
288 ac_lbl_dependency_flag="-M"
289 else
290 #
291 # Not GCC or a compiler deemed to be GCC; what platform is
292 # this? (We're assuming that if the compiler isn't GCC
293 # it's the compiler from the vendor of the OS; that won't
294 # necessarily be true for x86 platforms, where it might be
295 # the Intel C compiler.)
296 #
297 case "$host_os" in
298
299 darwin*)
300 #
301 # Clang uses -M.
302 #
303 ac_lbl_dependency_flag="-M"
304 ;;
305
306 solaris*)
307 #
308 # Sun C uses -xM.
309 #
310 ac_lbl_dependency_flag="-xM"
311 ;;
312
313 hpux*)
314 #
315 # HP's older C compilers don't support this.
316 # HP's newer C compilers support this with
317 # either +M or +Make; the older compilers
318 # interpret +M as something completely
319 # different, so we use +Make so we don't
320 # think it works with the older compilers.
321 #
322 ac_lbl_dependency_flag="+Make"
323 ;;
324
325 *)
326 #
327 # Not one of the above; assume no support for
328 # generating dependencies.
329 #
330 ac_lbl_dependency_flag=""
331 ;;
332 esac
333 fi
334
335 #
336 # Is ac_lbl_dependency_flag defined and, if so, does the compiler
337 # complain about it?
338 #
339 # Note: clang doesn't seem to exit with an error status when handed
340 # an unknown non-warning error, even if you pass it
341 # -Werror=unknown-warning-option. However, it always supports
342 # -M, so the fact that this test always succeeds with clang
343 # isn't an issue.
344 #
345 if test ! -z "$ac_lbl_dependency_flag"; then
346 AC_LANG_CONFTEST(
347 [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
348 if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
349 AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
350 DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
351 MKDEP='${top_srcdir}/mkdep'
352 else
353 AC_MSG_RESULT([no])
354 #
355 # We can't run mkdep, so have "make depend" do
356 # nothing.
357 #
358 MKDEP='${top_srcdir}/nomkdep'
359 fi
360 rm -rf conftest*
361 else
362 AC_MSG_RESULT([no])
363 #
364 # We can't run mkdep, so have "make depend" do
365 # nothing.
366 #
367 MKDEP='${top_srcdir}/nomkdep'
368 fi
369 AC_SUBST(DEPENDENCY_CFLAG)
370 AC_SUBST(MKDEP)
371 ])
372
373 dnl
374 dnl Determine what options are needed to build a shared library
375 dnl
376 dnl usage:
377 dnl
378 dnl AC_LBL_SHLIBS_INIT
379 dnl
380 dnl results:
381 dnl
382 dnl V_SHLIB_CCOPT (modified to build position-independent code)
383 dnl V_SHLIB_CMD
384 dnl V_SHLIB_OPT
385 dnl V_SONAME_OPT
386 dnl
387 AC_DEFUN(AC_LBL_SHLIBS_INIT,
388 [AC_PREREQ(2.50)
389 if test "$GCC" = yes ; then
390 #
391 # On platforms where we build a shared library:
392 #
393 # add options to generate position-independent code,
394 # if necessary (it's the default in AIX and Darwin/macOS);
395 #
396 # define option to set the soname of the shared library,
397 # if the OS supports that;
398 #
399 # add options to specify, at link time, a directory to
400 # add to the run-time search path, if that's necessary.
401 #
402 V_SHLIB_CMD="\$(CC)"
403 V_SHLIB_OPT="-shared"
404 case "$host_os" in
405
406 aix*)
407 ;;
408
409 freebsd*|netbsd*|openbsd*|dragonfly*|linux*|haiku*|midipix*|gnu*)
410 #
411 # Platforms where the C compiler is GCC or accepts
412 # compatible command-line arguments, and the linker
413 # is the GNU linker or accepts compatible command-line
414 # arguments.
415 #
416 # Some instruction sets require -fPIC on some
417 # operating systems. Check for them. If you
418 # have a combination that requires it, add it
419 # here.
420 #
421 PIC_OPT=-fpic
422 case "$host_cpu" in
423
424 sparc64*)
425 case "$host_os" in
426
427 freebsd*|openbsd*|linux*)
428 PIC_OPT=-fPIC
429 ;;
430 esac
431 ;;
432 esac
433 V_SHLIB_CCOPT="$V_SHLIB_CCOPT $PIC_OPT"
434 V_SONAME_OPT="-Wl,-soname,"
435 ;;
436
437 hpux*)
438 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
439 #
440 # XXX - this assumes GCC is using the HP linker,
441 # rather than the GNU linker, and that the "+h"
442 # option is used on all HP-UX platforms, both .sl
443 # and .so.
444 #
445 V_SONAME_OPT="-Wl,+h,"
446 #
447 # By default, directories specified with -L
448 # are added to the run-time search path, so
449 # we don't add them in pcap-config.
450 #
451 ;;
452
453 solaris*)
454 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
455 #
456 # Sun/Oracle's C compiler, GCC, and GCC-compatible
457 # compilers support -Wl,{comma-separated list of options},
458 # and we use the C compiler, not ld, for all linking,
459 # including linking to produce a shared library.
460 #
461 V_SONAME_OPT="-Wl,-h,"
462 ;;
463 esac
464 else
465 #
466 # Set the appropriate compiler flags and, on platforms
467 # where we build a shared library:
468 #
469 # add options to generate position-independent code,
470 # if necessary (it's the default in Darwin/macOS);
471 #
472 # if we generate ".so" shared libraries, define the
473 # appropriate options for building the shared library;
474 #
475 # add options to specify, at link time, a directory to
476 # add to the run-time search path, if that's necessary.
477 #
478 # Note: spaces after V_SONAME_OPT are significant; on
479 # some platforms the soname is passed with a GCC-like
480 # "-Wl,-soname,{soname}" option, with the soname part
481 # of the option, while on other platforms the C compiler
482 # driver takes it as a regular option with the soname
483 # following the option.
484 #
485 case "$host_os" in
486
487 aix*)
488 V_SHLIB_CMD="\$(CC)"
489 V_SHLIB_OPT="-G -bnoentry -bexpall"
490 ;;
491
492 freebsd*|netbsd*|openbsd*|dragonfly*|linux*)
493 #
494 # Platforms where the C compiler is GCC or accepts
495 # compatible command-line arguments, and the linker
496 # is the GNU linker or accepts compatible command-line
497 # arguments.
498 #
499 # XXX - does 64-bit SPARC require -fPIC?
500 #
501 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
502 V_SHLIB_CMD="\$(CC)"
503 V_SHLIB_OPT="-shared"
504 V_SONAME_OPT="-Wl,-soname,"
505 ;;
506
507 hpux*)
508 V_SHLIB_CCOPT="$V_SHLIB_CCOPT +z"
509 V_SHLIB_CMD="\$(LD)"
510 V_SHLIB_OPT="-b"
511 V_SONAME_OPT="+h "
512 #
513 # By default, directories specified with -L
514 # are added to the run-time search path, so
515 # we don't add them in pcap-config.
516 #
517 ;;
518
519 solaris*)
520 V_SHLIB_CCOPT="$V_SHLIB_CCOPT -Kpic"
521 V_SHLIB_CMD="\$(CC)"
522 V_SHLIB_OPT="-G"
523 #
524 # Sun/Oracle's C compiler, GCC, and GCC-compatible
525 # compilers support -Wl,{comma-separated list of options},
526 # and we use the C compiler, not ld, for all linking,
527 # including linking to produce a shared library.
528 #
529 V_SONAME_OPT="-Wl,-h,"
530 ;;
531 esac
532 fi
533 ])
534
535 #
536 # Test whether we have __atomic_load_n() and __atomic_store_n().
537 #
538 # We use AC_LINK_IFELSE because AC_TRY_COMPILE will succeed, as the
539 # compiler will just think that those functions are undefined,
540 # and perhaps warn about that, but not fail to compile.
541 #
542 AC_DEFUN(AC_PCAP_C___ATOMICS,
543 [
544 AC_MSG_CHECKING(for __atomic_load_n)
545 AC_CACHE_VAL(ac_cv_have___atomic_load_n,
546 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
547 [[
548 int i = 17;
549 int j;
550 j = __atomic_load_n(&i, __ATOMIC_RELAXED);
551 ]])],
552 [ac_have___atomic_load_n=yes],
553 [ac_have___atomic_load_n=no]))
554 AC_MSG_RESULT($ac_have___atomic_load_n)
555 if test $ac_have___atomic_load_n = yes ; then
556 AC_DEFINE(HAVE___ATOMIC_LOAD_N, 1,
557 [define if __atomic_load_n is supported by the compiler])
558 fi
559
560 AC_MSG_CHECKING(for __atomic_store_n)
561 AC_CACHE_VAL(ac_cv_have___atomic_store_n,
562 AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
563 [[
564 int i;
565 __atomic_store_n(&i, 17, __ATOMIC_RELAXED);
566 ]])],
567 [ac_have___atomic_store_n=yes],
568 [ac_have___atomic_store_n=no]))
569 AC_MSG_RESULT($ac_have___atomic_store_n)
570 if test $ac_have___atomic_store_n = yes ; then
571 AC_DEFINE(HAVE___ATOMIC_STORE_N, 1,
572 [define if __atomic_store_n is supported by the compiler])
573 fi])
574
575 dnl
576 dnl If the file .devel exists:
577 dnl Add some warning flags if the compiler supports them
578 dnl If an os prototype include exists, symlink os-proto.h to it
579 dnl
580 dnl usage:
581 dnl
582 dnl AC_LBL_DEVEL(copt)
583 dnl
584 dnl results:
585 dnl
586 dnl $1 (copt appended)
587 dnl HAVE_OS_PROTO_H (defined)
588 dnl os-proto.h (symlinked)
589 dnl
590 AC_DEFUN(AC_LBL_DEVEL,
591 [rm -f os-proto.h
592 if test "${LBL_CFLAGS+set}" = set; then
593 $1="$$1 ${LBL_CFLAGS}"
594 fi
595 if test -f .devel ; then
596 #
597 # Skip all the warning option stuff on some compilers.
598 #
599 if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
600 AC_LBL_CHECK_COMPILER_OPT($1, -W)
601 AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
602 AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma)
603 # Warns about safeguards added in case the enums are
604 # extended
605 # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
606 AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation)
607 AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral)
608 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn)
609 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
610 AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
611 AC_LBL_CHECK_COMPILER_OPT($1, -Wnull-pointer-subtraction)
612 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
613 AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
614 AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
615 AC_LBL_CHECK_COMPILER_OPT($1, -Wshorten-64-to-32)
616 AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
617 AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
618 AC_LBL_CHECK_COMPILER_OPT($1, -Wundef)
619 #
620 # This can cause problems with ntohs(), ntohl(),
621 # htons(), and htonl() on some platforms, such
622 # as OpenBSD 6.3 with Clang 5.0.1. I guess the
623 # problem is that the macro that ultimately does
624 # the byte-swapping involves a conditional
625 # expression that tests whether the value being
626 # swapped is a compile-time constant or not,
627 # using __builtin_constant_p(), and, depending
628 # on whether it is, does a compile-time swap or
629 # a run-time swap; perhaps the compiler always
630 # considers one of the two results of the
631 # conditional expression is never evaluated,
632 # because the conditional check is done at
633 # compile time, and thus always says "that
634 # expression is never executed".
635 #
636 # (Perhaps there should be a way of flagging
637 # an expression that you *want* evaluated at
638 # compile time, so that the compiler 1) warns
639 # if it *can't* be evaluated at compile time
640 # and 2) *doesn't* warn that the true or false
641 # branch will never be reached.)
642 #
643 AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code,
644 [
645 #include <arpa/inet.h>
646
647 unsigned short
648 testme(unsigned short a)
649 {
650 return ntohs(a);
651 }
652 ],
653 [generates warnings from ntohs()])
654 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-parameter)
655 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-but-set-variable)
656 AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
657 AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
658 fi
659 AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
660 AC_MSG_CHECKING([whether to use an os-proto.h header])
661 os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
662 name="lbl/os-$os.h"
663 if test -f $name ; then
664 AC_MSG_RESULT([yes, at "$name"])
665 ln -s $name os-proto.h
666 AC_DEFINE(HAVE_OS_PROTO_H, 1,
667 [if there's an os-proto.h for this platform, to use additional prototypes])
668 else
669 AC_MSG_RESULT([no])
670 fi
671 fi])
672
673 dnl
674 dnl AC_LBL_LIBRARY_NET
675 dnl
676 dnl Look for various networking-related libraries that we may need.
677 dnl
678 dnl We need getaddrinfo() to translate host names in filters to IP
679 dnl addresses. We use getaddrinfo() because we want a portable
680 dnl thread-safe way of getting information for a host name or port;
681 dnl there exist _r versions of gethostbyname() and getservbyname() on
682 dnl some platforms, but not on all platforms.
683 dnl
684 dnl We may also need socket() and other socket functions to support:
685 dnl
686 dnl Local packet capture with capture mechanisms that use sockets.
687 dnl
688 dnl Local capture device enumeration if a socket call is needed to
689 dnl enumerate devices or get device attributes.
690 dnl
691 dnl Packet capture from services that put captured packets on the
692 dnl network, such as rpcap servers.
693 dnl
694 dnl We may also need getnameinfo() for packet capture from services
695 dnl that put packets on the network.
696 dnl
697 AC_DEFUN(AC_LBL_LIBRARY_NET, [
698 #
699 # Most operating systems have getaddrinfo(), and the other routines
700 # we may need, in the default searched libraries (e.g., libc).
701 #
702 # These are: AIX, FreeBSD, Linux, macOS, NetBSD, OpenBSD, Solaris
703 # since 11.4.
704 #
705 # Check there first.
706 #
707 AC_CHECK_FUNC(getaddrinfo,,
708 [
709 #
710 # Not found in the standard system libraries.
711 #
712 # In some versions of Solaris, we need to link with libsocket
713 # and libnsl, so check in libsocket and also link with libnsl
714 # when doing this test.
715 #
716 # These are: illumos, Solaris 9.x, 10.x, 11.x before 11.4.
717 #
718 # Linking with libsocket and libnsl will find all the routines
719 # we need.
720 #
721 AC_CHECK_LIB(socket, getaddrinfo,
722 [
723 #
724 # OK, we found it in libsocket.
725 #
726 LIBS="-lsocket -lnsl $LIBS"
727 ],
728 [
729 #
730 # Not found in libsocket; test for it in libnetwork, which
731 # is where it is in Haiku.
732 #
733 # Linking with libnetwork will find all the routines we
734 # need.
735 #
736 AC_CHECK_LIB(network, getaddrinfo,
737 [
738 #
739 # OK, we found it in libnetwork.
740 #
741 LIBS="-lnetwork $LIBS"
742 ],
743 [
744 #
745 # We didn't find it.
746 #
747 AC_MSG_ERROR([getaddrinfo is required, but wasn't found])
748 ])
749 ], -lnsl)
750
751 #
752 # We require a version of recvmsg() that conforms to the Single
753 # UNIX Specification, so that we can check whether a datagram
754 # received with recvmsg() was truncated when received due to the
755 # buffer being too small.
756 #
757 # On most systems, the version of recvmsg() in the libraries
758 # found above conforms to the SUS.
759 #
760 # On at least some versions of Solaris, it does not conform to
761 # the SUS, and we need the version in libxnet, which does
762 # conform.
763 #
764 # Check whether libxnet exists and has a version of recvmsg();
765 # if it does, link with libxnet before we link with libsocket,
766 # to get that version.
767 #
768 # This test also links with libsocket and libnsl.
769 #
770 AC_CHECK_LIB(xnet, recvmsg,
771 [
772 #
773 # libxnet has recvmsg(); link with it as well.
774 #
775 LIBS="-lxnet $LIBS"
776 ], , -lsocket -lnsl)
777 ])
778 ])
779
780 m4_ifndef([AC_CONFIG_MACRO_DIRS], [m4_defun([_AM_CONFIG_MACRO_DIRS], [])m4_defun([AC_CONFIG_MACRO_DIRS], [_AM_CONFIG_MACRO_DIRS($@)])])
781 dnl pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
782 dnl serial 11 (pkg-config-0.29)
783 dnl
784 dnl Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
785 dnl Copyright © 2012-2015 Dan Nicholson <dbn.lists@gmail.com>
786 dnl
787 dnl This program is free software; you can redistribute it and/or modify
788 dnl it under the terms of the GNU General Public License as published by
789 dnl the Free Software Foundation; either version 2 of the License, or
790 dnl (at your option) any later version.
791 dnl
792 dnl This program is distributed in the hope that it will be useful, but
793 dnl WITHOUT ANY WARRANTY; without even the implied warranty of
794 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
795 dnl General Public License for more details.
796 dnl
797 dnl You should have received a copy of the GNU General Public License
798 dnl along with this program; if not, write to the Free Software
799 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
800 dnl 02111-1307, USA.
801 dnl
802 dnl As a special exception to the GNU General Public License, if you
803 dnl distribute this file as part of a program that contains a
804 dnl configuration script generated by Autoconf, you may include it under
805 dnl the same distribution terms that you use for the rest of that
806 dnl program.
807
808 dnl PKG_PREREQ(MIN-VERSION)
809 dnl -----------------------
810 dnl Since: 0.29
811 dnl
812 dnl Verify that the version of the pkg-config macros are at least
813 dnl MIN-VERSION. Unlike PKG_PROG_PKG_CONFIG, which checks the user's
814 dnl installed version of pkg-config, this checks the developer's version
815 dnl of pkg.m4 when generating configure.
816 dnl
817 dnl To ensure that this macro is defined, also add:
818 dnl m4_ifndef([PKG_PREREQ],
819 dnl [m4_fatal([must install pkg-config 0.29 or later before running autoconf/autogen])])
820 dnl
821 dnl See the "Since" comment for each macro you use to see what version
822 dnl of the macros you require.
823 m4_defun([PKG_PREREQ],
824 [m4_define([PKG_MACROS_VERSION], [0.29])
825 m4_if(m4_version_compare(PKG_MACROS_VERSION, [$1]), -1,
826 [m4_fatal([pkg.m4 version $1 or higher is required but ]PKG_MACROS_VERSION[ found])])
827 ])dnl PKG_PREREQ
828
829 dnl PKG_PROG_PKG_CONFIG([MIN-VERSION])
830 dnl ----------------------------------
831 dnl Since: 0.16
832 dnl
833 dnl Search for the pkg-config tool and set the PKG_CONFIG variable to
834 dnl first found in the path. Checks that the version of pkg-config found
835 dnl is at least MIN-VERSION. If MIN-VERSION is not specified, 0.17.0 is
836 dnl used since that's the first version where --static was supported.
837 AC_DEFUN([PKG_PROG_PKG_CONFIG],
838 [m4_pattern_forbid([^_?PKG_[A-Z_]+$])
839 m4_pattern_allow([^PKG_CONFIG(_(PATH|LIBDIR|SYSROOT_DIR|ALLOW_SYSTEM_(CFLAGS|LIBS)))?$])
840 m4_pattern_allow([^PKG_CONFIG_(DISABLE_UNINSTALLED|TOP_BUILD_DIR|DEBUG_SPEW)$])
841 AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
842 AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
843 AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
844
845 if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
846 AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
847 fi
848 if test -n "$PKG_CONFIG"; then
849 _pkg_min_version=m4_default([$1], [0.17.0])
850 AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
851 if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
852 AC_MSG_RESULT([yes])
853 else
854 AC_MSG_RESULT([no])
855 PKG_CONFIG=""
856 fi
857 fi[]dnl
858 ])dnl PKG_PROG_PKG_CONFIG
859
860 dnl PKG_CHECK_EXISTS(MODULE, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
861 dnl -------------------------------------------------------------------
862 dnl Since: 0.18
863 dnl
864 dnl Check to see whether a particular module exists. Similar to
865 dnl PKG_CHECK_MODULE(), but does not set variables or print errors.
866 AC_DEFUN([PKG_CHECK_EXISTS],
867 [
868 if test -n "$PKG_CONFIG" && \
869 AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then
870 m4_default([$2], [:])
871 m4_ifvaln([$3], [else
872 $3])dnl
873 fi])
874
875 dnl _PKG_CONFIG_WITH_FLAGS([VARIABLE], [FLAGS], [MODULE])
876 dnl ---------------------------------------------
877 dnl Internal wrapper calling pkg-config via PKG_CONFIG and, if
878 dnl pkg-config fails, reporting the error and quitting.
879 m4_define([_PKG_CONFIG_WITH_FLAGS],
880 [if test ! -n "$$1"; then
881 $1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
882 if test "x$?" != "x0"; then
883 #
884 # That failed - report an error.
885 # Re-run the command, telling pkg-config to print an error
886 # message, capture the error message, and report it.
887 # This causes the configuration script to fail, as it means
888 # the script is almost certainly doing something wrong.
889 #
890 _PKG_SHORT_ERRORS_SUPPORTED
891 if test $_pkg_short_errors_supported = yes; then
892 _pkg_error_string=`$PKG_CONFIG --short-errors --print-errors $2 "$3" 2>&1`
893 else
894 _pkg_error_string=`$PKG_CONFIG --print-errors $2 "$3" 2>&1`
895 fi
896 AC_MSG_ERROR([$PKG_CONFIG $2 "$3" failed: $_pkg_error_string])
897 fi
898 fi[]dnl
899 ])dnl _PKG_CONFIG_WITH_FLAGS
900
901
902 dnl _PKG_CONFIG([VARIABLE], [FLAGS], [MODULE])
903 dnl ---------------------------------------------
904 dnl Internal wrapper calling pkg-config via PKG_CONFIG and setting
905 dnl pkg_failed based on the result.
906 m4_define([_PKG_CONFIG],
907 [if test -n "$$1"; then
908 pkg_cv_[]$1="$$1"
909 elif test -n "$PKG_CONFIG"; then
910 PKG_CHECK_EXISTS([$3],
911 [pkg_cv_[]$1=`$PKG_CONFIG $2 "$3" 2>/dev/null`
912 test "x$?" != "x0" && pkg_failed=yes ],
913 [pkg_failed=yes])
914 else
915 pkg_failed=untried
916 fi[]dnl
917 ])dnl _PKG_CONFIG
918
919 dnl _PKG_SHORT_ERRORS_SUPPORTED
920 dnl ---------------------------
921 dnl Internal check to see if pkg-config supports short errors.
922 AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED],
923 [
924 if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
925 _pkg_short_errors_supported=yes
926 else
927 _pkg_short_errors_supported=no
928 fi[]dnl
929 ])dnl _PKG_SHORT_ERRORS_SUPPORTED
930
931
932 dnl PKG_CHECK_MODULE(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
933 dnl [ACTION-IF-NOT-FOUND])
934 dnl --------------------------------------------------------------
935 dnl Since: 0.4.0
936 AC_DEFUN([PKG_CHECK_MODULE],
937 [
938 AC_MSG_CHECKING([for $2 with pkg-config])
939 if test -n "$PKG_CONFIG"; then
940 AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $2, overriding pkg-config])dnl
941 AC_ARG_VAR([$1][_LIBS], [linker flags for $2, overriding pkg-config])dnl
942 AC_ARG_VAR([$1][_LIBS_STATIC], [static-link linker flags for $2, overriding pkg-config])dnl
943
944 if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
945 #
946 # The package was found, so try to get its C flags and
947 # libraries.
948 #
949 AC_MSG_RESULT([found])
950 _PKG_CONFIG_WITH_FLAGS([$1][_CFLAGS], [--cflags], [$2])
951 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS], [--libs], [$2])
952 _PKG_CONFIG_WITH_FLAGS([$1][_LIBS_STATIC], [--libs --static], [$2])
953 m4_default([$3], [:])
954 else
955 AC_MSG_RESULT([not found])
956 m4_default([$4], [:])
957 fi
958 else
959 # No pkg-config, so obviously not found with pkg-config.
960 AC_MSG_RESULT([pkg-config not found])
961 m4_default([$4], [:])
962 fi
963 ])dnl PKG_CHECK_MODULE
964
965
966 dnl PKG_CHECK_MODULE_STATIC(VARIABLE-PREFIX, MODULE, [ACTION-IF-FOUND],
967 dnl [ACTION-IF-NOT-FOUND])
968 dnl ---------------------------------------------------------------------
969 dnl Since: 0.29
970 dnl
971 dnl Checks for existence of MODULE and gathers its build flags with
972 dnl static libraries enabled. Sets VARIABLE-PREFIX_CFLAGS from --cflags
973 dnl and VARIABLE-PREFIX_LIBS from --libs.
974 AC_DEFUN([PKG_CHECK_MODULE_STATIC],
975 [
976 _save_PKG_CONFIG=$PKG_CONFIG
977 PKG_CONFIG="$PKG_CONFIG --static"
978 PKG_CHECK_MODULE($@)
979 PKG_CONFIG=$_save_PKG_CONFIG[]dnl
980 ])dnl PKG_CHECK_MODULE_STATIC
981
982
983 dnl PKG_INSTALLDIR([DIRECTORY])
984 dnl -------------------------
985 dnl Since: 0.27
986 dnl
987 dnl Substitutes the variable pkgconfigdir as the location where a module
988 dnl should install pkg-config .pc files. By default the directory is
989 dnl $libdir/pkgconfig, but the default can be changed by passing
990 dnl DIRECTORY. The user can override through the --with-pkgconfigdir
991 dnl parameter.
992 AC_DEFUN([PKG_INSTALLDIR],
993 [m4_pushdef([pkg_default], [m4_default([$1], ['${libdir}/pkgconfig'])])
994 m4_pushdef([pkg_description],
995 [pkg-config installation directory @<:@]pkg_default[@:>@])
996 AC_ARG_WITH([pkgconfigdir],
997 [AS_HELP_STRING([--with-pkgconfigdir], pkg_description)],,
998 [with_pkgconfigdir=]pkg_default)
999 AC_SUBST([pkgconfigdir], [$with_pkgconfigdir])
1000 m4_popdef([pkg_default])
1001 m4_popdef([pkg_description])
1002 ])dnl PKG_INSTALLDIR
1003
1004
1005 dnl PKG_NOARCH_INSTALLDIR([DIRECTORY])
1006 dnl --------------------------------
1007 dnl Since: 0.27
1008 dnl
1009 dnl Substitutes the variable noarch_pkgconfigdir as the location where a
1010 dnl module should install arch-independent pkg-config .pc files. By
1011 dnl default the directory is $datadir/pkgconfig, but the default can be
1012 dnl changed by passing DIRECTORY. The user can override through the
1013 dnl --with-noarch-pkgconfigdir parameter.
1014 AC_DEFUN([PKG_NOARCH_INSTALLDIR],
1015 [m4_pushdef([pkg_default], [m4_default([$1], ['${datadir}/pkgconfig'])])
1016 m4_pushdef([pkg_description],
1017 [pkg-config arch-independent installation directory @<:@]pkg_default[@:>@])
1018 AC_ARG_WITH([noarch-pkgconfigdir],
1019 [AS_HELP_STRING([--with-noarch-pkgconfigdir], pkg_description)],,
1020 [with_noarch_pkgconfigdir=]pkg_default)
1021 AC_SUBST([noarch_pkgconfigdir], [$with_noarch_pkgconfigdir])
1022 m4_popdef([pkg_default])
1023 m4_popdef([pkg_description])
1024 ])dnl PKG_NOARCH_INSTALLDIR
1025
1026
1027 dnl PKG_CHECK_VAR(VARIABLE, MODULE, CONFIG-VARIABLE,
1028 dnl [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
1029 dnl -------------------------------------------
1030 dnl Since: 0.28
1031 dnl
1032 dnl Retrieves the value of the pkg-config variable for the given module.
1033 AC_DEFUN([PKG_CHECK_VAR],
1034 [
1035 AC_ARG_VAR([$1], [value of $3 for $2, overriding pkg-config])dnl
1036
1037 _PKG_CONFIG([$1], [--variable="][$3]["], [$2])
1038 AS_VAR_COPY([$1], [pkg_cv_][$1])
1039
1040 AS_VAR_IF([$1], [""], [$5], [$4])dnl
1041 ])dnl PKG_CHECK_VAR