• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl Copyright (c) 1995, 1996, 1997, 1998
2dnl	The Regents of the University of California.  All rights reserved.
3dnl
4dnl Redistribution and use in source and binary forms, with or without
5dnl modification, are permitted provided that: (1) source code distributions
6dnl retain the above copyright notice and this paragraph in its entirety, (2)
7dnl distributions including binary code include the above copyright notice and
8dnl this paragraph in its entirety in the documentation or other materials
9dnl provided with the distribution, and (3) all advertising materials mentioning
10dnl features or use of this software display the following acknowledgement:
11dnl ``This product includes software developed by the University of California,
12dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13dnl the University nor the names of its contributors may be used to endorse
14dnl or promote products derived from this software without specific prior
15dnl written permission.
16dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19dnl
20dnl LBL autoconf macros
21dnl
22
23dnl
24dnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
25dnl
26dnl It appears that newer versions of autoconf (2.64 and later) will,
27dnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the
28dnl beginning of the macro, even if the macro itself calls AC_PROG_CC.
29dnl See the "Prerequisite Macros" and "Expanded Before Required" sections
30dnl in the Autoconf documentation.
31dnl
32dnl This causes a steaming heap of fail in our case, as we were, in
33dnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC,
34dnl calling AC_PROG_CC, and then doing the tests we now do in
35dnl AC_LBL_C_INIT.  Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC,
36dnl and AC_LBL_C_INIT at the top level.
37dnl
38AC_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
70dnl
71dnl Determine which compiler we're using (cc or gcc)
72dnl If using gcc, determine the version number
73dnl If using cc:
74dnl     require that it support ansi prototypes
75dnl     use -O (AC_PROG_CC will use -g -O2 on gcc, so we don't need to
76dnl     do that ourselves for gcc)
77dnl     add -g flags, as appropriate
78dnl     explicitly specify /usr/local/include
79dnl
80dnl NOTE WELL: with newer versions of autoconf, "gcc" means any compiler
81dnl that defines __GNUC__, which means clang, for example, counts as "gcc".
82dnl
83dnl usage:
84dnl
85dnl	AC_LBL_C_INIT(copt, incls)
86dnl
87dnl results:
88dnl
89dnl	$1 (copt set)
90dnl	$2 (incls set)
91dnl	CC
92dnl	LDFLAGS
93dnl	LBL_CFLAGS
94dnl
95AC_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
213dnl
214dnl Check whether, if you pass an unknown warning option to the
215dnl compiler, it fails or just prints a warning message and succeeds.
216dnl Set ac_lbl_unknown_warning_option_error to the appropriate flag
217dnl to force an error if it would otherwise just print a warning message
218dnl and succeed.
219dnl
220AC_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
243dnl
244dnl Check whether the compiler option specified as the second argument
245dnl is supported by the compiler and, if so, add it to the macro
246dnl specified as the first argument
247dnl
248AC_DEFUN(AC_LBL_CHECK_COMPILER_OPT,
249    [
250	AC_MSG_CHECKING([whether the compiler supports the $2 option])
251	save_CFLAGS="$CFLAGS"
252	if expr "x$2" : "x-W.*" >/dev/null
253	then
254	    CFLAGS="$CFLAGS $ac_lbl_unknown_warning_option_error $2"
255	elif expr "x$2" : "x-f.*" >/dev/null
256	then
257	    CFLAGS="$CFLAGS -Werror $2"
258	elif expr "x$2" : "x-m.*" >/dev/null
259	then
260	    CFLAGS="$CFLAGS -Werror $2"
261	else
262	    CFLAGS="$CFLAGS $2"
263	fi
264	AC_TRY_COMPILE(
265	    [],
266	    [return 0],
267	    [
268		AC_MSG_RESULT([yes])
269		CFLAGS="$save_CFLAGS"
270		$1="$$1 $2"
271	    ],
272	    [
273		AC_MSG_RESULT([no])
274		CFLAGS="$save_CFLAGS"
275	    ])
276    ])
277
278dnl
279dnl Check whether the compiler supports an option to generate
280dnl Makefile-style dependency lines
281dnl
282dnl GCC uses -M for this.  Non-GCC compilers that support this
283dnl use a variety of flags, including but not limited to -M.
284dnl
285dnl We test whether the flag in question is supported, as older
286dnl versions of compilers might not support it.
287dnl
288dnl We don't try all the possible flags, just in case some flag means
289dnl "generate dependencies" on one compiler but means something else
290dnl on another compiler.
291dnl
292dnl Most compilers that support this send the output to the standard
293dnl output by default.  IBM's XLC, however, supports -M but sends
294dnl the output to {sourcefile-basename}.u, and AIX has no /dev/stdout
295dnl to work around that, so we don't bother with XLC.
296dnl
297AC_DEFUN(AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT,
298    [
299	AC_MSG_CHECKING([whether the compiler supports generating dependencies])
300	if test "$GCC" = yes ; then
301		#
302		# GCC, or a compiler deemed to be GCC by AC_PROG_CC (even
303		# though it's not); we assume that, in this case, the flag
304		# would be -M.
305		#
306		ac_lbl_dependency_flag="-M"
307	else
308		#
309		# Not GCC or a compiler deemed to be GCC; what platform is
310		# this?  (We're assuming that if the compiler isn't GCC
311		# it's the compiler from the vendor of the OS; that won't
312		# necessarily be true for x86 platforms, where it might be
313		# the Intel C compiler.)
314		#
315		case "$host_os" in
316
317		irix*|osf*|darwin*)
318			#
319			# MIPS C for IRIX, DEC C, and clang all use -M.
320			#
321			ac_lbl_dependency_flag="-M"
322			;;
323
324		solaris*)
325			#
326			# Sun C uses -xM.
327			#
328			ac_lbl_dependency_flag="-xM"
329			;;
330
331		hpux*)
332			#
333			# HP's older C compilers don't support this.
334			# HP's newer C compilers support this with
335			# either +M or +Make; the older compilers
336			# interpret +M as something completely
337			# different, so we use +Make so we don't
338			# think it works with the older compilers.
339			#
340			ac_lbl_dependency_flag="+Make"
341			;;
342
343		*)
344			#
345			# Not one of the above; assume no support for
346			# generating dependencies.
347			#
348			ac_lbl_dependency_flag=""
349			;;
350		esac
351	fi
352
353	#
354	# Is ac_lbl_dependency_flag defined and, if so, does the compiler
355	# complain about it?
356	#
357	# Note: clang doesn't seem to exit with an error status when handed
358	# an unknown non-warning error, even if you pass it
359	# -Werror=unknown-warning-option.  However, it always supports
360	# -M, so the fact that this test always succeeds with clang
361	# isn't an issue.
362	#
363	if test ! -z "$ac_lbl_dependency_flag"; then
364		AC_LANG_CONFTEST(
365		    [AC_LANG_SOURCE([[int main(void) { return 0; }]])])
366		if AC_RUN_LOG([eval "$CC $ac_lbl_dependency_flag conftest.c >/dev/null 2>&1"]); then
367			AC_MSG_RESULT([yes, with $ac_lbl_dependency_flag])
368			DEPENDENCY_CFLAG="$ac_lbl_dependency_flag"
369			MKDEP='${top_srcdir}/mkdep'
370		else
371			AC_MSG_RESULT([no])
372			#
373			# We can't run mkdep, so have "make depend" do
374			# nothing.
375			#
376			MKDEP=:
377		fi
378		rm -rf conftest*
379	else
380		AC_MSG_RESULT([no])
381		#
382		# We can't run mkdep, so have "make depend" do
383		# nothing.
384		#
385		MKDEP=:
386	fi
387	AC_SUBST(DEPENDENCY_CFLAG)
388	AC_SUBST(MKDEP)
389    ])
390
391#
392# Try compiling a sample of the type of code that appears in
393# gencode.c with "inline", "__inline__", and "__inline".
394#
395# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
396# as it just tests whether a function returning "int" can be inlined;
397# at least some versions of HP's C compiler can inline that, but can't
398# inline a function that returns a struct pointer.
399#
400# Make sure we use the V_CCOPT flags, because some of those might
401# disable inlining.
402#
403AC_DEFUN(AC_LBL_C_INLINE,
404    [AC_MSG_CHECKING(for inline)
405    save_CFLAGS="$CFLAGS"
406    CFLAGS="$V_CCOPT"
407    AC_CACHE_VAL(ac_cv_lbl_inline, [
408	ac_cv_lbl_inline=""
409	ac_lbl_cc_inline=no
410	for ac_lbl_inline in inline __inline__ __inline
411	do
412	    AC_TRY_COMPILE(
413		[#define inline $ac_lbl_inline
414		static inline struct iltest *foo(void);
415		struct iltest {
416		    int iltest1;
417		    int iltest2;
418		};
419
420		static inline struct iltest *
421		foo()
422		{
423		    static struct iltest xxx;
424
425		    return &xxx;
426		}],,ac_lbl_cc_inline=yes,)
427	    if test "$ac_lbl_cc_inline" = yes ; then
428		break;
429	    fi
430	done
431	if test "$ac_lbl_cc_inline" = yes ; then
432	    ac_cv_lbl_inline=$ac_lbl_inline
433	fi])
434    CFLAGS="$save_CFLAGS"
435    if test ! -z "$ac_cv_lbl_inline" ; then
436	AC_MSG_RESULT($ac_cv_lbl_inline)
437    else
438	AC_MSG_RESULT(no)
439    fi
440    AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
441
442dnl
443dnl Use pfopen.c if available and pfopen() not in standard libraries
444dnl Require libpcap
445dnl Look for libpcap in directories under ..; those are local versions.
446dnl Look for an installed libpcap if there is no local version or if
447dnl the user said not to look for a local version.
448dnl
449dnl usage:
450dnl
451dnl	AC_LBL_LIBPCAP(pcapdep, incls)
452dnl
453dnl results:
454dnl
455dnl	$1 (pcapdep set)
456dnl	$2 (incls appended)
457dnl	LIBS
458dnl	LBL_LIBS
459dnl
460AC_DEFUN(AC_LBL_LIBPCAP,
461    [AC_REQUIRE([AC_LBL_LIBRARY_NET])
462    dnl
463    dnl save a copy before locating libpcap.a
464    dnl
465    LBL_LIBS="$LIBS"
466    pfopen=/usr/examples/packetfilter/pfopen.c
467    if test -f $pfopen ; then
468        AC_CHECK_FUNCS(pfopen)
469        if test $ac_cv_func_pfopen = "no" ; then
470            AC_MSG_RESULT(Using $pfopen)
471            LIBS="$LIBS $pfopen"
472        fi
473    fi
474    libpcap=FAIL
475    AC_MSG_CHECKING([whether to look for a local libpcap])
476    AC_ARG_ENABLE(local-libpcap,
477        AS_HELP_STRING([--disable-local-libpcap],
478                       [don't look for a local libpcap @<:@default=check for a local libpcap@:>@]),,
479        enableval=yes)
480    case "$enableval" in
481
482    no)
483        AC_MSG_RESULT(no)
484        #
485        # Don't look for a local libpcap.
486        #
487        using_local_libpcap=no
488        ;;
489
490    *)
491        AC_MSG_RESULT(yes)
492        #
493        # Look for a local pcap library.
494        #
495        AC_MSG_CHECKING(for local pcap library)
496        lastdir=FAIL
497        places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
498            egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
499        places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
500            egrep '/libpcap-[[0-9]]+\.[[0-9]]+(\.[[0-9]]*)?([[ab]][[0-9]]*|-PRE-GIT|rc.)?$'`
501        for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
502            basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//' | \
503                sed -e 's/-PRE-GIT$//' `
504            if test $lastdir = $basedir ; then
505                dnl skip alphas when an actual release is present
506                continue;
507            fi
508            lastdir=$dir
509            if test -r $dir/libpcap.a ; then
510                libpcap=$dir/libpcap.a
511                local_pcap_dir=$dir
512                dnl continue and select the last one that exists
513            fi
514        done
515        if test $libpcap = FAIL ; then
516            #
517            # We didn't find a local libpcap.
518            #
519            AC_MSG_RESULT(not found)
520            using_local_libpcap=no;
521        else
522            #
523            # We found a local libpcap.
524            #
525            AC_MSG_RESULT($libpcap)
526            using_local_libpcap=yes
527        fi
528        ;;
529    esac
530
531    if test $using_local_libpcap = no ; then
532        #
533        # We didn't find a local libpcap.
534        # Look for an installed pkg-config.
535        #
536        AC_PATH_TOOL(PKG_CONFIG, pkg-config)
537        if test -n "$PKG_CONFIG" ; then
538            #
539            # We have it.  Are there .pc files for libpcap?
540            #
541            # --exists was introduced in pkg-config 0.4.0; that
542            # dates back to late 2000, so we won't worry about
543            # earlier releases that lack it.
544            #
545            AC_MSG_CHECKING(whether there are .pc files for libpcap)
546            if "$PKG_CONFIG" libpcap --exists ; then
547                #
548                # Yes, so we can use pkg-config to get configuration
549                # information for libpcap.
550                #
551                AC_MSG_RESULT(yes)
552                pkg_config_usable=yes
553            else
554                #
555                # No, so we can't use pkg-config to get configuration
556                # information for libpcap.
557                #
558                AC_MSG_RESULT(no)
559                pkg_config_usable=no
560            fi
561        else
562            #
563            # We don't have it, so we obviously can't use it.
564            #
565            pkg_config_usable=no
566        fi
567        if test "$pkg_config_usable" = "yes" ; then
568            #
569            # Found both - use pkg-config to get the include flags for
570            # libpcap and the flags to link with libpcap.
571            #
572            # Please read section 11.6 "Shell Substitutions"
573            # in the autoconf manual before doing anything
574            # to this that involves quoting.  Especially note
575            # the statement "There is just no portable way to use
576            # double-quoted strings inside double-quoted back-quoted
577            # expressions (pfew!)."
578            #
579            cflags=`"$PKG_CONFIG" libpcap --cflags`
580            $2="$cflags $$2"
581            libpcap=`"$PKG_CONFIG" libpcap --libs`
582        else
583            #
584            # No pkg-config
585            # Look for an installed pcap-config.
586            #
587            AC_PATH_TOOL(PCAP_CONFIG, pcap-config)
588            if test -n "$PCAP_CONFIG" ; then
589                #
590                # Found - use it to get the include flags for
591                # libpcap and the flags to link with libpcap.
592                #
593                # Please read section 11.6 "Shell Substitutions"
594                # in the autoconf manual before doing anything
595                # to this that involves quoting.  Especially note
596                # the statement "There is just no portable way to use
597                # double-quoted strings inside double-quoted back-quoted
598                # expressions (pfew!)."
599                #
600                cflags=`"$PCAP_CONFIG" --cflags`
601                $2="$cflags $$2"
602                libpcap=`"$PCAP_CONFIG" --libs`
603            else
604                #
605                # Not found; look for an installed pcap.
606                #
607                AC_CHECK_LIB(pcap, main, libpcap="-lpcap")
608                if test $libpcap = FAIL ; then
609                    AC_MSG_ERROR(see the INSTALL doc for more info)
610                fi
611                dnl
612                dnl Some versions of Red Hat Linux put "pcap.h" in
613                dnl "/usr/include/pcap"; had the LBL folks done so,
614                dnl that would have been a good idea, but for
615                dnl the Red Hat folks to do so just breaks source
616                dnl compatibility with other systems.
617                dnl
618                dnl We work around this by assuming that, as we didn't
619                dnl find a local libpcap, libpcap is in /usr/lib or
620                dnl /usr/local/lib and that the corresponding header
621                dnl file is under one of those directories; if we don't
622                dnl find it in either of those directories, we check to
623                dnl see if it's in a "pcap" subdirectory of them and,
624                dnl if so, add that subdirectory to the "-I" list.
625                dnl
626                dnl (We now also put pcap.h in /usr/include/pcap, but we
627                dnl leave behind a /usr/include/pcap.h that includes it,
628                dnl so you can still just include <pcap.h>.)
629                dnl
630                AC_MSG_CHECKING(for extraneous pcap header directories)
631                if test \( ! -r /usr/local/include/pcap.h \) -a \
632                        \( ! -r /usr/include/pcap.h \); then
633                    if test -r /usr/local/include/pcap/pcap.h; then
634                        d="/usr/local/include/pcap"
635                    elif test -r /usr/include/pcap/pcap.h; then
636                        d="/usr/include/pcap"
637                    fi
638                fi
639                if test -z "$d" ; then
640                    AC_MSG_RESULT(not found)
641                else
642                    $2="-I$d $$2"
643                    AC_MSG_RESULT(found -- -I$d added)
644                fi
645            fi
646        fi
647    else
648        #
649        # We found a local libpcap.  Add it to the dependencies for
650        # tcpdump.
651        #
652        $1=$libpcap
653
654        #
655        # Look for its pcap-config script.
656        #
657        AC_PATH_PROG(PCAP_CONFIG, pcap-config,, $local_pcap_dir)
658
659        if test -n "$PCAP_CONFIG"; then
660            #
661            # We don't want its --cflags or --libs output, because
662            # those presume it's installed.  For the C compiler flags,
663            # we add the source directory for the local libpcap, so
664            # we pick up its header files.
665            #
666            # We do, however, want its additional libraries, as required
667            # when linking statically, because it makes calls to
668            # routines in those libraries, so we'll need to link with
669            # them, because we'll be linking statically with it.
670            #
671            $2="-I$local_pcap_dir $$2"
672            additional_libs=`"$PCAP_CONFIG" --static --additional-libs`
673            libpcap="$libpcap $additional_libs"
674        else
675            #
676            # It doesn't have a pcap-config script.
677            # Make sure it has a pcap.h file.
678            #
679            places=`ls $srcdir/.. | sed -e 's,/$,,' -e "s,^,$srcdir/../," | \
680                egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
681            places2=`ls .. | sed -e 's,/$,,' -e "s,^,../," | \
682                egrep '/libpcap-[[0-9]]*.[[0-9]]*(.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
683            pcapH=FAIL
684            if test -r $local_pcap_dir/pcap.h; then
685                pcapH=$local_pcap_dir
686            else
687                for dir in $places $srcdir/../libpcap ../libpcap $srcdir/libpcap $places2 ; do
688                    if test -r $dir/pcap.h ; then
689                        pcapH=$dir
690                    fi
691                done
692            fi
693
694            if test $pcapH = FAIL ; then
695                AC_MSG_ERROR(cannot find pcap.h: see INSTALL)
696            fi
697
698            #
699            # Force the compiler to look for header files in the
700            # directory containing pcap.h.
701            #
702            $2="-I$pcapH $$2"
703        fi
704    fi
705
706    if test -z "$PKG_CONFIG" -a -z "$PCAP_CONFIG"; then
707        #
708        # We don't have pkg-config or pcap-config; find out any additional
709        # link flags we need.  (If we have pkg-config or pcap-config, we
710        # assume it tells us what we need.)
711        #
712        case "$host_os" in
713
714        aix*)
715            #
716            # If libpcap is DLPI-based, we have to use /lib/pse.exp if
717            # present, as we use the STREAMS routines.
718            #
719            # (XXX - true only if we're linking with a static libpcap?)
720            #
721            pseexe="/lib/pse.exp"
722            AC_MSG_CHECKING(for $pseexe)
723            if test -f $pseexe ; then
724                AC_MSG_RESULT(yes)
725                LIBS="$LIBS -I:$pseexe"
726            fi
727
728            #
729            # If libpcap is BPF-based, we need "-lodm" and "-lcfg", as
730            # we use them to load the BPF module.
731            #
732            # (XXX - true only if we're linking with a static libpcap?)
733            #
734            LIBS="$LIBS -lodm -lcfg"
735            ;;
736
737	solaris*)
738            # libdlpi is needed for Solaris 11 and later.
739            AC_CHECK_LIB(dlpi, dlpi_walk, LIBS="$LIBS -ldlpi" LDFLAGS="-L/lib $LDFLAGS", ,-L/lib)
740            ;;
741        esac
742    fi
743
744    LIBS="$libpcap $LIBS"
745
746    dnl
747    dnl Check for "pcap_loop()", to make sure we found a working
748    dnl libpcap and have all the right other libraries with which
749    dnl to link.  (Otherwise, the checks below will fail, not
750    dnl because the routines are missing from the library, but
751    dnl because we aren't linking properly with libpcap, and
752    dnl that will cause confusing errors at build time.)
753    dnl
754    AC_CHECK_FUNC(pcap_loop,,
755    [
756        AC_MSG_ERROR(
757[This is a bug, please follow the guidelines in CONTRIBUTING and include the
758config.log file in your report.  If you have downloaded libpcap from
759tcpdump.org, and built it yourself, please also include the config.log
760file from the libpcap source directory, the Makefile from the libpcap
761source directory, and the output of the make process for libpcap, as
762this could be a problem with the libpcap that was built, and we will
763not be able to determine why this is happening, and thus will not be
764able to fix it, without that information, as we have not been able to
765reproduce this problem ourselves.])
766    ])
767])
768
769dnl
770dnl If using gcc, make sure we have ANSI ioctl definitions
771dnl
772dnl usage:
773dnl
774dnl	AC_LBL_FIXINCLUDES
775dnl
776AC_DEFUN(AC_LBL_FIXINCLUDES,
777    [if test "$GCC" = yes ; then
778	    AC_MSG_CHECKING(for ANSI ioctl definitions)
779	    AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
780		AC_TRY_COMPILE(
781		    [/*
782		     * This generates a "duplicate case value" when fixincludes
783		     * has not be run.
784		     */
785#		include <sys/types.h>
786#		include <sys/time.h>
787#		include <sys/ioctl.h>
788#		ifdef HAVE_SYS_IOCCOM_H
789#		include <sys/ioccom.h>
790#		endif],
791		    [switch (0) {
792		    case _IO('A', 1):;
793		    case _IO('B', 1):;
794		    }],
795		    ac_cv_lbl_gcc_fixincludes=yes,
796		    ac_cv_lbl_gcc_fixincludes=no))
797	    AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
798	    if test $ac_cv_lbl_gcc_fixincludes = no ; then
799		    # Don't cache failure
800		    unset ac_cv_lbl_gcc_fixincludes
801		    AC_MSG_ERROR(see the INSTALL for more info)
802	    fi
803    fi])
804
805dnl
806dnl Checks to see if union wait is used with WEXITSTATUS()
807dnl
808dnl usage:
809dnl
810dnl	AC_LBL_UNION_WAIT
811dnl
812dnl results:
813dnl
814dnl	DECLWAITSTATUS (defined)
815dnl
816AC_DEFUN(AC_LBL_UNION_WAIT,
817    [AC_MSG_CHECKING(if union wait is used)
818    AC_CACHE_VAL(ac_cv_lbl_union_wait,
819	AC_TRY_COMPILE([
820#	include <sys/types.h>
821#	include <sys/wait.h>],
822	    [int status;
823	    u_int i = WEXITSTATUS(status);
824	    u_int j = waitpid(0, &status, 0);],
825	    ac_cv_lbl_union_wait=no,
826	    ac_cv_lbl_union_wait=yes))
827    AC_MSG_RESULT($ac_cv_lbl_union_wait)
828    if test $ac_cv_lbl_union_wait = yes ; then
829	    AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
830    else
831	    AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
832    fi])
833
834dnl
835dnl Checks to see if -R is used
836dnl
837dnl usage:
838dnl
839dnl	AC_LBL_HAVE_RUN_PATH
840dnl
841dnl results:
842dnl
843dnl	ac_cv_lbl_have_run_path (yes or no)
844dnl
845AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
846    [AC_MSG_CHECKING(for ${CC-cc} -R)
847    AC_CACHE_VAL(ac_cv_lbl_have_run_path,
848	[echo 'main(){}' > conftest.c
849	${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
850	if test ! -s conftest.out ; then
851		ac_cv_lbl_have_run_path=yes
852	else
853		ac_cv_lbl_have_run_path=no
854	fi
855	rm -f -r conftest*])
856    AC_MSG_RESULT($ac_cv_lbl_have_run_path)
857    ])
858
859dnl
860dnl Check whether a given format can be used to print 64-bit integers
861dnl
862AC_DEFUN(AC_LBL_CHECK_64BIT_FORMAT,
863  [
864    AC_MSG_CHECKING([whether %$1x can be used to format 64-bit integers])
865    AC_RUN_IFELSE(
866      [
867	AC_LANG_SOURCE(
868	  [[
869#	    ifdef HAVE_INTTYPES_H
870	    #include <inttypes.h>
871#	    endif
872	    #include <stdio.h>
873	    #include <sys/types.h>
874
875	    main()
876	    {
877	      uint64_t t = 1;
878	      char strbuf[16+1];
879	      sprintf(strbuf, "%016$1x", t << 32);
880	      if (strcmp(strbuf, "0000000100000000") == 0)
881		exit(0);
882	      else
883		exit(1);
884	    }
885	  ]])
886      ],
887      [
888	AC_DEFINE(PRId64, "$1d", [define if the platform doesn't define PRId64])
889	AC_DEFINE(PRIo64, "$1o", [define if the platform doesn't define PRIo64])
890	AC_DEFINE(PRIx64, "$1x", [define if the platform doesn't define PRIu64])
891	AC_DEFINE(PRIu64, "$1u", [define if the platform doesn't define PRIx64])
892	AC_MSG_RESULT(yes)
893      ],
894      [
895	AC_MSG_RESULT(no)
896	$2
897      ])
898  ])
899
900dnl
901dnl If the file .devel exists:
902dnl	Add some warning flags if the compiler supports them
903dnl	If an os prototype include exists, symlink os-proto.h to it
904dnl
905dnl usage:
906dnl
907dnl	AC_LBL_DEVEL(copt)
908dnl
909dnl results:
910dnl
911dnl	$1 (copt appended)
912dnl	HAVE_OS_PROTO_H (defined)
913dnl	os-proto.h (symlinked)
914dnl
915AC_DEFUN(AC_LBL_DEVEL,
916    [rm -f os-proto.h
917    if test "${LBL_CFLAGS+set}" = set; then
918	    $1="$$1 ${LBL_CFLAGS}"
919    fi
920    if test -f .devel ; then
921	    #
922	    # Skip all the warning option stuff on some compilers.
923	    #
924	    if test "$ac_lbl_cc_dont_try_gcc_dashW" != yes; then
925		    AC_LBL_CHECK_UNKNOWN_WARNING_OPTION_ERROR()
926		    AC_LBL_CHECK_COMPILER_OPT($1, -W)
927		    AC_LBL_CHECK_COMPILER_OPT($1, -Wall)
928		    AC_LBL_CHECK_COMPILER_OPT($1, -Wassign-enum)
929		    AC_LBL_CHECK_COMPILER_OPT($1, -Wcast-qual)
930		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-prototypes)
931		    AC_LBL_CHECK_COMPILER_OPT($1, -Wmissing-variable-declarations)
932		    AC_LBL_CHECK_COMPILER_OPT($1, -Wold-style-definition)
933		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpedantic)
934		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-arith)
935		    AC_LBL_CHECK_COMPILER_OPT($1, -Wpointer-sign)
936		    AC_LBL_CHECK_COMPILER_OPT($1, -Wshadow)
937		    AC_LBL_CHECK_COMPILER_OPT($1, -Wsign-compare)
938		    AC_LBL_CHECK_COMPILER_OPT($1, -Wstrict-prototypes)
939		    AC_LBL_CHECK_COMPILER_OPT($1, -Wunreachable-code-return)
940		    AC_LBL_CHECK_COMPILER_OPT($1, -Wused-but-marked-unused)
941		    AC_LBL_CHECK_COMPILER_OPT($1, -Wwrite-strings)
942	    fi
943	    AC_LBL_CHECK_DEPENDENCY_GENERATION_OPT()
944	    #
945	    # We used to set -n32 for IRIX 6 when not using GCC (presumed
946	    # to mean that we're using MIPS C or MIPSpro C); it specified
947	    # the "new" faster 32-bit ABI, introduced in IRIX 6.2.  I'm
948	    # not sure why that would be something to do *only* with a
949	    # .devel file; why should the ABI for which we produce code
950	    # depend on .devel?
951	    #
952	    os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
953	    name="lbl/os-$os.h"
954	    if test -f $name ; then
955		    ln -s $name os-proto.h
956		    AC_DEFINE(HAVE_OS_PROTO_H, 1,
957			[if there's an os_proto.h for this platform, to use additional prototypes])
958	    else
959		    AC_MSG_WARN(can't find $name)
960	    fi
961    fi])
962
963dnl
964dnl Improved version of AC_CHECK_LIB
965dnl
966dnl Thanks to John Hawkinson (jhawk@mit.edu)
967dnl
968dnl usage:
969dnl
970dnl	AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
971dnl	    ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
972dnl
973dnl results:
974dnl
975dnl	LIBS
976dnl
977dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
978dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
979dnl We keep it around for reference purposes in case it's ever
980dnl useful in the future.
981dnl
982
983define(AC_LBL_CHECK_LIB,
984[AC_MSG_CHECKING([for $2 in -l$1])
985dnl Use a cache variable name containing the library, function
986dnl name, and extra libraries to link with, because the test really is
987dnl for library $1 defining function $2, when linked with potinal
988dnl library $5, not just for library $1.  Separate tests with the same
989dnl $1 and different $2's or $5's may have different results.
990ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
991AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
992[ac_save_LIBS="$LIBS"
993LIBS="-l$1 $5 $LIBS"
994AC_TRY_LINK(dnl
995ifelse([$2], [main], , dnl Avoid conflicting decl of main.
996[/* Override any gcc2 internal prototype to avoid an error.  */
997]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
998extern "C"
999#endif
1000])dnl
1001[/* We use char because int might match the return type of a gcc2
1002    builtin and then its argument prototype would still apply.  */
1003char $2();
1004]),
1005	    [$2()],
1006	    eval "ac_cv_lbl_lib_$ac_lib_var=yes",
1007	    eval "ac_cv_lbl_lib_$ac_lib_var=no")
1008LIBS="$ac_save_LIBS"
1009])dnl
1010if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
1011  AC_MSG_RESULT(yes)
1012  ifelse([$3], ,
1013[changequote(, )dnl
1014  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
1015    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1016changequote([, ])dnl
1017  AC_DEFINE_UNQUOTED($ac_tr_lib)
1018  LIBS="-l$1 $LIBS"
1019], [$3])
1020else
1021  AC_MSG_RESULT(no)
1022ifelse([$4], , , [$4
1023])dnl
1024fi
1025])
1026
1027dnl
1028dnl AC_LBL_LIBRARY_NET
1029dnl
1030dnl This test is for network applications that need socket() and
1031dnl gethostbyname() -ish functions.  Under Solaris, those applications
1032dnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
1033dnl with "-lnsl" but should *not* link with "-lsocket" because
1034dnl libsocket.a breaks a number of things (for instance:
1035dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
1036dnl versions of IRIX).
1037dnl
1038dnl Unfortunately, many application developers are not aware of this,
1039dnl and mistakenly write tests that cause -lsocket to be used under
1040dnl IRIX.  It is also easy to write tests that cause -lnsl to be used
1041dnl under operating systems where neither are necessary (or useful),
1042dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
1043dnl
1044dnl This test exists so that every application developer does not test
1045dnl this in a different, and subtly broken fashion.
1046
1047dnl It has been argued that this test should be broken up into two
1048dnl separate tests, one for the resolver libraries, and one for the
1049dnl libraries necessary for using Sockets API. Unfortunately, the two
1050dnl are carefully intertwined and allowing the autoconf user to use
1051dnl them independently potentially results in unfortunate ordering
1052dnl dependencies -- as such, such component macros would have to
1053dnl carefully use indirection and be aware if the other components were
1054dnl executed. Since other autoconf macros do not go to this trouble,
1055dnl and almost no applications use sockets without the resolver, this
1056dnl complexity has not been implemented.
1057dnl
1058dnl The check for libresolv is in case you are attempting to link
1059dnl statically and happen to have a libresolv.a lying around (and no
1060dnl libnsl.a).
1061dnl
1062AC_DEFUN(AC_LBL_LIBRARY_NET, [
1063    # Most operating systems have gethostbyname() in the default searched
1064    # libraries (i.e. libc):
1065    # Some OSes (eg. Solaris) place it in libnsl
1066    # Some strange OSes (SINIX) have it in libsocket:
1067    AC_SEARCH_LIBS(gethostbyname, nsl socket resolv)
1068    # Unfortunately libsocket sometimes depends on libnsl and
1069    # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
1070    if test "$ac_cv_search_gethostbyname" = "no"
1071    then
1072	AC_CHECK_LIB(socket, gethostbyname,
1073                     LIBS="-lsocket -lnsl $LIBS", , -lnsl)
1074    fi
1075    AC_SEARCH_LIBS(socket, socket, ,
1076	AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
1077    # DLPI needs putmsg under HPUX so test for -lstr while we're at it
1078    AC_SEARCH_LIBS(putmsg, str)
1079    ])
1080
1081dnl Copyright (c) 1999 WIDE Project. All rights reserved.
1082dnl
1083dnl Redistribution and use in source and binary forms, with or without
1084dnl modification, are permitted provided that the following conditions
1085dnl are met:
1086dnl 1. Redistributions of source code must retain the above copyright
1087dnl    notice, this list of conditions and the following disclaimer.
1088dnl 2. Redistributions in binary form must reproduce the above copyright
1089dnl    notice, this list of conditions and the following disclaimer in the
1090dnl    documentation and/or other materials provided with the distribution.
1091dnl 3. Neither the name of the project nor the names of its contributors
1092dnl    may be used to endorse or promote products derived from this software
1093dnl    without specific prior written permission.
1094dnl
1095dnl THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1096dnl ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1097dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1098dnl ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
1099dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1100dnl DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1101dnl OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1102dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1103dnl LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1104dnl OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1105dnl SUCH DAMAGE.
1106
1107AC_DEFUN(AC_LBL_SSLEAY,
1108    [
1109	#
1110	# Find the last component of $libdir; it's not necessarily
1111	# "lib" - it might be "lib64" on, for example, x86-64
1112	# Linux systems.
1113	#
1114	# We assume the directory in which we're looking for
1115	# libcrypto has a subdirectory with that as its name.
1116	#
1117	tmplib=`echo "$libdir" | sed 's,.*/,,'`
1118
1119	#
1120	# XXX - is there a better way to check if a given library is
1121	# in a given directory than checking each of the possible
1122	# shared library suffixes?
1123	#
1124	# Are there any other suffixes we need to look for?  Do we
1125	# have to worry about ".so.{version}"?
1126	#
1127	# Or should we just look for "libcrypto.*"?
1128	#
1129	if test -d "$1/$tmplib" -a \( -f "$1/$tmplib/libcrypto.a" -o \
1130				    -f "$1/$tmplib/libcrypto.so" -o \
1131				    -f "$1/$tmplib/libcrypto.sl" -o \
1132				    -f "$1/$tmplib/libcrypto.dylib" \); then
1133		ac_cv_ssleay_path="$1"
1134	fi
1135
1136	#
1137	# Make sure we have the headers as well.
1138	#
1139	if test -d "$1/include/openssl" -a -f "$1/include/openssl/des.h"; then
1140		incdir="-I$1/include"
1141	fi
1142])
1143