]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libpcap/aclocal.m4
Optionally bind ktls threads to NUMA domains
[FreeBSD/FreeBSD.git] / contrib / 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_FIXINCLUDES])
43     AC_BEFORE([$0], [AC_LBL_DEVEL])
44     AC_ARG_WITH(gcc, [  --without-gcc           don't use gcc])
45     $1=""
46     if test "${srcdir}" != "." ; then
47             $1="-I\$(srcdir)"
48     fi
49     if test "${CFLAGS+set}" = set; then
50             LBL_CFLAGS="$CFLAGS"
51     fi
52     if test -z "$CC" ; then
53             case "$host_os" in
54
55             bsdi*)
56                     AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
57                     if test $SHLICC2 = yes ; then
58                             CC=shlicc2
59                             export CC
60                     fi
61                     ;;
62             esac
63     fi
64     if test -z "$CC" -a "$with_gcc" = no ; then
65             CC=cc
66             export CC
67     fi
68 ])
69
70 dnl
71 dnl Determine which compiler we're using (cc or gcc)
72 dnl If using gcc, determine the version number
73 dnl If using cc:
74 dnl     require that it support ansi prototypes
75 dnl     use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
76 dnl     do that ourselves for gcc)
77 dnl     add -g flags, as appropriate
78 dnl     explicitly specify /usr/local/include
79 dnl
80 dnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
81 dnl that defines __GNUC__, which means clang, for example, counts as "gcc".
82 dnl
83 dnl usage:
84 dnl
85 dnl     AC_LBL_C_INIT(copt, incls)
86 dnl
87 dnl results:
88 dnl
89 dnl     $1 (copt set)
90 dnl     $2 (incls set)
91 dnl     CC
92 dnl     LDFLAGS
93 dnl     LBL_CFLAGS
94 dnl
95 AC_DEFUN(AC_LBL_C_INIT,
96 [
97     AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
98     AC_BEFORE([$0], [AC_LBL_DEVEL])
99     AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT])
100     if test "$GCC" = yes ; then
101             #
102             # -Werror forces warnings to be errors.
103             #
104             ac_lbl_cc_force_warning_errors=-Werror
105
106             #
107             # Try to have the compiler default to hiding symbols,
108             # so that only symbols explicitly exported with
109             # PCAP_API will be visible outside (shared) libraries.
110             #
111             AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
112     else
113             $2="$$2 -I/usr/local/include"
114             LDFLAGS="$LDFLAGS -L/usr/local/lib"
115
116             case "$host_os" in
117
118             darwin*)
119                     #
120                     # This is assumed either to be GCC or clang, both
121                     # of which use -Werror to force warnings to be errors.
122                     #
123                     ac_lbl_cc_force_warning_errors=-Werror
124
125                     #
126                     # Try to have the compiler default to hiding symbols,
127                     # so that only symbols explicitly exported with
128                     # PCAP_API will be visible outside (shared) libraries.
129                     #
130                     AC_LBL_CHECK_COMPILER_OPT($1, -fvisibility=hidden)
131                     ;;
132
133             hpux*)
134                     #
135                     # HP C, which is what we presume we're using, doesn't
136                     # exit with a non-zero exit status if we hand it an
137                     # invalid -W flag, can't be forced to do so even with
138                     # +We, and doesn't handle GCC-style -W flags, so we
139                     # don't want to try using GCC-style -W flags.
140                     #
141                     ac_lbl_cc_dont_try_gcc_dashW=yes
142                     ;;
143
144             irix*)
145                     #
146                     # MIPS C, which is what we presume we're using, doesn't
147                     # necessarily exit with a non-zero exit status if we
148                     # hand it an invalid -W flag, can't be forced to do
149                     # so, and doesn't handle GCC-style -W flags, so we
150                     # don't want to try using GCC-style -W flags.
151                     #
152                     ac_lbl_cc_dont_try_gcc_dashW=yes
153                     #
154                     # It also, apparently, defaults to "char" being
155                     # unsigned, unlike most other C implementations;
156                     # I suppose we could say "signed char" whenever
157                     # we want to guarantee a signed "char", but let's
158                     # just force signed chars.
159                     #
160                     # -xansi is normally the default, but the
161                     # configure script was setting it; perhaps -cckr
162                     # was the default in the Old Days.  (Then again,
163                     # that would probably be for backwards compatibility
164                     # in the days when ANSI C was Shiny and New, i.e.
165                     # 1989 and the early '90's, so maybe we can just
166                     # drop support for those compilers.)
167                     #
168                     # -g is equivalent to -g2, which turns off
169                     # optimization; we choose -g3, which generates
170                     # debugging information but doesn't turn off
171                     # optimization (even if the optimization would
172                     # cause inaccuracies in debugging).
173                     #
174                     $1="$$1 -xansi -signed -g3"
175                     ;;
176
177             osf*)
178                     #
179                     # Presumed to be DEC OSF/1, Digital UNIX, or
180                     # Tru64 UNIX.
181                     #
182                     # The DEC C compiler, which is what we presume we're
183                     # using, doesn't exit with a non-zero exit status if we
184                     # hand it an invalid -W flag, can't be forced to do
185                     # so, and doesn't handle GCC-style -W flags, so we
186                     # don't want to try using GCC-style -W flags.
187                     #
188                     ac_lbl_cc_dont_try_gcc_dashW=yes
189                     #
190                     # -g is equivalent to -g2, which turns off
191                     # optimization; we choose -g3, which generates
192                     # debugging information but doesn't turn off
193                     # optimization (even if the optimization would
194                     # cause inaccuracies in debugging).
195                     #
196                     $1="$$1 -g3"
197                     ;;
198
199             solaris*)
200                     #
201                     # Assumed to be Sun C, which requires -errwarn to force
202                     # warnings to be treated as errors.
203                     #
204                     ac_lbl_cc_force_warning_errors=-errwarn
205
206                     #
207                     # Try to have the compiler default to hiding symbols,
208                     # so that only symbols explicitly exported with
209                     # PCAP_API will be visible outside (shared) libraries.
210                     #
211                     AC_LBL_CHECK_COMPILER_OPT($1, -xldscope=hidden)
212                     ;;
213
214             ultrix*)
215                     AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
216                     AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
217                         AC_TRY_COMPILE(
218                             [#include <sys/types.h>],
219                             [struct a { int b; };
220                             void c(const struct a *)],
221                             ac_cv_lbl_cc_const_proto=yes,
222                             ac_cv_lbl_cc_const_proto=no))
223                     AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
224                     if test $ac_cv_lbl_cc_const_proto = no ; then
225                             AC_DEFINE(const,[],
226                                 [to handle Ultrix compilers that don't support const in prototypes])
227                     fi
228                     ;;
229             esac
230             $1="$$1 -O"
231     fi
232 ])
233
234 dnl
235 dnl Check whether, if you pass an unknown warning option to the
236 dnl compiler, it fails or just prints a warning message and succeeds.
237 dnl Set ac_lbl_unknown_warning_option_error to the appropriate flag
238 dnl to force an error if it would otherwise just print a warning message
239 dnl and succeed.
240 dnl
241 AC_DEFUN(AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR,
242     [
243         AC_MSG_CHECKING([whether the compiler fails when given an unknown warning option])
244         save_CFLAGS="$CFLAGS"
245         CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy"
246         AC_TRY_COMPILE(
247             [],
248             [return 0],
249             [
250                 AC_MSG_RESULT([no])
251                 #
252                 # We're assuming this is clang, where
253                 # -Werror=unknown-warning-option is the appropriate
254                 # option to force the compiler to fail.
255                 #
256                 ac_lbl_unknown_warning_option_error="-Werror=unknown-warning-option"
257             ],
258             [
259                 AC_MSG_RESULT([yes])
260             ])
261         CFLAGS="$save_CFLAGS"
262     ])
263
264 dnl
265 dnl Check whether the compiler option specified as the second argument
266 dnl is supported by the compiler and, if so, add it to the macro
267 dnl specified as the first argument
268 dnl
269 dnl If a third argument is supplied, treat it as C code to be compiled
270 dnl with the flag in question, and the "treat warnings as errors" flag
271 dnl set, and don't add the flag to the first argument if the compile
272 dnl fails; this is for warning options cause problems that can't be
273 dnl worked around.  If a third argument is supplied, a fourth argument
274 dnl should also be supplied; it's a message desribing what the test
275 dnl program is checking.
276 dnl
277 AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
278     [
279         AC_MSG_CHECKING([whether the compiler supports the $2 option])
280         save_CFLAGS="$CFLAGS"
281         if expr "x$2" : "x-W.*" >/dev/null
282         then
283             CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error $2"
284         elif expr "x$2" : "x-f.*" >/dev/null
285         then
286             CFLAGS="$CFLAGS -Werror $2"
287         elif expr "x$2" : "x-m.*" >/dev/null
288         then
289             CFLAGS="$CFLAGS -Werror $2"
290         else
291             CFLAGS="$CFLAGS $2"
292         fi
293         AC_TRY_COMPILE(
294             [],
295             [return 0],
296             [
297                 AC_MSG_RESULT([yes])
298                 can_add_to_cflags=yes
299                 #
300                 # The compile supports this; do we have some C code for
301                 # which the warning should *not* appear?
302                 # We test the fourth argument because the third argument
303                 # could contain quotes, breaking the test.
304                 #
305                 if test "x$4" != "x"
306                 then
307                     CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
308                     AC_MSG_CHECKING(whether $2 $4)
309                     AC_COMPILE_IFELSE(
310                       [AC_LANG_SOURCE($3)],
311                       [
312                         #
313                         # Not a problem.
314                         #
315                         AC_MSG_RESULT(no)
316                       ],
317                       [
318                         #
319                         # A problem.
320                         #
321                         AC_MSG_RESULT(yes)
322                         can_add_to_cflags=no
323                       ])
324                 fi
325                 CFLAGS="$save_CFLAGS"
326                 if test x"$can_add_to_cflags" = "xyes"
327                 then
328                     $1="$$1 $2"
329                 fi
330             ],
331             [
332                 AC_MSG_RESULT([no])
333                 CFLAGS="$save_CFLAGS"
334             ])
335     ])
336
337 dnl
338 dnl Check whether the compiler supports an option to generate
339 dnl Makefile-style dependency lines
340 dnl
341 dnl GCC uses -M for this.  Non-GCC compilers that support this
342 dnl use a variety of flags, including but not limited to -M.
343 dnl
344 dnl We test whether the flag in question is supported, as older
345 dnl versions of compilers might not support it.
346 dnl
347 dnl We don't try all the possible flags, just in case some flag means
348 dnl "generate dependencies" on one compiler but means something else
349 dnl on another compiler.
350 dnl
351 dnl Most compilers that support this send the output to the standard
352 dnl output by default.  IBM's XLC, however, supports -M but sends
353 dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
354 dnl to work around that, so we don't bother with XLC.
355 dnl
356 AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
357     [
358         AC_MSG_CHECKING([whether the compiler supports generating dependencies])
359         if test "$GCC" = yes ; then
360                 #
361                 # GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
362                 # though it's not); we assume that, in this case, the flag
363                 # would be -M.
364                 #
365                 ac_lbl_dependency_flag="-M"
366         else
367                 #
368                 # Not GCC or a compiler deemed to be GCC; what platform is
369                 # this?  (We're assuming that if the compiler isn't GCC
370                 # it's the compiler from the vendor of the OS; that won't
371                 # necessarily be true for x86 platforms, where it might be
372                 # the Intel C compiler.)
373                 #
374                 case "$host_os" in
375
376                 irix*|osf*|darwin*)
377                         #
378                         # MIPS C for IRIX, DEC C, and clang all use -M.
379                         #
380                         ac_lbl_dependency_flag="-M"
381                         ;;
382
383                 solaris*)
384                         #
385                         # Sun C uses -xM.
386                         #
387                         ac_lbl_dependency_flag="-xM"
388                         ;;
389
390                 hpux*)
391                         #
392                         # HP's older C compilers don't support this.
393                         # HP's newer C compilers support this with
394                         # either +M or +Make; the older compilers
395                         # interpret +M as something completely
396                         # different, so we use +Make so we don't
397                         # think it works with the older compilers.
398                         #
399                         ac_lbl_dependency_flag="+Make"
400                         ;;
401
402                 *)
403                         #
404                         # Not one of the above; assume no support for
405                         # generating dependencies.
406                         #
407                         ac_lbl_dependency_flag=""
408                         ;;
409                 esac
410         fi
411
412         #
413         # Is ac_lbl_dependency_flag defined and, if so, does the compiler
414         # complain about it?
415         #
416         # Note: clang doesn't seem to exit with an error status when handed
417         # an unknown non-warning error, even if you pass it
418         # -Werror=unknown-warning-option.  However, it always supports
419         # -M, so the fact that this test always succeeds with clang
420         # isn't an issue.
421         #
422         if test ! -z "$ac_lbl_dependency_flag"; then
423                 AC_LANG_CONFTEST(
424                     [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
425                 if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
426                         AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
427                         DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
428                         MKDEP='${srcdir}/mkdep'
429                 else
430                         AC_MSG_RESULT([no])
431                         #
432                         # We can't run mkdep, so have "make depend" do
433                         # nothing.
434                         #
435                         MKDEP='${srcdir}/nomkdep'
436                 fi
437                 rm -rf conftest*
438         else
439                 AC_MSG_RESULT([no])
440                 #
441                 # We can't run mkdep, so have "make depend" do
442                 # nothing.
443                 #
444                 MKDEP='${srcdir}/nomkdep'
445         fi
446         AC_SUBST(DEPENDENCY_CFLAG)
447         AC_SUBST(MKDEP)
448     ])
449
450 dnl
451 dnl Determine what options are needed to build a shared library
452 dnl
453 dnl usage:
454 dnl
455 dnl     AC_LBL_SHLIBS_INIT
456 dnl
457 dnl results:
458 dnl
459 dnl     V_SHLIB_CCOPT (modified to build position-independent code)
460 dnl     V_SHLIB_CMD
461 dnl     V_SHLIB_OPT
462 dnl     V_SONAME_OPT
463 dnl     V_RPATH_OPT
464 dnl
465 AC_DEFUN(AC_LBL_SHLIBS_INIT,
466     [AC_PREREQ(2.50)
467     if test "$GCC" = yes ; then
468             #
469             # On platforms where we build a shared library:
470             #
471             #   add options to generate position-independent code,
472             #   if necessary (it's the default in AIX and Darwin/macOS);
473             #
474             #   define option to set the soname of the shared library,
475             #   if the OS supports that;
476             #
477             #   add options to specify, at link time, a directory to
478             #   add to the run-time search path, if that's necessary.
479             #
480             V_SHLIB_CMD="\$(CC)"
481             V_SHLIB_OPT="-shared"
482             case "$host_os" in
483
484             aix*)
485                     ;;
486
487             freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*|midipix*)
488                     #
489                     # Platforms where the linker is the GNU linker
490                     # or accepts command-line arguments like
491                     # those the GNU linker accepts.
492                     #
493                     # Some instruction sets require -fPIC on some
494                     # operating systems.  Check for them.  If you
495                     # have a combination that requires it, add it
496                     # here.
497                     #
498                     PIC_OPT=-fpic
499                     case "$host_cpu" in
500
501                     sparc64*)
502                         case "$host_os" in
503
504                         freebsd*|openbsd*|linux*)
505                             PIC_OPT=-fPIC
506                             ;;
507                         esac
508                         ;;
509                     esac
510                     V_SHLIB_CCOPT="$V_SHLIB_CCOPT $PIC_OPT"
511                     V_SONAME_OPT="-Wl,-soname,"
512                     V_RPATH_OPT="-Wl,-rpath,"
513                     ;;
514
515             hpux*)
516                     V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
517                     #
518                     # XXX - this assumes GCC is using the HP linker,
519                     # rather than the GNU linker, and that the "+h"
520                     # option is used on all HP-UX platforms, both .sl
521                     # and .so.
522                     #
523                     V_SONAME_OPT="-Wl,+h,"
524                     #
525                     # By default, directories specifed with -L
526                     # are added to the run-time search path, so
527                     # we don't add them in pcap-config.
528                     #
529                     ;;
530
531             solaris*)
532                     V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
533                     #
534                     # XXX - this assumes GCC is using the Sun linker,
535                     # rather than the GNU linker.
536                     #
537                     V_SONAME_OPT="-Wl,-h,"
538                     V_RPATH_OPT="-Wl,-R,"
539                     ;;
540             esac
541     else
542             #
543             # Set the appropriate compiler flags and, on platforms
544             # where we build a shared library:
545             #
546             #   add options to generate position-independent code,
547             #   if necessary (it's the default in Darwin/macOS);
548             #
549             #   if we generate ".so" shared libraries, define the
550             #   appropriate options for building the shared library;
551             #
552             #   add options to specify, at link time, a directory to
553             #   add to the run-time search path, if that's necessary.
554             #
555             # Note: spaces after V_SONAME_OPT are significant; on
556             # some platforms the soname is passed with a GCC-like
557             # "-Wl,-soname,{soname}" option, with the soname part
558             # of the option, while on other platforms the C compiler
559             # driver takes it as a regular option with the soname
560             # following the option.  The same applies to V_RPATH_OPT.
561             #
562             case "$host_os" in
563
564             aix*)
565                     V_SHLIB_CMD="\$(CC)"
566                     V_SHLIB_OPT="-G -bnoentry -bexpall"
567                     ;;
568
569             freebsd*|netbsd*|openbsd*|dragonfly*|linux*)
570                     #
571                     # "cc" is GCC.
572                     #
573                     V_SHLIB_CCOPT="$V_SHLIB_CCOPT -fpic"
574                     V_SHLIB_CMD="\$(CC)"
575                     V_SHLIB_OPT="-shared"
576                     V_SONAME_OPT="-Wl,-soname,"
577                     V_RPATH_OPT="-Wl,-rpath,"
578                     ;;
579
580             hpux*)
581                     V_SHLIB_CCOPT="$V_SHLIB_CCOPT +z"
582                     V_SHLIB_CMD="\$(LD)"
583                     V_SHLIB_OPT="-b"
584                     V_SONAME_OPT="+h "
585                     #
586                     # By default, directories specifed with -L
587                     # are added to the run-time search path, so
588                     # we don't add them in pcap-config.
589                     #
590                     ;;
591
592             osf*)
593                     #
594                     # Presumed to be DEC OSF/1, Digital UNIX, or
595                     # Tru64 UNIX.
596                     #
597                     V_SHLIB_CMD="\$(CC)"
598                     V_SHLIB_OPT="-shared"
599                     V_SONAME_OPT="-soname "
600                     V_RPATH_OPT="-rpath "
601                     ;;
602
603             solaris*)
604                     V_SHLIB_CCOPT="$V_SHLIB_CCOPT -Kpic"
605                     V_SHLIB_CMD="\$(CC)"
606                     V_SHLIB_OPT="-G"
607                     V_SONAME_OPT="-h "
608                     V_RPATH_OPT="-R"
609                     ;;
610             esac
611     fi
612 ])
613
614 #
615 # Try compiling a sample of the type of code that appears in
616 # gencode.c with "inline", "__inline__", and "__inline".
617 #
618 # Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
619 # as it just tests whether a function returning "int" can be inlined;
620 # at least some versions of HP's C compiler can inline that, but can't
621 # inline a function that returns a struct pointer.
622 #
623 # Make sure we use the V_CCOPT flags, because some of those might
624 # disable inlining.
625 #
626 AC_DEFUN(AC_LBL_C_INLINE,
627     [AC_MSG_CHECKING(for inline)
628     save_CFLAGS="$CFLAGS"
629     CFLAGS="$V_CCOPT"
630     AC_CACHE_VAL(ac_cv_lbl_inline, [
631         ac_cv_lbl_inline=""
632         ac_lbl_cc_inline=no
633         for ac_lbl_inline in inline __inline__ __inline
634         do
635             AC_TRY_COMPILE(
636                 [#define inline $ac_lbl_inline
637                 static inline struct iltest *foo(void);
638                 struct iltest {
639                     int iltest1;
640                     int iltest2;
641                 };
642
643                 static inline struct iltest *
644                 foo()
645                 {
646                     static struct iltest xxx;
647
648                     return &xxx;
649                 }],,ac_lbl_cc_inline=yes,)
650             if test "$ac_lbl_cc_inline" = yes ; then
651                 break;
652             fi
653         done
654         if test "$ac_lbl_cc_inline" = yes ; then
655             ac_cv_lbl_inline=$ac_lbl_inline
656         fi])
657     CFLAGS="$save_CFLAGS"
658     if test ! -z "$ac_cv_lbl_inline" ; then
659         AC_MSG_RESULT($ac_cv_lbl_inline)
660     else
661         AC_MSG_RESULT(no)
662     fi
663     AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
664
665 dnl
666 dnl If using gcc, make sure we have ANSI ioctl definitions
667 dnl
668 dnl usage:
669 dnl
670 dnl     AC_LBL_FIXINCLUDES
671 dnl
672 AC_DEFUN(AC_LBL_FIXINCLUDES,
673     [if test "$GCC" = yes ; then
674             AC_MSG_CHECKING(for ANSI ioctl definitions)
675             AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
676                 AC_TRY_COMPILE(
677                     [/*
678                      * This generates a "duplicate case value" when fixincludes
679                      * has not be run.
680                      */
681 #               include <sys/types.h>
682 #               include <sys/time.h>
683 #               include <sys/ioctl.h>
684 #               ifdef HAVE_SYS_IOCCOM_H
685 #               include <sys/ioccom.h>
686 #               endif],
687                     [switch (0) {
688                     case _IO('A', 1):;
689                     case _IO('B', 1):;
690                     }],
691                     ac_cv_lbl_gcc_fixincludes=yes,
692                     ac_cv_lbl_gcc_fixincludes=no))
693             AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
694             if test $ac_cv_lbl_gcc_fixincludes = no ; then
695                     # Don't cache failure
696                     unset ac_cv_lbl_gcc_fixincludes
697                     AC_MSG_ERROR(see the INSTALL for more info)
698             fi
699     fi])
700
701 dnl
702 dnl Checks to see if union wait is used with WEXITSTATUS()
703 dnl
704 dnl usage:
705 dnl
706 dnl     AC_LBL_UNION_WAIT
707 dnl
708 dnl results:
709 dnl
710 dnl     DECLWAITSTATUS (defined)
711 dnl
712 AC_DEFUN(AC_LBL_UNION_WAIT,
713     [AC_MSG_CHECKING(if union wait is used)
714     AC_CACHE_VAL(ac_cv_lbl_union_wait,
715         AC_TRY_COMPILE([
716 #       include <sys/types.h>
717 #       include <sys/wait.h>],
718             [int status;
719             u_int i = WEXITSTATUS(status);
720             u_int j = waitpid(0, &status, 0);],
721             ac_cv_lbl_union_wait=no,
722             ac_cv_lbl_union_wait=yes))
723     AC_MSG_RESULT($ac_cv_lbl_union_wait)
724     if test $ac_cv_lbl_union_wait = yes ; then
725             AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
726     else
727             AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
728     fi])
729
730 dnl
731 dnl Checks to see if -R is used
732 dnl
733 dnl usage:
734 dnl
735 dnl     AC_LBL_HAVE_RUN_PATH
736 dnl
737 dnl results:
738 dnl
739 dnl     ac_cv_lbl_have_run_path (yes or no)
740 dnl
741 AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
742     [AC_MSG_CHECKING(for ${CC-cc} -R)
743     AC_CACHE_VAL(ac_cv_lbl_have_run_path,
744         [echo 'main(){}' > conftest.c
745         ${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
746         if test ! -s conftest.out ; then
747                 ac_cv_lbl_have_run_path=yes
748         else
749                 ac_cv_lbl_have_run_path=no
750         fi
751         rm -f -r conftest*])
752     AC_MSG_RESULT($ac_cv_lbl_have_run_path)
753     ])
754
755 dnl
756 dnl Checks to see if unaligned memory accesses fail
757 dnl
758 dnl usage:
759 dnl
760 dnl     AC_LBL_UNALIGNED_ACCESS
761 dnl
762 dnl results:
763 dnl
764 dnl     LBL_ALIGN (DEFINED)
765 dnl
766 AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
767     [AC_MSG_CHECKING(if unaligned accesses fail)
768     AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
769         [case "$host_cpu" in
770
771         #
772         # These are CPU types where:
773         #
774         #       the CPU faults on an unaligned access, but at least some
775         #       OSes that support that CPU catch the fault and simulate
776         #       the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
777         #       the simulation is slow, so we don't want to use it;
778         #
779         #       the CPU, I infer (from the old
780         #
781         # XXX: should also check that they don't do weird things (like on arm)
782         #
783         #       comment) doesn't fault on unaligned accesses, but doesn't
784         #       do a normal unaligned fetch, either (e.g., presumably, ARM);
785         #
786         #       for whatever reason, the test program doesn't work
787         #       (this has been claimed to be the case for several of those
788         #       CPUs - I don't know what the problem is; the problem
789         #       was reported as "the test program dumps core" for SuperH,
790         #       but that's what the test program is *supposed* to do -
791         #       it dumps core before it writes anything, so the test
792         #       for an empty output file should find an empty output
793         #       file and conclude that unaligned accesses don't work).
794         #
795         # This run-time test won't work if you're cross-compiling, so
796         # in order to support cross-compiling for a particular CPU,
797         # we have to wire in the list of CPU types anyway, as far as
798         # I know, so perhaps we should just have a set of CPUs on
799         # which we know it doesn't work, a set of CPUs on which we
800         # know it does work, and have the script just fail on other
801         # cpu types and update it when such a failure occurs.
802         #
803         alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1)
804                 ac_cv_lbl_unaligned_fail=yes
805                 ;;
806
807         *)
808                 cat >conftest.c <<EOF
809 #               include <sys/types.h>
810 #               include <sys/wait.h>
811 #               include <stdio.h>
812                 unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
813                 main() {
814                 unsigned int i;
815                 pid_t pid;
816                 int status;
817                 /* avoid "core dumped" message */
818                 pid = fork();
819                 if (pid <  0)
820                         exit(2);
821                 if (pid > 0) {
822                         /* parent */
823                         pid = waitpid(pid, &status, 0);
824                         if (pid < 0)
825                                 exit(3);
826                         exit(!WIFEXITED(status));
827                 }
828                 /* child */
829                 i = *(unsigned int *)&a[[1]];
830                 printf("%d\n", i);
831                 exit(0);
832                 }
833 EOF
834                 ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
835                     conftest.c $LIBS >/dev/null 2>&1
836                 if test ! -x conftest ; then
837                         dnl failed to compile for some reason
838                         ac_cv_lbl_unaligned_fail=yes
839                 else
840                         ./conftest >conftest.out
841                         if test ! -s conftest.out ; then
842                                 ac_cv_lbl_unaligned_fail=yes
843                         else
844                                 ac_cv_lbl_unaligned_fail=no
845                         fi
846                 fi
847                 rm -f -r conftest* core core.conftest
848                 ;;
849         esac])
850     AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
851     if test $ac_cv_lbl_unaligned_fail = yes ; then
852             AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails])
853     fi])
854
855 dnl
856 dnl If the file .devel exists:
857 dnl     Add some warning flags if the compiler supports them
858 dnl     If an os prototype include exists, symlink os-proto.h to it
859 dnl
860 dnl usage:
861 dnl
862 dnl     AC_LBL_DEVEL(copt)
863 dnl
864 dnl results:
865 dnl
866 dnl     $1 (copt appended)
867 dnl     HAVE_OS_PROTO_H (defined)
868 dnl     os-proto.h (symlinked)
869 dnl
870 AC_DEFUN(AC_LBL_DEVEL,
871     [rm -f os-proto.h
872     if test "${LBL_CFLAGS+set}" = set; then
873             $1="$$1 ${LBL_CFLAGS}"
874     fi
875     if test -f .devel ; then
876             #
877             # Skip all the warning option stuff on some compilers.
878             #
879             if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
880                     AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR()
881                     AC_LBL_CHECK_COMPILER_OPT($1, -W)
882                     AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
883                     AC_LBL_CHECK_COMPILER_OPT($1, -Wcomma)
884                     AC_LBL_CHECK_COMPILER_OPT($1, -Wdeclaration-after-statement)
885                     AC_LBL_CHECK_COMPILER_OPT($1, -Wdocumentation)
886                     AC_LBL_CHECK_COMPILER_OPT($1, -Wformat-nonliteral)
887                     AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-noreturn)
888                     AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
889                     AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
890                     AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
891                     AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
892                     AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
893                     AC_LBL_CHECK_COMPILER_OPT($1, -Wunused-parameter)
894                     AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
895                     # Warns about safeguards added in case the enums are
896                     # extended
897                     # AC_LBL_CHECK_COMPILER_OPT($1, -Wcovered-switch-default)
898                     #
899                     # This can cause problems with ntohs(), ntohl(),
900                     # htons(), and htonl() on some platforms, such
901                     # as OpenBSD 6.3 with Clang 5.0.1.  I guess the
902                     # problem is that the macro that ultimately does
903                     # the byte-swapping involves a conditional
904                     # expression that tests whether the value being
905                     # swapped is a compile-time constant or not,
906                     # using __builtin_constant_p(), and, depending
907                     # on whether it is, does a compile-time swap or
908                     # a run-time swap; perhaps the compiler always
909                     # considers one of the two results of the
910                     # conditional expressin is never evaluated,
911                     # because the conditional check is done at
912                     # compile time, and thus always says "that
913                     # expression is never executed".
914                     #
915                     # (Perhaps there should be a way of flagging
916                     # an expression that you *want* evaluated at
917                     # compile time, so that the compiler 1) warns
918                     # if it *can't* be evaluated at compile time
919                     # and 2) *doesn't* warn that the true or false
920                     # branch will never be reached.)
921                     #
922                     AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code,
923                       [
924 #include <arpa/inet.h>
925
926 unsigned short
927 testme(unsigned short a)
928 {
929         return ntohs(a);
930 }
931                       ],
932                       [generates warnings from ntohs()])
933             fi
934             AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
935             #
936             # We used to set -n32 for IRIX 6 when not using GCC (presumed
937             # to mean that we're using MIPS C or MIPSpro C); it specified
938             # the "new" faster 32-bit ABI, introduced in IRIX 6.2.  I'm
939             # not sure why that would be something to do *only* with a
940             # .devel file; why should the ABI for which we produce code
941             # depend on .devel?
942             #
943             os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
944             name="lbl/os-$os.h"
945             if test -f $name ; then
946                     ln -s $name os-proto.h
947                     AC_DEFINE(HAVE_OS_PROTO_H, 1,
948                         [if there's an os_proto.h for this platform, to use additional prototypes])
949             else
950                     AC_MSG_WARN(can't find $name)
951             fi
952     fi])
953
954 dnl
955 dnl Improved version of AC_CHECK_LIB
956 dnl
957 dnl Thanks to John Hawkinson (jhawk@mit.edu)
958 dnl
959 dnl usage:
960 dnl
961 dnl     AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
962 dnl         ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
963 dnl
964 dnl results:
965 dnl
966 dnl     LIBS
967 dnl
968 dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
969 dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
970 dnl We keep it around for reference purposes in case it's ever
971 dnl useful in the future.
972 dnl
973
974 define(AC_LBL_CHECK_LIB,
975 [AC_MSG_CHECKING([for $2 in -l$1])
976 dnl Use a cache variable name containing the library, function
977 dnl name, and extra libraries to link with, because the test really is
978 dnl for library $1 defining function $2, when linked with potinal
979 dnl library $5, not just for library $1.  Separate tests with the same
980 dnl $1 and different $2's or $5's may have different results.
981 ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
982 AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
983 [ac_save_LIBS="$LIBS"
984 LIBS="-l$1 $5 $LIBS"
985 AC_TRY_LINK(dnl
986 ifelse([$2], [main], , dnl Avoid conflicting decl of main.
987 [/* Override any gcc2 internal prototype to avoid an error.  */
988 ]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
989 extern "C"
990 #endif
991 ])dnl
992 [/* We use char because int might match the return type of a gcc2
993     builtin and then its argument prototype would still apply.  */
994 char $2();
995 ]),
996             [$2()],
997             eval "ac_cv_lbl_lib_$ac_lib_var=yes",
998             eval "ac_cv_lbl_lib_$ac_lib_var=no")
999 LIBS="$ac_save_LIBS"
1000 ])dnl
1001 if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
1002   AC_MSG_RESULT(yes)
1003   ifelse([$3], ,
1004 [changequote(, )dnl
1005   ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
1006     -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1007 changequote([, ])dnl
1008   AC_DEFINE_UNQUOTED($ac_tr_lib)
1009   LIBS="-l$1 $LIBS"
1010 ], [$3])
1011 else
1012   AC_MSG_RESULT(no)
1013 ifelse([$4], , , [$4
1014 ])dnl
1015 fi
1016 ])
1017
1018 dnl
1019 dnl AC_LBL_LIBRARY_NET
1020 dnl
1021 dnl This test is for network applications that need socket functions and
1022 dnl getaddrinfo()/getnameinfo()-ish functions.  We now require
1023 dnl getaddrinfo() and getnameinfo().  We also prefer versions of
1024 dnl recvmsg() that conform to the Single UNIX Specification, so that we
1025 dnl can check whether a datagram received with recvmsg() was truncated
1026 dnl when received due to the buffer being too small.
1027 dnl
1028 dnl On most operating systems, they're available in the system library.
1029 dnl
1030 dnl Under Solaris, we need to link with libsocket and libnsl to get
1031 dnl getaddrinfo() and getnameinfo() and, if we have libxnet, we need to
1032 dnl link with libxnet before libsocket to get a version of recvmsg()
1033 dnl that conforms to the Single UNIX Specification.
1034 dnl
1035 dnl We use getaddrinfo() because we want a portable thread-safe way
1036 dnl of getting information for a host name or port; there exist _r
1037 dnl versions of gethostbyname() and getservbyname() on some platforms,
1038 dnl but not on all platforms.
1039 dnl
1040 AC_DEFUN(AC_LBL_LIBRARY_NET, [
1041     #
1042     # Most operating systems have getaddrinfo() in the default searched
1043     # libraries (i.e. libc).  Check there first.
1044     #
1045     AC_CHECK_FUNC(getaddrinfo,,
1046     [
1047         #
1048         # Not found in the standard system libraries.
1049         # Try libsocket, which requires libnsl.
1050         #
1051         AC_CHECK_LIB(socket, getaddrinfo,
1052         [
1053             #
1054             # OK, we found it in libsocket.
1055             #
1056             LIBS="-lsocket -lnsl $LIBS"
1057         ],
1058         [
1059             #
1060             # We didn't find it.
1061             #
1062             AC_MSG_ERROR([getaddrinfo is required, but wasn't found])
1063         ], -lnsl)
1064
1065         #
1066         # OK, do we have recvmsg() in libxnet?
1067         # We also link with libsocket and libnsl.
1068         #
1069         AC_CHECK_LIB(xnet, recvmsg,
1070         [
1071             #
1072             # Yes - link with it as well.
1073             #
1074             LIBS="-lxnet $LIBS"
1075         ], , -lsocket -lnsl)
1076     ])
1077     # DLPI needs putmsg under HPUX so test for -lstr while we're at it
1078     AC_SEARCH_LIBS(putmsg, str)
1079 ])