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