Home | History | Annotate | Download | only in libpcap
      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     else
    106 	    $2="$$2 -I/usr/local/include"
    107 	    LDFLAGS="$LDFLAGS -L/usr/local/lib"
    108 
    109 	    case "$host_os" in
    110 
    111 	    darwin*)
    112 		    #
    113 		    # This is assumed either to be GCC or clang, both
    114 		    # of which use -Werror to force warnings to be errors.
    115 		    #
    116 		    ac_lbl_cc_force_warning_errors=-Werror
    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 	    ultrix*)
    194 		    AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
    195 		    AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
    196 			AC_TRY_COMPILE(
    197 			    [#include <sys/types.h>],
    198 			    [struct a { int b; };
    199 			    void c(const struct a *)],
    200 			    ac_cv_lbl_cc_const_proto=yes,
    201 			    ac_cv_lbl_cc_const_proto=no))
    202 		    AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
    203 		    if test $ac_cv_lbl_cc_const_proto = no ; then
    204 			    AC_DEFINE(const,[],
    205 			        [to handle Ultrix compilers that don't support const in prototypes])
    206 		    fi
    207 		    ;;
    208 	    esac
    209 	    $1="$$1 -O"
    210     fi
    211 ])
    212 
    213 dnl
    214 dnl Check whether, if you pass an unknown warning option to the
    215 dnl compiler, it fails or just prints a warning message and succeeds.
    216 dnl Set ac_lbl_unknown_warning_option_error to the appropriate flag
    217 dnl to force an error if it would otherwise just print a warning message
    218 dnl and succeed.
    219 dnl
    220 AC_DEFUN(AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR,
    221     [
    222 	AC_MSG_CHECKING([whether the compiler fails when given an unknown warning option])
    223 	save_CFLAGS="$CFLAGS"
    224 	CFLAGS="$CFLAGS -Wxyzzy-this-will-never-succeed-xyzzy"
    225 	AC_TRY_COMPILE(
    226 	    [],
    227 	    [return 0],
    228 	    [
    229 		AC_MSG_RESULT([no])
    230 		#
    231 		# We're assuming this is clang, where
    232 		# -Werror=unknown-warning-option is the appropriate
    233 		# option to force the compiler to fail.
    234 		#
    235 		ac_lbl_unknown_warning_option_error="-Werror=unknown-warning-option"
    236 	    ],
    237 	    [
    238 		AC_MSG_RESULT([yes])
    239 	    ])
    240 	CFLAGS="$save_CFLAGS"
    241     ])
    242 
    243 dnl
    244 dnl Check whether the compiler option specified as the second argument
    245 dnl is supported by the compiler and, if so, add it to the macro
    246 dnl specified as the first argument
    247 dnl
    248 AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
    249     [
    250 	AC_MSG_CHECKING([whether the compiler supports the $2 option])
    251 	save_CFLAGS="$CFLAGS"
    252 	CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error $2"
    253 	AC_TRY_COMPILE(
    254 	    [],
    255 	    [return 0],
    256 	    [
    257 		AC_MSG_RESULT([yes])
    258 		CFLAGS="$save_CFLAGS"
    259 		$1="$$1 $2"
    260 	    ],
    261 	    [
    262 		AC_MSG_RESULT([no])
    263 		CFLAGS="$save_CFLAGS"
    264 	    ])
    265     ])
    266 
    267 dnl
    268 dnl Check whether the compiler supports an option to generate
    269 dnl Makefile-style dependency lines
    270 dnl
    271 dnl GCC uses -M for this.  Non-GCC compilers that support this
    272 dnl use a variety of flags, including but not limited to -M.
    273 dnl
    274 dnl We test whether the flag in question is supported, as older
    275 dnl versions of compilers might not support it.
    276 dnl
    277 dnl We don't try all the possible flags, just in case some flag means
    278 dnl "generate dependencies" on one compiler but means something else
    279 dnl on another compiler.
    280 dnl
    281 dnl Most compilers that support this send the output to the standard
    282 dnl output by default.  IBM's XLC, however, supports -M but sends
    283 dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
    284 dnl to work around that, so we don't bother with XLC.
    285 dnl
    286 AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
    287     [
    288 	AC_MSG_CHECKING([whether the compiler supports generating dependencies])
    289 	if test "$GCC" = yes ; then
    290 		#
    291 		# GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
    292 		# though it's not); we assume that, in this case, the flag
    293 		# would be -M.
    294 		#
    295 		ac_lbl_dependency_flag="-M"
    296 	else
    297 		#
    298 		# Not GCC or a compiler deemed to be GCC; what platform is
    299 		# this?  (We're assuming that if the compiler isn't GCC
    300 		# it's the compiler from the vendor of the OS; that won't
    301 		# necessarily be true for x86 platforms, where it might be
    302 		# the Intel C compiler.)
    303 		#
    304 		case "$host_os" in
    305 
    306 		irix*|osf*|darwin*)
    307 			#
    308 			# MIPS C for IRIX, DEC C, and clang all use -M.
    309 			#
    310 			ac_lbl_dependency_flag="-M"
    311 			;;
    312 
    313 		solaris*)
    314 			#
    315 			# Sun C uses -xM.
    316 			#
    317 			ac_lbl_dependency_flag="-xM"
    318 			;;
    319 
    320 		hpux*)
    321 			#
    322 			# HP's older C compilers don't support this.
    323 			# HP's newer C compilers support this with
    324 			# either +M or +Make; the older compilers
    325 			# interpret +M as something completely
    326 			# different, so we use +Make so we don't
    327 			# think it works with the older compilers.
    328 			#
    329 			ac_lbl_dependency_flag="+Make"
    330 			;;
    331 
    332 		*)
    333 			#
    334 			# Not one of the above; assume no support for
    335 			# generating dependencies.
    336 			#
    337 			ac_lbl_dependency_flag=""
    338 			;;
    339 		esac
    340 	fi
    341 
    342 	#
    343 	# Is ac_lbl_dependency_flag defined and, if so, does the compiler
    344 	# complain about it?
    345 	#
    346 	# Note: clang doesn't seem to exit with an error status when handed
    347 	# an unknown non-warning error, even if you pass it
    348 	# -Werror=unknown-warning-option.  However, it always supports
    349 	# -M, so the fact that this test always succeeds with clang
    350 	# isn't an issue.
    351 	#
    352 	if test ! -z "$ac_lbl_dependency_flag"; then
    353 		AC_LANG_CONFTEST(
    354 		    [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
    355 		echo "$CC" $ac_lbl_dependency_flag conftest.c >&5
    356 		if "$CC" $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1; then
    357 			AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
    358 			DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
    359 			MKDEP='${srcdir}/mkdep'
    360 		else
    361 			AC_MSG_RESULT([no])
    362 			#
    363 			# We can't run mkdep, so have "make depend" do
    364 			# nothing.
    365 			#
    366 			MKDEP=:
    367 		fi
    368 		rm -rf conftest*
    369 	else
    370 		AC_MSG_RESULT([no])
    371 		#
    372 		# We can't run mkdep, so have "make depend" do
    373 		# nothing.
    374 		#
    375 		MKDEP=:
    376 	fi
    377 	AC_SUBST(DEPENDENCY_CFLAG)
    378 	AC_SUBST(MKDEP)
    379     ])
    380 
    381 dnl
    382 dnl Determine what options are needed to build a shared library
    383 dnl
    384 dnl usage:
    385 dnl
    386 dnl	AC_LBL_SHLIBS_INIT
    387 dnl
    388 dnl results:
    389 dnl
    390 dnl	V_CCOPT (modified to build position-independent code)
    391 dnl	V_SHLIB_CMD
    392 dnl	V_SHLIB_OPT
    393 dnl	V_SONAME_OPT
    394 dnl	V_RPATH_OPT
    395 dnl
    396 AC_DEFUN(AC_LBL_SHLIBS_INIT,
    397     [AC_PREREQ(2.50)
    398     if test "$GCC" = yes ; then
    399 	    #
    400 	    # On platforms where we build a shared library:
    401 	    #
    402 	    #	add options to generate position-independent code,
    403 	    #	if necessary (it's the default in AIX and Darwin/OS X);
    404 	    #
    405 	    #	define option to set the soname of the shared library,
    406 	    #	if the OS supports that;
    407 	    #
    408 	    #	add options to specify, at link time, a directory to
    409 	    #	add to the run-time search path, if that's necessary.
    410 	    #
    411 	    V_SHLIB_CMD="\$(CC)"
    412 	    V_SHLIB_OPT="-shared"
    413 	    case "$host_os" in
    414 
    415 	    aix*)
    416 		    ;;
    417 
    418 	    freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*)
    419 	    	    #
    420 		    # Platforms where the linker is the GNU linker
    421 		    # or accepts command-line arguments like
    422 		    # those the GNU linker accepts.
    423 		    #
    424 		    # Some instruction sets require -fPIC on some
    425 		    # operating systems.  Check for them.  If you
    426 		    # have a combination that requires it, add it
    427 		    # here.
    428 		    #
    429 		    PIC_OPT=-fpic
    430 		    case "$host_cpu" in
    431 
    432 		    sparc64*)
    433 			case "$host_os" in
    434 
    435 			freebsd*|openbsd*)
    436 			    PIC_OPT=-fPIC
    437 			    ;;
    438 			esac
    439 			;;
    440 		    esac
    441 		    V_CCOPT="$V_CCOPT $PIC_OPT"
    442 		    V_SONAME_OPT="-Wl,-soname,"
    443 		    V_RPATH_OPT="-Wl,-rpath,"
    444 		    ;;
    445 
    446 	    hpux*)
    447 		    V_CCOPT="$V_CCOPT -fpic"
    448 	    	    #
    449 		    # XXX - this assumes GCC is using the HP linker,
    450 		    # rather than the GNU linker, and that the "+h"
    451 		    # option is used on all HP-UX platforms, both .sl
    452 		    # and .so.
    453 		    #
    454 		    V_SONAME_OPT="-Wl,+h,"
    455 		    #
    456 		    # By default, directories specifed with -L
    457 		    # are added to the run-time search path, so
    458 		    # we don't add them in pcap-config.
    459 		    #
    460 		    ;;
    461 
    462 	    solaris*)
    463 		    V_CCOPT="$V_CCOPT -fpic"
    464 		    #
    465 		    # XXX - this assumes GCC is using the Sun linker,
    466 		    # rather than the GNU linker.
    467 		    #
    468 		    V_SONAME_OPT="-Wl,-h,"
    469 		    V_RPATH_OPT="-Wl,-R,"
    470 		    ;;
    471 	    esac
    472     else
    473 	    #
    474 	    # Set the appropriate compiler flags and, on platforms
    475 	    # where we build a shared library:
    476 	    #
    477 	    #	add options to generate position-independent code,
    478 	    #	if necessary (it's the default in Darwin/OS X);
    479 	    #
    480 	    #	if we generate ".so" shared libraries, define the
    481 	    #	appropriate options for building the shared library;
    482 	    #
    483 	    #	add options to specify, at link time, a directory to
    484 	    #	add to the run-time search path, if that's necessary.
    485 	    #
    486 	    # Note: spaces after V_SONAME_OPT are significant; on
    487 	    # some platforms the soname is passed with a GCC-like
    488 	    # "-Wl,-soname,{soname}" option, with the soname part
    489 	    # of the option, while on other platforms the C compiler
    490 	    # driver takes it as a regular option with the soname
    491 	    # following the option.  The same applies to V_RPATH_OPT.
    492 	    #
    493 	    case "$host_os" in
    494 
    495 	    aix*)
    496 		    V_SHLIB_CMD="\$(CC)"
    497 		    V_SHLIB_OPT="-G -bnoentry -bexpall"
    498 		    ;;
    499 
    500 	    freebsd*|netbsd*|openbsd*|dragonfly*|linux*)
    501 		    #
    502 		    # "cc" is GCC.
    503 		    #
    504 		    V_CCOPT="$V_CCOPT -fpic"
    505 		    V_SHLIB_CMD="\$(CC)"
    506 		    V_SHLIB_OPT="-shared"
    507 		    V_SONAME_OPT="-Wl,-soname,"
    508 		    V_RPATH_OPT="-Wl,-rpath,"
    509 		    ;;
    510 
    511 	    hpux*)
    512 		    V_CCOPT="$V_CCOPT +z"
    513 		    V_SHLIB_CMD="\$(LD)"
    514 		    V_SHLIB_OPT="-b"
    515 		    V_SONAME_OPT="+h "
    516 		    #
    517 		    # By default, directories specifed with -L
    518 		    # are added to the run-time search path, so
    519 		    # we don't add them in pcap-config.
    520 		    #
    521 		    ;;
    522 
    523 	    osf*)
    524 	    	    #
    525 		    # Presumed to be DEC OSF/1, Digital UNIX, or
    526 		    # Tru64 UNIX.
    527 		    #
    528 		    V_SHLIB_CMD="\$(CC)"
    529 		    V_SHLIB_OPT="-shared"
    530 		    V_SONAME_OPT="-soname "
    531 		    V_RPATH_OPT="-rpath "
    532 		    ;;
    533 
    534 	    solaris*)
    535 		    V_CCOPT="$V_CCOPT -Kpic"
    536 		    V_SHLIB_CMD="\$(CC)"
    537 		    V_SHLIB_OPT="-G"
    538 		    V_SONAME_OPT="-h "
    539 		    V_RPATH_OPT="-R"
    540 		    ;;
    541 	    esac
    542     fi
    543 ])
    544 
    545 #
    546 # Try compiling a sample of the type of code that appears in
    547 # gencode.c with "inline", "__inline__", and "__inline".
    548 #
    549 # Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
    550 # as it just tests whether a function returning "int" can be inlined;
    551 # at least some versions of HP's C compiler can inline that, but can't
    552 # inline a function that returns a struct pointer.
    553 #
    554 # Make sure we use the V_CCOPT flags, because some of those might
    555 # disable inlining.
    556 #
    557 AC_DEFUN(AC_LBL_C_INLINE,
    558     [AC_MSG_CHECKING(for inline)
    559     save_CFLAGS="$CFLAGS"
    560     CFLAGS="$V_CCOPT"
    561     AC_CACHE_VAL(ac_cv_lbl_inline, [
    562 	ac_cv_lbl_inline=""
    563 	ac_lbl_cc_inline=no
    564 	for ac_lbl_inline in inline __inline__ __inline
    565 	do
    566 	    AC_TRY_COMPILE(
    567 		[#define inline $ac_lbl_inline
    568 		static inline struct iltest *foo(void);
    569 		struct iltest {
    570 		    int iltest1;
    571 		    int iltest2;
    572 		};
    573 
    574 		static inline struct iltest *
    575 		foo()
    576 		{
    577 		    static struct iltest xxx;
    578 
    579 		    return &xxx;
    580 		}],,ac_lbl_cc_inline=yes,)
    581 	    if test "$ac_lbl_cc_inline" = yes ; then
    582 		break;
    583 	    fi
    584 	done
    585 	if test "$ac_lbl_cc_inline" = yes ; then
    586 	    ac_cv_lbl_inline=$ac_lbl_inline
    587 	fi])
    588     CFLAGS="$save_CFLAGS"
    589     if test ! -z "$ac_cv_lbl_inline" ; then
    590 	AC_MSG_RESULT($ac_cv_lbl_inline)
    591     else
    592 	AC_MSG_RESULT(no)
    593     fi
    594     AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
    595 
    596 dnl
    597 dnl If using gcc, make sure we have ANSI ioctl definitions
    598 dnl
    599 dnl usage:
    600 dnl
    601 dnl	AC_LBL_FIXINCLUDES
    602 dnl
    603 AC_DEFUN(AC_LBL_FIXINCLUDES,
    604     [if test "$GCC" = yes ; then
    605 	    AC_MSG_CHECKING(for ANSI ioctl definitions)
    606 	    AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
    607 		AC_TRY_COMPILE(
    608 		    [/*
    609 		     * This generates a "duplicate case value" when fixincludes
    610 		     * has not be run.
    611 		     */
    612 #		include <sys/types.h>
    613 #		include <sys/time.h>
    614 #		include <sys/ioctl.h>
    615 #		ifdef HAVE_SYS_IOCCOM_H
    616 #		include <sys/ioccom.h>
    617 #		endif],
    618 		    [switch (0) {
    619 		    case _IO('A', 1):;
    620 		    case _IO('B', 1):;
    621 		    }],
    622 		    ac_cv_lbl_gcc_fixincludes=yes,
    623 		    ac_cv_lbl_gcc_fixincludes=no))
    624 	    AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
    625 	    if test $ac_cv_lbl_gcc_fixincludes = no ; then
    626 		    # Don't cache failure
    627 		    unset ac_cv_lbl_gcc_fixincludes
    628 		    AC_MSG_ERROR(see the INSTALL for more info)
    629 	    fi
    630     fi])
    631 
    632 dnl
    633 dnl Check for flex, default to lex
    634 dnl Require flex 2.4 or higher
    635 dnl Check for bison, default to yacc
    636 dnl Default to lex/yacc if both flex and bison are not available
    637 dnl
    638 dnl If we're using flex and bison, pass -P to flex and -p to bison
    639 dnl to define a prefix string for the lexer and parser
    640 dnl
    641 dnl If we're not using flex and bison, don't pass those options
    642 dnl (as they might not work - although if "lex" is a wrapper for
    643 dnl Flex and "yacc" is a wrapper for Bison, they will work), and
    644 dnl define NEED_YYPARSE_WRAPPER (we *CANNOT* use YYBISON to check
    645 dnl whether the wrapper is needed, as some people apparently, for
    646 dnl some unknown reason, choose to use --without-flex and
    647 dnl --without-bison on systems that have Flex and Bison, which
    648 dnl means that the "yacc" they end up using is a wrapper that
    649 dnl runs "bison -y", and at least some versions of Bison define
    650 dnl YYBISON even if run with "-y", so we end up not compiling
    651 dnl the yyparse wrapper and end up with a libpcap that doesn't
    652 dnl define pcap_parse())
    653 dnl
    654 dnl usage:
    655 dnl
    656 dnl	AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix)
    657 dnl
    658 dnl results:
    659 dnl
    660 dnl	$1 (lex set)
    661 dnl	$2 (yacc appended)
    662 dnl	$3 (optional flex and bison -P prefix)
    663 dnl
    664 AC_DEFUN(AC_LBL_LEX_AND_YACC,
    665     [AC_ARG_WITH(flex, [  --without-flex          don't use flex])
    666     AC_ARG_WITH(bison, [  --without-bison         don't use bison])
    667     if test "$with_flex" = no ; then
    668 	    $1=lex
    669     else
    670 	    AC_CHECK_PROGS($1, flex, lex)
    671     fi
    672     if test "$$1" = flex ; then
    673 	    # The -V flag was added in 2.4
    674 	    AC_MSG_CHECKING(for flex 2.4 or higher)
    675 	    AC_CACHE_VAL(ac_cv_lbl_flex_v24,
    676 		if flex -V >/dev/null 2>&1; then
    677 			ac_cv_lbl_flex_v24=yes
    678 		else
    679 			ac_cv_lbl_flex_v24=no
    680 		fi)
    681 	    AC_MSG_RESULT($ac_cv_lbl_flex_v24)
    682 	    if test $ac_cv_lbl_flex_v24 = no ; then
    683 		    s="2.4 or higher required"
    684 		    AC_MSG_WARN(ignoring obsolete flex executable ($s))
    685 		    $1=lex
    686 	    fi
    687     fi
    688     if test "$with_bison" = no ; then
    689 	    $2=yacc
    690     else
    691 	    AC_CHECK_PROGS($2, bison, yacc)
    692     fi
    693     if test "$$2" = bison ; then
    694 	    $2="$$2 -y"
    695     fi
    696     if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then
    697 	    AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc)
    698 	    $1=lex
    699 	    $2=yacc
    700     fi
    701     if test "$$1" = flex -a -n "$3" ; then
    702 	    $1="$$1 -P$3"
    703 	    $2="$$2 -p $3"
    704     else
    705 	    AC_DEFINE(NEED_YYPARSE_WRAPPER,1,[if we need a pcap_parse wrapper around yyparse])
    706     fi])
    707 
    708 dnl
    709 dnl Checks to see if union wait is used with WEXITSTATUS()
    710 dnl
    711 dnl usage:
    712 dnl
    713 dnl	AC_LBL_UNION_WAIT
    714 dnl
    715 dnl results:
    716 dnl
    717 dnl	DECLWAITSTATUS (defined)
    718 dnl
    719 AC_DEFUN(AC_LBL_UNION_WAIT,
    720     [AC_MSG_CHECKING(if union wait is used)
    721     AC_CACHE_VAL(ac_cv_lbl_union_wait,
    722 	AC_TRY_COMPILE([
    723 #	include <sys/types.h>
    724 #	include <sys/wait.h>],
    725 	    [int status;
    726 	    u_int i = WEXITSTATUS(status);
    727 	    u_int j = waitpid(0, &status, 0);],
    728 	    ac_cv_lbl_union_wait=no,
    729 	    ac_cv_lbl_union_wait=yes))
    730     AC_MSG_RESULT($ac_cv_lbl_union_wait)
    731     if test $ac_cv_lbl_union_wait = yes ; then
    732 	    AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
    733     else
    734 	    AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
    735     fi])
    736 
    737 dnl
    738 dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
    739 dnl
    740 dnl usage:
    741 dnl
    742 dnl	AC_LBL_SOCKADDR_SA_LEN
    743 dnl
    744 dnl results:
    745 dnl
    746 dnl	HAVE_SOCKADDR_SA_LEN (defined)
    747 dnl
    748 AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
    749     [AC_MSG_CHECKING(if sockaddr struct has the sa_len member)
    750     AC_CACHE_VAL(ac_cv_lbl_sockaddr_has_sa_len,
    751 	AC_TRY_COMPILE([
    752 #	include <sys/types.h>
    753 #	include <sys/socket.h>],
    754 	[u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
    755 	ac_cv_lbl_sockaddr_has_sa_len=yes,
    756 	ac_cv_lbl_sockaddr_has_sa_len=no))
    757     AC_MSG_RESULT($ac_cv_lbl_sockaddr_has_sa_len)
    758     if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then
    759 	    AC_DEFINE(HAVE_SOCKADDR_SA_LEN,1,[if struct sockaddr has the sa_len member])
    760     fi])
    761 
    762 dnl
    763 dnl Checks to see if there's a sockaddr_storage structure
    764 dnl
    765 dnl usage:
    766 dnl
    767 dnl	AC_LBL_SOCKADDR_STORAGE
    768 dnl
    769 dnl results:
    770 dnl
    771 dnl	HAVE_SOCKADDR_STORAGE (defined)
    772 dnl
    773 AC_DEFUN(AC_LBL_SOCKADDR_STORAGE,
    774     [AC_MSG_CHECKING(if sockaddr_storage struct exists)
    775     AC_CACHE_VAL(ac_cv_lbl_has_sockaddr_storage,
    776 	AC_TRY_COMPILE([
    777 #	include <sys/types.h>
    778 #	include <sys/socket.h>],
    779 	[u_int i = sizeof (struct sockaddr_storage)],
    780 	ac_cv_lbl_has_sockaddr_storage=yes,
    781 	ac_cv_lbl_has_sockaddr_storage=no))
    782     AC_MSG_RESULT($ac_cv_lbl_has_sockaddr_storage)
    783     if test $ac_cv_lbl_has_sockaddr_storage = yes ; then
    784 	    AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[if struct sockaddr_storage exists])
    785     fi])
    786 
    787 dnl
    788 dnl Checks to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
    789 dnl dl_module_id_1 member
    790 dnl
    791 dnl usage:
    792 dnl
    793 dnl	AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1
    794 dnl
    795 dnl results:
    796 dnl
    797 dnl	HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1 (defined)
    798 dnl
    799 dnl NOTE: any compile failure means we conclude that it doesn't have
    800 dnl that member, so if we don't have DLPI, don't have a <sys/dlpi_ext.h>
    801 dnl header, or have one that doesn't declare a dl_hp_ppa_info_t type,
    802 dnl we conclude it doesn't have that member (which is OK, as either we
    803 dnl won't be using code that would use that member, or we wouldn't
    804 dnl compile in any case).
    805 dnl
    806 AC_DEFUN(AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1,
    807     [AC_MSG_CHECKING(if dl_hp_ppa_info_t struct has dl_module_id_1 member)
    808     AC_CACHE_VAL(ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1,
    809 	AC_TRY_COMPILE([
    810 #	include <sys/types.h>
    811 #	include <sys/dlpi.h>
    812 #	include <sys/dlpi_ext.h>],
    813 	[u_int i = sizeof(((dl_hp_ppa_info_t *)0)->dl_module_id_1)],
    814 	ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=yes,
    815 	ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=no))
    816     AC_MSG_RESULT($ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1)
    817     if test $ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1 = yes ; then
    818 	    AC_DEFINE(HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1,1,[if ppa_info_t_dl_module_id exists])
    819     fi])
    820 
    821 dnl
    822 dnl Checks to see if -R is used
    823 dnl
    824 dnl usage:
    825 dnl
    826 dnl	AC_LBL_HAVE_RUN_PATH
    827 dnl
    828 dnl results:
    829 dnl
    830 dnl	ac_cv_lbl_have_run_path (yes or no)
    831 dnl
    832 AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
    833     [AC_MSG_CHECKING(for ${CC-cc} -R)
    834     AC_CACHE_VAL(ac_cv_lbl_have_run_path,
    835 	[echo 'main(){}' > conftest.c
    836 	${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
    837 	if test ! -s conftest.out ; then
    838 		ac_cv_lbl_have_run_path=yes
    839 	else
    840 		ac_cv_lbl_have_run_path=no
    841 	fi
    842 	rm -f -r conftest*])
    843     AC_MSG_RESULT($ac_cv_lbl_have_run_path)
    844     ])
    845 
    846 dnl
    847 dnl Checks to see if unaligned memory accesses fail
    848 dnl
    849 dnl usage:
    850 dnl
    851 dnl	AC_LBL_UNALIGNED_ACCESS
    852 dnl
    853 dnl results:
    854 dnl
    855 dnl	LBL_ALIGN (DEFINED)
    856 dnl
    857 AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
    858     [AC_MSG_CHECKING(if unaligned accesses fail)
    859     AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
    860 	[case "$host_cpu" in
    861 
    862 	#
    863 	# These are CPU types where:
    864 	#
    865 	#	the CPU faults on an unaligned access, but at least some
    866 	#	OSes that support that CPU catch the fault and simulate
    867 	#	the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
    868 	#	the simulation is slow, so we don't want to use it;
    869 	#
    870 	#	the CPU, I infer (from the old
    871 	#
    872 	# XXX: should also check that they don't do weird things (like on arm)
    873 	#
    874 	#	comment) doesn't fault on unaligned accesses, but doesn't
    875 	#	do a normal unaligned fetch, either (e.g., presumably, ARM);
    876 	#
    877 	#	for whatever reason, the test program doesn't work
    878 	#	(this has been claimed to be the case for several of those
    879 	#	CPUs - I don't know what the problem is; the problem
    880 	#	was reported as "the test program dumps core" for SuperH,
    881 	#	but that's what the test program is *supposed* to do -
    882 	#	it dumps core before it writes anything, so the test
    883 	#	for an empty output file should find an empty output
    884 	#	file and conclude that unaligned accesses don't work).
    885 	#
    886 	# This run-time test won't work if you're cross-compiling, so
    887 	# in order to support cross-compiling for a particular CPU,
    888 	# we have to wire in the list of CPU types anyway, as far as
    889 	# I know, so perhaps we should just have a set of CPUs on
    890 	# which we know it doesn't work, a set of CPUs on which we
    891 	# know it does work, and have the script just fail on other
    892 	# cpu types and update it when such a failure occurs.
    893 	#
    894 	alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1)
    895 		ac_cv_lbl_unaligned_fail=yes
    896 		;;
    897 
    898 	*)
    899 		cat >conftest.c <<EOF
    900 #		include <sys/types.h>
    901 #		include <sys/wait.h>
    902 #		include <stdio.h>
    903 		unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
    904 		main() {
    905 		unsigned int i;
    906 		pid_t pid;
    907 		int status;
    908 		/* avoid "core dumped" message */
    909 		pid = fork();
    910 		if (pid <  0)
    911 			exit(2);
    912 		if (pid > 0) {
    913 			/* parent */
    914 			pid = waitpid(pid, &status, 0);
    915 			if (pid < 0)
    916 				exit(3);
    917 			exit(!WIFEXITED(status));
    918 		}
    919 		/* child */
    920 		i = *(unsigned int *)&a[[1]];
    921 		printf("%d\n", i);
    922 		exit(0);
    923 		}
    924 EOF
    925 		${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
    926 		    conftest.c $LIBS >/dev/null 2>&1
    927 		if test ! -x conftest ; then
    928 			dnl failed to compile for some reason
    929 			ac_cv_lbl_unaligned_fail=yes
    930 		else
    931 			./conftest >conftest.out
    932 			if test ! -s conftest.out ; then
    933 				ac_cv_lbl_unaligned_fail=yes
    934 			else
    935 				ac_cv_lbl_unaligned_fail=no
    936 			fi
    937 		fi
    938 		rm -f -r conftest* core core.conftest
    939 		;;
    940 	esac])
    941     AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
    942     if test $ac_cv_lbl_unaligned_fail = yes ; then
    943 	    AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails])
    944     fi])
    945 
    946 dnl
    947 dnl If the file .devel exists:
    948 dnl	Add some warning flags if the compiler supports them
    949 dnl	If an os prototype include exists, symlink os-proto.h to it
    950 dnl
    951 dnl usage:
    952 dnl
    953 dnl	AC_LBL_DEVEL(copt)
    954 dnl
    955 dnl results:
    956 dnl
    957 dnl	$1 (copt appended)
    958 dnl	HAVE_OS_PROTO_H (defined)
    959 dnl	os-proto.h (symlinked)
    960 dnl
    961 AC_DEFUN(AC_LBL_DEVEL,
    962     [rm -f os-proto.h
    963     if test "${LBL_CFLAGS+set}" = set; then
    964 	    $1="$$1 ${LBL_CFLAGS}"
    965     fi
    966     if test -f .devel ; then
    967 	    #
    968 	    # Skip all the warning option stuff on some compilers.
    969 	    #
    970 	    if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
    971 		    AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR()
    972 		    AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
    973 		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
    974 		    AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
    975 	    fi
    976 	    AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
    977 	    #
    978 	    # We used to set -n32 for IRIX 6 when not using GCC (presumed
    979 	    # to mean that we're using MIPS C or MIPSpro C); it specified
    980 	    # the "new" faster 32-bit ABI, introduced in IRIX 6.2.  I'm
    981 	    # not sure why that would be something to do *only* with a
    982 	    # .devel file; why should the ABI for which we produce code
    983 	    # depend on .devel?
    984 	    #
    985 	    os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
    986 	    name="lbl/os-$os.h"
    987 	    if test -f $name ; then
    988 		    ln -s $name os-proto.h
    989 		    AC_DEFINE(HAVE_OS_PROTO_H, 1,
    990 			[if there's an os_proto.h for this platform, to use additional prototypes])
    991 	    else
    992 		    AC_MSG_WARN(can't find $name)
    993 	    fi
    994     fi])
    995 
    996 dnl
    997 dnl Improved version of AC_CHECK_LIB
    998 dnl
    999 dnl Thanks to John Hawkinson (jhawk (a] mit.edu)
   1000 dnl
   1001 dnl usage:
   1002 dnl
   1003 dnl	AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
   1004 dnl	    ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
   1005 dnl
   1006 dnl results:
   1007 dnl
   1008 dnl	LIBS
   1009 dnl
   1010 dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
   1011 dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
   1012 dnl We keep it around for reference purposes in case it's ever
   1013 dnl useful in the future.
   1014 dnl
   1015 
   1016 define(AC_LBL_CHECK_LIB,
   1017 [AC_MSG_CHECKING([for $2 in -l$1])
   1018 dnl Use a cache variable name containing the library, function
   1019 dnl name, and extra libraries to link with, because the test really is
   1020 dnl for library $1 defining function $2, when linked with potinal
   1021 dnl library $5, not just for library $1.  Separate tests with the same
   1022 dnl $1 and different $2's or $5's may have different results.
   1023 ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
   1024 AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
   1025 [ac_save_LIBS="$LIBS"
   1026 LIBS="-l$1 $5 $LIBS"
   1027 AC_TRY_LINK(dnl
   1028 ifelse([$2], [main], , dnl Avoid conflicting decl of main.
   1029 [/* Override any gcc2 internal prototype to avoid an error.  */
   1030 ]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
   1031 extern "C"
   1032 #endif
   1033 ])dnl
   1034 [/* We use char because int might match the return type of a gcc2
   1035     builtin and then its argument prototype would still apply.  */
   1036 char $2();
   1037 ]),
   1038 	    [$2()],
   1039 	    eval "ac_cv_lbl_lib_$ac_lib_var=yes",
   1040 	    eval "ac_cv_lbl_lib_$ac_lib_var=no")
   1041 LIBS="$ac_save_LIBS"
   1042 ])dnl
   1043 if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
   1044   AC_MSG_RESULT(yes)
   1045   ifelse([$3], ,
   1046 [changequote(, )dnl
   1047   ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
   1048     -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
   1049 changequote([, ])dnl
   1050   AC_DEFINE_UNQUOTED($ac_tr_lib)
   1051   LIBS="-l$1 $LIBS"
   1052 ], [$3])
   1053 else
   1054   AC_MSG_RESULT(no)
   1055 ifelse([$4], , , [$4
   1056 ])dnl
   1057 fi
   1058 ])
   1059 
   1060 dnl
   1061 dnl AC_LBL_LIBRARY_NET
   1062 dnl
   1063 dnl This test is for network applications that need socket() and
   1064 dnl gethostbyname() -ish functions.  Under Solaris, those applications
   1065 dnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
   1066 dnl with "-lnsl" but should *not* link with "-lsocket" because
   1067 dnl libsocket.a breaks a number of things (for instance:
   1068 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
   1069 dnl versions of IRIX).
   1070 dnl
   1071 dnl Unfortunately, many application developers are not aware of this,
   1072 dnl and mistakenly write tests that cause -lsocket to be used under
   1073 dnl IRIX.  It is also easy to write tests that cause -lnsl to be used
   1074 dnl under operating systems where neither are necessary (or useful),
   1075 dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
   1076 dnl
   1077 dnl This test exists so that every application developer does not test
   1078 dnl this in a different, and subtly broken fashion.
   1079 
   1080 dnl It has been argued that this test should be broken up into two
   1081 dnl seperate tests, one for the resolver libraries, and one for the
   1082 dnl libraries necessary for using Sockets API. Unfortunately, the two
   1083 dnl are carefully intertwined and allowing the autoconf user to use
   1084 dnl them independantly potentially results in unfortunate ordering
   1085 dnl dependancies -- as such, such component macros would have to
   1086 dnl carefully use indirection and be aware if the other components were
   1087 dnl executed. Since other autoconf macros do not go to this trouble,
   1088 dnl and almost no applications use sockets without the resolver, this
   1089 dnl complexity has not been implemented.
   1090 dnl
   1091 dnl The check for libresolv is in case you are attempting to link
   1092 dnl statically and happen to have a libresolv.a lying around (and no
   1093 dnl libnsl.a).
   1094 dnl
   1095 AC_DEFUN(AC_LBL_LIBRARY_NET, [
   1096     # Most operating systems have gethostbyname() in the default searched
   1097     # libraries (i.e. libc):
   1098     # Some OSes (eg. Solaris) place it in libnsl
   1099     # Some strange OSes (SINIX) have it in libsocket:
   1100     AC_SEARCH_LIBS(gethostbyname, nsl socket resolv)
   1101     # Unfortunately libsocket sometimes depends on libnsl and
   1102     # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
   1103     if test "$ac_cv_search_gethostbyname" = "no"
   1104     then
   1105 	AC_CHECK_LIB(socket, gethostbyname,
   1106                      LIBS="-lsocket -lnsl $LIBS", , -lnsl)
   1107     fi
   1108     AC_SEARCH_LIBS(socket, socket, ,
   1109 	AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
   1110     # DLPI needs putmsg under HPUX so test for -lstr while we're at it
   1111     AC_SEARCH_LIBS(putmsg, str)
   1112     ])
   1113 
   1114 dnl
   1115 dnl Test for __attribute__
   1116 dnl
   1117 
   1118 AC_DEFUN(AC_C___ATTRIBUTE__, [
   1119 AC_MSG_CHECKING(for __attribute__)
   1120 AC_CACHE_VAL(ac_cv___attribute__, [
   1121 AC_COMPILE_IFELSE([
   1122   AC_LANG_SOURCE([[
   1123 #include <stdlib.h>
   1124 
   1125 static void foo(void) __attribute__ ((noreturn));
   1126 
   1127 static void
   1128 foo(void)
   1129 {
   1130   exit(1);
   1131 }
   1132 
   1133 int
   1134 main(int argc, char **argv)
   1135 {
   1136   foo();
   1137 }
   1138   ]])],
   1139 ac_cv___attribute__=yes,
   1140 ac_cv___attribute__=no)])
   1141 if test "$ac_cv___attribute__" = "yes"; then
   1142   AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
   1143 else
   1144   #
   1145   # We can't use __attribute__, so we can't use __attribute__((unused)),
   1146   # so we define _U_ to an empty string.
   1147   #
   1148   V_DEFS="$V_DEFS -D_U_=\"\""
   1149 fi
   1150 AC_MSG_RESULT($ac_cv___attribute__)
   1151 ])
   1152 
   1153 dnl
   1154 dnl Test whether __attribute__((unused)) can be used without warnings
   1155 dnl
   1156 
   1157 AC_DEFUN(AC_C___ATTRIBUTE___UNUSED, [
   1158 AC_MSG_CHECKING([whether __attribute__((unused)) can be used without warnings])
   1159 AC_CACHE_VAL(ac_cv___attribute___unused, [
   1160 save_CFLAGS="$CFLAGS"
   1161 CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
   1162 AC_COMPILE_IFELSE([
   1163   AC_LANG_SOURCE([[
   1164 #include <stdlib.h>
   1165 #include <stdio.h>
   1166 
   1167 int
   1168 main(int argc  __attribute((unused)), char **argv __attribute((unused)))
   1169 {
   1170   printf("Hello, world!\n");
   1171   return 0;
   1172 }
   1173   ]])],
   1174 ac_cv___attribute___unused=yes,
   1175 ac_cv___attribute___unused=no)])
   1176 CFLAGS="$save_CFLAGS"
   1177 if test "$ac_cv___attribute___unused" = "yes"; then
   1178   V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
   1179 else
   1180   V_DEFS="$V_DEFS -D_U_=\"\""
   1181 fi
   1182 AC_MSG_RESULT($ac_cv___attribute___unused)
   1183 ])
   1184 
   1185 dnl
   1186 dnl Test whether __attribute__((format)) can be used without warnings
   1187 dnl
   1188 
   1189 AC_DEFUN(AC_C___ATTRIBUTE___FORMAT, [
   1190 AC_MSG_CHECKING([whether __attribute__((format)) can be used without warnings])
   1191 AC_CACHE_VAL(ac_cv___attribute___format, [
   1192 save_CFLAGS="$CFLAGS"
   1193 CFLAGS="$CFLAGS $ac_lbl_cc_force_warning_errors"
   1194 AC_COMPILE_IFELSE([
   1195   AC_LANG_SOURCE([[
   1196 #include <stdlib.h>
   1197 
   1198 extern int foo(const char *fmt, ...)
   1199 		  __attribute__ ((format (printf, 1, 2)));
   1200 
   1201 int
   1202 main(int argc, char **argv)
   1203 {
   1204   foo("%s", "test");
   1205 }
   1206   ]])],
   1207 ac_cv___attribute___format=yes,
   1208 ac_cv___attribute___format=no)])
   1209 CFLAGS="$save_CFLAGS"
   1210 if test "$ac_cv___attribute___format" = "yes"; then
   1211   AC_DEFINE(__ATTRIBUTE___FORMAT_OK, 1,
   1212     [define if your compiler allows __attribute__((format)) without a warning])
   1213 fi
   1214 AC_MSG_RESULT($ac_cv___attribute___format)
   1215 ])
   1216 
   1217 dnl
   1218 dnl Checks to see if tpacket_stats is defined in linux/if_packet.h
   1219 dnl If so then pcap-linux.c can use this to report proper statistics.
   1220 dnl
   1221 dnl -Scott Barron
   1222 dnl
   1223 AC_DEFUN(AC_LBL_TPACKET_STATS,
   1224    [AC_MSG_CHECKING(if if_packet.h has tpacket_stats defined)
   1225    AC_CACHE_VAL(ac_cv_lbl_tpacket_stats,
   1226    AC_TRY_COMPILE([
   1227 #  include <linux/if_packet.h>],
   1228    [struct tpacket_stats stats],
   1229    ac_cv_lbl_tpacket_stats=yes,
   1230    ac_cv_lbl_tpacket_stats=no))
   1231    AC_MSG_RESULT($ac_cv_lbl_tpacket_stats)
   1232    if test $ac_cv_lbl_tpacket_stats = yes; then
   1233        AC_DEFINE(HAVE_TPACKET_STATS,1,[if if_packet.h has tpacket_stats defined])
   1234    fi])
   1235 
   1236 dnl
   1237 dnl Checks to see if the tpacket_auxdata struct has a tp_vlan_tci member.
   1238 dnl
   1239 dnl usage:
   1240 dnl
   1241 dnl	AC_LBL_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI
   1242 dnl
   1243 dnl results:
   1244 dnl
   1245 dnl	HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI (defined)
   1246 dnl
   1247 dnl NOTE: any compile failure means we conclude that it doesn't have
   1248 dnl that member, so if we don't have tpacket_auxdata, we conclude it
   1249 dnl doesn't have that member (which is OK, as either we won't be using
   1250 dnl code that would use that member, or we wouldn't compile in any case).
   1251 dnl
   1252 AC_DEFUN(AC_LBL_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI,
   1253     [AC_MSG_CHECKING(if tpacket_auxdata struct has tp_vlan_tci member)
   1254     AC_CACHE_VAL(ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci,
   1255 	AC_TRY_COMPILE([
   1256 #	include <sys/types.h>
   1257 #	include <linux/if_packet.h>],
   1258 	[u_int i = sizeof(((struct tpacket_auxdata *)0)->tp_vlan_tci)],
   1259 	ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci=yes,
   1260 	ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci=no))
   1261     AC_MSG_RESULT($ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci)
   1262     if test $ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci = yes ; then
   1263 	    HAVE_LINUX_TPACKET_AUXDATA=tp_vlan_tci
   1264 	    AC_SUBST(HAVE_LINUX_TPACKET_AUXDATA)
   1265 	    AC_DEFINE(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI,1,[if tp_vlan_tci exists])
   1266     fi])
   1267 
   1268 dnl
   1269 dnl Checks to see if Solaris has the dl_passive_req_t struct defined
   1270 dnl in <sys/dlpi.h>.
   1271 dnl
   1272 dnl usage:
   1273 dnl
   1274 dnl	AC_LBL_DL_PASSIVE_REQ_T
   1275 dnl
   1276 dnl results:
   1277 dnl
   1278 dnl 	HAVE_DLPI_PASSIVE (defined)
   1279 dnl
   1280 AC_DEFUN(AC_LBL_DL_PASSIVE_REQ_T,
   1281         [AC_MSG_CHECKING(if dl_passive_req_t struct exists)
   1282        AC_CACHE_VAL(ac_cv_lbl_has_dl_passive_req_t,
   1283                 AC_TRY_COMPILE([
   1284 #       include <sys/types.h>
   1285 #       include <sys/dlpi.h>],
   1286         [u_int i = sizeof(dl_passive_req_t)],
   1287         ac_cv_lbl_has_dl_passive_req_t=yes,
   1288         ac_cv_lbl_has_dl_passive_req_t=no))
   1289     AC_MSG_RESULT($ac_cv_lbl_has_dl_passive_req_t)
   1290     if test $ac_cv_lbl_has_dl_passive_req_t = yes ; then
   1291             AC_DEFINE(HAVE_DLPI_PASSIVE,1,[if passive_req_t primitive
   1292 		exists])
   1293     fi])
   1294