xref: /netbsd-src/external/bsd/libpcap/dist/aclocal.m4 (revision a5847cc334d9a7029f6352b847e9e8d71a0f9e0c)
1dnl @(#) Header: /tcpdump/master/libpcap/aclocal.m4,v 1.93 2008-11-18 07:29:48 guy Exp (LBL)
2dnl
3dnl Copyright (c) 1995, 1996, 1997, 1998
4dnl	The Regents of the University of California.  All rights reserved.
5dnl
6dnl Redistribution and use in source and binary forms, with or without
7dnl modification, are permitted provided that: (1) source code distributions
8dnl retain the above copyright notice and this paragraph in its entirety, (2)
9dnl distributions including binary code include the above copyright notice and
10dnl this paragraph in its entirety in the documentation or other materials
11dnl provided with the distribution, and (3) all advertising materials mentioning
12dnl features or use of this software display the following acknowledgement:
13dnl ``This product includes software developed by the University of California,
14dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15dnl the University nor the names of its contributors may be used to endorse
16dnl or promote products derived from this software without specific prior
17dnl written permission.
18dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21dnl
22dnl LBL autoconf macros
23dnl
24
25dnl
26dnl Do whatever AC_LBL_C_INIT work is necessary before using AC_PROG_CC.
27dnl
28dnl It appears that newer versions of autoconf (2.64 and later) will,
29dnl if you use AC_TRY_COMPILE in a macro, stick AC_PROG_CC at the
30dnl beginning of the macro, even if the macro itself calls AC_PROG_CC.
31dnl See the "Prerequisite Macros" and "Expanded Before Required" sections
32dnl in the Autoconf documentation.
33dnl
34dnl This causes a steaming heap of fail in our case, as we were, in
35dnl AC_LBL_C_INIT, doing the tests we now do in AC_LBL_C_INIT_BEFORE_CC,
36dnl calling AC_PROG_CC, and then doing the tests we now do in
37dnl AC_LBL_C_INIT.  Now, we run AC_LBL_C_INIT_BEFORE_CC, AC_PROG_CC,
38dnl and AC_LBL_C_INIT at the top level.
39dnl
40AC_DEFUN(AC_LBL_C_INIT_BEFORE_CC,
41    [AC_PREREQ(2.50)
42    AC_BEFORE([$0], [AC_LBL_C_INIT])
43    AC_BEFORE([$0], [AC_PROG_CC])
44    AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
45    AC_BEFORE([$0], [AC_LBL_DEVEL])
46    AC_ARG_WITH(gcc, [  --without-gcc           don't use gcc])
47    $1="-O"
48    $2=""
49    if test "${srcdir}" != "." ; then
50	    $2="-I\$(srcdir)"
51    fi
52    if test "${CFLAGS+set}" = set; then
53	    LBL_CFLAGS="$CFLAGS"
54    fi
55    if test -z "$CC" ; then
56	    case "$host_os" in
57
58	    bsdi*)
59		    AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
60		    if test $SHLICC2 = yes ; then
61			    CC=shlicc2
62			    export CC
63		    fi
64		    ;;
65	    esac
66    fi
67    if test -z "$CC" -a "$with_gcc" = no ; then
68	    CC=cc
69	    export CC
70    fi
71])
72
73dnl
74dnl Determine which compiler we're using (cc or gcc)
75dnl If using gcc, determine the version number
76dnl If using cc, require that it support ansi prototypes
77dnl If using gcc, use -O2 (otherwise use -O)
78dnl If using cc, explicitly specify /usr/local/include
79dnl
80dnl usage:
81dnl
82dnl	AC_LBL_C_INIT(copt, incls)
83dnl
84dnl results:
85dnl
86dnl	$1 (copt set)
87dnl	$2 (incls set)
88dnl	CC
89dnl	LDFLAGS
90dnl	ac_cv_lbl_gcc_vers
91dnl	LBL_CFLAGS
92dnl
93AC_DEFUN(AC_LBL_C_INIT,
94    [AC_PREREQ(2.50)
95    AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
96    AC_BEFORE([$0], [AC_LBL_DEVEL])
97    AC_BEFORE([$0], [AC_LBL_SHLIBS_INIT])
98    if test "$GCC" = yes ; then
99	    if test "$SHLICC2" = yes ; then
100		    ac_cv_lbl_gcc_vers=2
101		    $1="-O2"
102	    else
103		    AC_MSG_CHECKING(gcc version)
104		    AC_CACHE_VAL(ac_cv_lbl_gcc_vers,
105			ac_cv_lbl_gcc_vers=`$CC -v 2>&1 | \
106			    sed -e '/^gcc version /!d' \
107				-e 's/^gcc version //' \
108				-e 's/ .*//' -e 's/^[[[^0-9]]]*//' \
109				-e 's/\..*//'`)
110		    AC_MSG_RESULT($ac_cv_lbl_gcc_vers)
111		    if test $ac_cv_lbl_gcc_vers -gt 1 ; then
112			    $1="-O2"
113		    fi
114	    fi
115    else
116	    AC_MSG_CHECKING(that $CC handles ansi prototypes)
117	    AC_CACHE_VAL(ac_cv_lbl_cc_ansi_prototypes,
118		AC_TRY_COMPILE(
119		    [#include <sys/types.h>],
120		    [int frob(int, char *)],
121		    ac_cv_lbl_cc_ansi_prototypes=yes,
122		    ac_cv_lbl_cc_ansi_prototypes=no))
123	    AC_MSG_RESULT($ac_cv_lbl_cc_ansi_prototypes)
124	    if test $ac_cv_lbl_cc_ansi_prototypes = no ; then
125		    case "$host_os" in
126
127		    hpux*)
128			    AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE))
129			    savedcflags="$CFLAGS"
130			    CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS"
131			    AC_CACHE_VAL(ac_cv_lbl_cc_hpux_cc_aa,
132				AC_TRY_COMPILE(
133				    [#include <sys/types.h>],
134				    [int frob(int, char *)],
135				    ac_cv_lbl_cc_hpux_cc_aa=yes,
136				    ac_cv_lbl_cc_hpux_cc_aa=no))
137			    AC_MSG_RESULT($ac_cv_lbl_cc_hpux_cc_aa)
138			    if test $ac_cv_lbl_cc_hpux_cc_aa = no ; then
139				    AC_MSG_ERROR(see the INSTALL doc for more info)
140			    fi
141			    CFLAGS="$savedcflags"
142			    $1="-Aa $$1"
143			    AC_DEFINE(_HPUX_SOURCE,1,[needed on HP-UX])
144			    ;;
145
146		    osf*)
147			    AC_MSG_CHECKING(for ansi mode in DEC compiler ($CC -std1))
148			    savedcflags="$CFLAGS"
149			    CFLAGS="-std1"
150			    AC_CACHE_VAL(ac_cv_lbl_cc_osf1_cc_std1,
151				AC_TRY_COMPILE(
152				    [#include <sys/types.h>],
153				    [int frob(int, char *)],
154				    ac_cv_lbl_cc_osf1_cc_std1=yes,
155				    ac_cv_lbl_cc_osf1_cc_std1=no))
156			    AC_MSG_RESULT($ac_cv_lbl_cc_osf1_cc_std1)
157			    if test $ac_cv_lbl_cc_osf1_cc_std1 = no ; then
158				    AC_MSG_ERROR(see the INSTALL doc for more info)
159			    fi
160			    CFLAGS="$savedcflags"
161			    $1="-std1 $$1"
162			    ;;
163
164		    *)
165			    AC_MSG_ERROR(see the INSTALL doc for more info)
166			    ;;
167		    esac
168	    fi
169	    $2="$$2 -I/usr/local/include"
170	    LDFLAGS="$LDFLAGS -L/usr/local/lib"
171
172	    case "$host_os" in
173
174	    irix*)
175		    $1="$$1 -xansi -signed -g3"
176		    ;;
177
178	    osf*)
179	    	    #
180		    # Presumed to be DEC OSF/1, Digital UNIX, or
181		    # Tru64 UNIX.
182		    #
183		    $1="$$1 -g3"
184		    ;;
185
186	    ultrix*)
187		    AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
188		    AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
189			AC_TRY_COMPILE(
190			    [#include <sys/types.h>],
191			    [struct a { int b; };
192			    void c(const struct a *)],
193			    ac_cv_lbl_cc_const_proto=yes,
194			    ac_cv_lbl_cc_const_proto=no))
195		    AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
196		    if test $ac_cv_lbl_cc_const_proto = no ; then
197			    AC_DEFINE(const,[],
198			        [to handle Ultrix compilers that don't support const in prototypes])
199		    fi
200		    ;;
201	    esac
202    fi
203])
204
205dnl
206dnl Determine what options are needed to build a shared library
207dnl
208dnl usage:
209dnl
210dnl	AC_LBL_SHLIBS_INIT
211dnl
212dnl results:
213dnl
214dnl	V_CCOPT (modified to build position-independent code)
215dnl	V_SHLIB_CMD
216dnl	V_SHLIB_OPT
217dnl	V_SONAME_OPT
218dnl	V_RPATH_OPT
219dnl
220AC_DEFUN(AC_LBL_SHLIBS_INIT,
221    [AC_PREREQ(2.50)
222    if test "$GCC" = yes ; then
223	    #
224	    # On platforms where we build a shared library:
225	    #
226	    #	add options to generate position-independent code,
227	    #	if necessary (it's the default in AIX and Darwin/OS X);
228	    #
229	    #	define option to set the soname of the shared library,
230	    #	if the OS supports that;
231	    #
232	    #	add options to specify, at link time, a directory to
233	    #	add to the run-time search path, if that's necessary.
234	    #
235	    V_SHLIB_CMD="\$(CC)"
236	    V_SHLIB_OPT="-shared"
237	    case "$host_os" in
238
239	    aix*)
240		    ;;
241
242	    freebsd*|netbsd*|openbsd*|dragonfly*|linux*|osf*)
243	    	    #
244		    # Platforms where the linker is the GNU linker
245		    # or accepts command-line arguments like
246		    # those the GNU linker accepts.
247		    #
248		    V_CCOPT="$V_CCOPT -fpic"
249		    V_SONAME_OPT="-Wl,-soname,"
250		    V_RPATH_OPT="-Wl,-rpath,"
251		    ;;
252
253	    hpux*)
254		    V_CCOPT="$V_CCOPT -fpic"
255	    	    #
256		    # XXX - this assumes GCC is using the HP linker,
257		    # rather than the GNU linker, and that the "+h"
258		    # option is used on all HP-UX platforms, both .sl
259		    # and .so.
260		    #
261		    V_SONAME_OPT="-Wl,+h,"
262		    #
263		    # By default, directories specifed with -L
264		    # are added to the run-time search path, so
265		    # we don't add them in pcap-config.
266		    #
267		    ;;
268
269	    solaris*)
270		    V_CCOPT="$V_CCOPT -fpic"
271		    #
272		    # XXX - this assumes GCC is using the Sun linker,
273		    # rather than the GNU linker.
274		    #
275		    V_SONAME_OPT="-Wl,-h,"
276		    V_RPATH_OPT="-Wl,-R,"
277		    ;;
278	    esac
279    else
280	    #
281	    # Set the appropriate compiler flags and, on platforms
282	    # where we build a shared library:
283	    #
284	    #	add options to generate position-independent code,
285	    #	if necessary (it's the default in Darwin/OS X);
286	    #
287	    #	if we generate ".so" shared libraries, define the
288	    #	appropriate options for building the shared library;
289	    #
290	    #	add options to specify, at link time, a directory to
291	    #	add to the run-time search path, if that's necessary.
292	    #
293	    # Note: spaces after V_SONAME_OPT are significant; on
294	    # some platforms the soname is passed with a GCC-like
295	    # "-Wl,-soname,{soname}" option, with the soname part
296	    # of the option, while on other platforms the C compiler
297	    # driver takes it as a regular option with the soname
298	    # following the option.  The same applies to V_RPATH_OPT.
299	    #
300	    case "$host_os" in
301
302	    aix*)
303		    V_SHLIB_CMD="\$(CC)"
304		    V_SHLIB_OPT="-G -bnoentry -bexpall"
305		    ;;
306
307	    freebsd*|netbsd*|openbsd*|dragonfly*|linux*)
308		    #
309		    # "cc" is GCC.
310		    #
311		    V_CCOPT="$V_CCOPT -fpic"
312		    V_SHLIB_CMD="\$(CC)"
313		    V_SHLIB_OPT="-shared"
314		    V_SONAME_OPT="-Wl,-soname,"
315		    V_RPATH_OPT="-Wl,-rpath,"
316		    ;;
317
318	    hpux*)
319		    V_CCOPT="$V_CCOPT +z"
320		    V_SHLIB_CMD="\$(LD)"
321		    V_SHLIB_OPT="-b"
322		    V_SONAME_OPT="+h "
323		    #
324		    # By default, directories specifed with -L
325		    # are added to the run-time search path, so
326		    # we don't add them in pcap-config.
327		    #
328		    ;;
329
330	    osf*)
331	    	    #
332		    # Presumed to be DEC OSF/1, Digital UNIX, or
333		    # Tru64 UNIX.
334		    #
335		    V_SHLIB_CMD="\$(CC)"
336		    V_SHLIB_OPT="-shared"
337		    V_SONAME_OPT="-soname "
338		    V_RPATH_OPT="-rpath "
339		    ;;
340
341	    solaris*)
342		    V_CCOPT="$V_CCOPT -Kpic"
343		    V_SHLIB_CMD="\$(CC)"
344		    V_SHLIB_OPT="-G"
345		    V_SONAME_OPT="-h "
346		    V_RPATH_OPT="-R"
347		    ;;
348	    esac
349    fi
350])
351
352#
353# Try compiling a sample of the type of code that appears in
354# gencode.c with "inline", "__inline__", and "__inline".
355#
356# Autoconf's AC_C_INLINE, at least in autoconf 2.13, isn't good enough,
357# as it just tests whether a function returning "int" can be inlined;
358# at least some versions of HP's C compiler can inline that, but can't
359# inline a function that returns a struct pointer.
360#
361# Make sure we use the V_CCOPT flags, because some of those might
362# disable inlining.
363#
364AC_DEFUN(AC_LBL_C_INLINE,
365    [AC_MSG_CHECKING(for inline)
366    save_CFLAGS="$CFLAGS"
367    CFLAGS="$V_CCOPT"
368    AC_CACHE_VAL(ac_cv_lbl_inline, [
369	ac_cv_lbl_inline=""
370	ac_lbl_cc_inline=no
371	for ac_lbl_inline in inline __inline__ __inline
372	do
373	    AC_TRY_COMPILE(
374		[#define inline $ac_lbl_inline
375		static inline struct iltest *foo(void);
376		struct iltest {
377		    int iltest1;
378		    int iltest2;
379		};
380
381		static inline struct iltest *
382		foo()
383		{
384		    static struct iltest xxx;
385
386		    return &xxx;
387		}],,ac_lbl_cc_inline=yes,)
388	    if test "$ac_lbl_cc_inline" = yes ; then
389		break;
390	    fi
391	done
392	if test "$ac_lbl_cc_inline" = yes ; then
393	    ac_cv_lbl_inline=$ac_lbl_inline
394	fi])
395    CFLAGS="$save_CFLAGS"
396    if test ! -z "$ac_cv_lbl_inline" ; then
397	AC_MSG_RESULT($ac_cv_lbl_inline)
398    else
399	AC_MSG_RESULT(no)
400    fi
401    AC_DEFINE_UNQUOTED(inline, $ac_cv_lbl_inline, [Define as token for inline if inlining supported])])
402
403dnl
404dnl If using gcc, make sure we have ANSI ioctl definitions
405dnl
406dnl usage:
407dnl
408dnl	AC_LBL_FIXINCLUDES
409dnl
410AC_DEFUN(AC_LBL_FIXINCLUDES,
411    [if test "$GCC" = yes ; then
412	    AC_MSG_CHECKING(for ANSI ioctl definitions)
413	    AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
414		AC_TRY_COMPILE(
415		    [/*
416		     * This generates a "duplicate case value" when fixincludes
417		     * has not be run.
418		     */
419#		include <sys/types.h>
420#		include <sys/time.h>
421#		include <sys/ioctl.h>
422#		ifdef HAVE_SYS_IOCCOM_H
423#		include <sys/ioccom.h>
424#		endif],
425		    [switch (0) {
426		    case _IO('A', 1):;
427		    case _IO('B', 1):;
428		    }],
429		    ac_cv_lbl_gcc_fixincludes=yes,
430		    ac_cv_lbl_gcc_fixincludes=no))
431	    AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
432	    if test $ac_cv_lbl_gcc_fixincludes = no ; then
433		    # Don't cache failure
434		    unset ac_cv_lbl_gcc_fixincludes
435		    AC_MSG_ERROR(see the INSTALL for more info)
436	    fi
437    fi])
438
439dnl
440dnl Check for flex, default to lex
441dnl Require flex 2.4 or higher
442dnl Check for bison, default to yacc
443dnl Default to lex/yacc if both flex and bison are not available
444dnl Define the yy prefix string if using flex and bison
445dnl
446dnl usage:
447dnl
448dnl	AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix)
449dnl
450dnl results:
451dnl
452dnl	$1 (lex set)
453dnl	$2 (yacc appended)
454dnl	$3 (optional flex and bison -P prefix)
455dnl
456AC_DEFUN(AC_LBL_LEX_AND_YACC,
457    [AC_ARG_WITH(flex, [  --without-flex          don't use flex])
458    AC_ARG_WITH(bison, [  --without-bison         don't use bison])
459    if test "$with_flex" = no ; then
460	    $1=lex
461    else
462	    AC_CHECK_PROGS($1, flex, lex)
463    fi
464    if test "$$1" = flex ; then
465	    # The -V flag was added in 2.4
466	    AC_MSG_CHECKING(for flex 2.4 or higher)
467	    AC_CACHE_VAL(ac_cv_lbl_flex_v24,
468		if flex -V >/dev/null 2>&1; then
469			ac_cv_lbl_flex_v24=yes
470		else
471			ac_cv_lbl_flex_v24=no
472		fi)
473	    AC_MSG_RESULT($ac_cv_lbl_flex_v24)
474	    if test $ac_cv_lbl_flex_v24 = no ; then
475		    s="2.4 or higher required"
476		    AC_MSG_WARN(ignoring obsolete flex executable ($s))
477		    $1=lex
478	    fi
479    fi
480    if test "$with_bison" = no ; then
481	    $2=yacc
482    else
483	    AC_CHECK_PROGS($2, bison, yacc)
484    fi
485    if test "$$2" = bison ; then
486	    $2="$$2 -y"
487    fi
488    if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then
489	    AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc)
490	    $1=lex
491	    $2=yacc
492    fi
493    if test "$$1" = flex -a -n "$3" ; then
494	    $1="$$1 -P$3"
495	    $2="$$2 -p $3"
496    fi])
497
498dnl
499dnl Checks to see if union wait is used with WEXITSTATUS()
500dnl
501dnl usage:
502dnl
503dnl	AC_LBL_UNION_WAIT
504dnl
505dnl results:
506dnl
507dnl	DECLWAITSTATUS (defined)
508dnl
509AC_DEFUN(AC_LBL_UNION_WAIT,
510    [AC_MSG_CHECKING(if union wait is used)
511    AC_CACHE_VAL(ac_cv_lbl_union_wait,
512	AC_TRY_COMPILE([
513#	include <sys/types.h>
514#	include <sys/wait.h>],
515	    [int status;
516	    u_int i = WEXITSTATUS(status);
517	    u_int j = waitpid(0, &status, 0);],
518	    ac_cv_lbl_union_wait=no,
519	    ac_cv_lbl_union_wait=yes))
520    AC_MSG_RESULT($ac_cv_lbl_union_wait)
521    if test $ac_cv_lbl_union_wait = yes ; then
522	    AC_DEFINE(DECLWAITSTATUS,union wait,[type for wait])
523    else
524	    AC_DEFINE(DECLWAITSTATUS,int,[type for wait])
525    fi])
526
527dnl
528dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
529dnl
530dnl usage:
531dnl
532dnl	AC_LBL_SOCKADDR_SA_LEN
533dnl
534dnl results:
535dnl
536dnl	HAVE_SOCKADDR_SA_LEN (defined)
537dnl
538AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
539    [AC_MSG_CHECKING(if sockaddr struct has the sa_len member)
540    AC_CACHE_VAL(ac_cv_lbl_sockaddr_has_sa_len,
541	AC_TRY_COMPILE([
542#	include <sys/types.h>
543#	include <sys/socket.h>],
544	[u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
545	ac_cv_lbl_sockaddr_has_sa_len=yes,
546	ac_cv_lbl_sockaddr_has_sa_len=no))
547    AC_MSG_RESULT($ac_cv_lbl_sockaddr_has_sa_len)
548    if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then
549	    AC_DEFINE(HAVE_SOCKADDR_SA_LEN,1,[if struct sockaddr has the sa_len member])
550    fi])
551
552dnl
553dnl Checks to see if there's a sockaddr_storage structure
554dnl
555dnl usage:
556dnl
557dnl	AC_LBL_SOCKADDR_STORAGE
558dnl
559dnl results:
560dnl
561dnl	HAVE_SOCKADDR_STORAGE (defined)
562dnl
563AC_DEFUN(AC_LBL_SOCKADDR_STORAGE,
564    [AC_MSG_CHECKING(if sockaddr_storage struct exists)
565    AC_CACHE_VAL(ac_cv_lbl_has_sockaddr_storage,
566	AC_TRY_COMPILE([
567#	include <sys/types.h>
568#	include <sys/socket.h>],
569	[u_int i = sizeof (struct sockaddr_storage)],
570	ac_cv_lbl_has_sockaddr_storage=yes,
571	ac_cv_lbl_has_sockaddr_storage=no))
572    AC_MSG_RESULT($ac_cv_lbl_has_sockaddr_storage)
573    if test $ac_cv_lbl_has_sockaddr_storage = yes ; then
574	    AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[if struct sockaddr_storage exists])
575    fi])
576
577dnl
578dnl Checks to see if the dl_hp_ppa_info_t struct has the HP-UX 11.00
579dnl dl_module_id_1 member
580dnl
581dnl usage:
582dnl
583dnl	AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1
584dnl
585dnl results:
586dnl
587dnl	HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1 (defined)
588dnl
589dnl NOTE: any compile failure means we conclude that it doesn't have
590dnl that member, so if we don't have DLPI, don't have a <sys/dlpi_ext.h>
591dnl header, or have one that doesn't declare a dl_hp_ppa_info_t type,
592dnl we conclude it doesn't have that member (which is OK, as either we
593dnl won't be using code that would use that member, or we wouldn't
594dnl compile in any case).
595dnl
596AC_DEFUN(AC_LBL_HP_PPA_INFO_T_DL_MODULE_ID_1,
597    [AC_MSG_CHECKING(if dl_hp_ppa_info_t struct has dl_module_id_1 member)
598    AC_CACHE_VAL(ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1,
599	AC_TRY_COMPILE([
600#	include <sys/types.h>
601#	include <sys/dlpi.h>
602#	include <sys/dlpi_ext.h>],
603	[u_int i = sizeof(((dl_hp_ppa_info_t *)0)->dl_module_id_1)],
604	ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=yes,
605	ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1=no))
606    AC_MSG_RESULT($ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1)
607    if test $ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1 = yes ; then
608	    AC_DEFINE(HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1,1,[if ppa_info_t_dl_module_id exists])
609    fi])
610
611dnl
612dnl Checks to see if -R is used
613dnl
614dnl usage:
615dnl
616dnl	AC_LBL_HAVE_RUN_PATH
617dnl
618dnl results:
619dnl
620dnl	ac_cv_lbl_have_run_path (yes or no)
621dnl
622AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
623    [AC_MSG_CHECKING(for ${CC-cc} -R)
624    AC_CACHE_VAL(ac_cv_lbl_have_run_path,
625	[echo 'main(){}' > conftest.c
626	${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
627	if test ! -s conftest.out ; then
628		ac_cv_lbl_have_run_path=yes
629	else
630		ac_cv_lbl_have_run_path=no
631	fi
632	rm -f -r conftest*])
633    AC_MSG_RESULT($ac_cv_lbl_have_run_path)
634    ])
635
636dnl
637dnl Checks to see if unaligned memory accesses fail
638dnl
639dnl usage:
640dnl
641dnl	AC_LBL_UNALIGNED_ACCESS
642dnl
643dnl results:
644dnl
645dnl	LBL_ALIGN (DEFINED)
646dnl
647AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
648    [AC_MSG_CHECKING(if unaligned accesses fail)
649    AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
650	[case "$host_cpu" in
651
652	#
653	# These are CPU types where:
654	#
655	#	the CPU faults on an unaligned access, but at least some
656	#	OSes that support that CPU catch the fault and simulate
657	#	the unaligned access (e.g., Alpha/{Digital,Tru64} UNIX) -
658	#	the simulation is slow, so we don't want to use it;
659	#
660	#	the CPU, I infer (from the old
661	#
662	# XXX: should also check that they don't do weird things (like on arm)
663	#
664	#	comment) doesn't fault on unaligned accesses, but doesn't
665	#	do a normal unaligned fetch, either (e.g., presumably, ARM);
666	#
667	#	for whatever reason, the test program doesn't work
668	#	(this has been claimed to be the case for several of those
669	#	CPUs - I don't know what the problem is; the problem
670	#	was reported as "the test program dumps core" for SuperH,
671	#	but that's what the test program is *supposed* to do -
672	#	it dumps core before it writes anything, so the test
673	#	for an empty output file should find an empty output
674	#	file and conclude that unaligned accesses don't work).
675	#
676	# This run-time test won't work if you're cross-compiling, so
677	# in order to support cross-compiling for a particular CPU,
678	# we have to wire in the list of CPU types anyway, as far as
679	# I know, so perhaps we should just have a set of CPUs on
680	# which we know it doesn't work, a set of CPUs on which we
681	# know it does work, and have the script just fail on other
682	# cpu types and update it when such a failure occurs.
683	#
684	alpha*|arm*|bfin*|hp*|mips*|sh*|sparc*|ia64|nv1)
685		ac_cv_lbl_unaligned_fail=yes
686		;;
687
688	*)
689		cat >conftest.c <<EOF
690#		include <sys/types.h>
691#		include <sys/wait.h>
692#		include <stdio.h>
693		unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
694		main() {
695		unsigned int i;
696		pid_t pid;
697		int status;
698		/* avoid "core dumped" message */
699		pid = fork();
700		if (pid <  0)
701			exit(2);
702		if (pid > 0) {
703			/* parent */
704			pid = waitpid(pid, &status, 0);
705			if (pid < 0)
706				exit(3);
707			exit(!WIFEXITED(status));
708		}
709		/* child */
710		i = *(unsigned int *)&a[[1]];
711		printf("%d\n", i);
712		exit(0);
713		}
714EOF
715		${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
716		    conftest.c $LIBS >/dev/null 2>&1
717		if test ! -x conftest ; then
718			dnl failed to compile for some reason
719			ac_cv_lbl_unaligned_fail=yes
720		else
721			./conftest >conftest.out
722			if test ! -s conftest.out ; then
723				ac_cv_lbl_unaligned_fail=yes
724			else
725				ac_cv_lbl_unaligned_fail=no
726			fi
727		fi
728		rm -f -r conftest* core core.conftest
729		;;
730	esac])
731    AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
732    if test $ac_cv_lbl_unaligned_fail = yes ; then
733	    AC_DEFINE(LBL_ALIGN,1,[if unaligned access fails])
734    fi])
735
736dnl
737dnl If using gcc and the file .devel exists:
738dnl	Compile with -g (if supported) and -Wall
739dnl	If using gcc 2 or later, do extra prototype checking
740dnl	If an os prototype include exists, symlink os-proto.h to it
741dnl
742dnl usage:
743dnl
744dnl	AC_LBL_DEVEL(copt)
745dnl
746dnl results:
747dnl
748dnl	$1 (copt appended)
749dnl	HAVE_OS_PROTO_H (defined)
750dnl	os-proto.h (symlinked)
751dnl
752AC_DEFUN(AC_LBL_DEVEL,
753    [rm -f os-proto.h
754    if test "${LBL_CFLAGS+set}" = set; then
755	    $1="$$1 ${LBL_CFLAGS}"
756    fi
757    if test -f .devel ; then
758	    if test "$GCC" = yes ; then
759		    if test "${LBL_CFLAGS+set}" != set; then
760			    if test "$ac_cv_prog_cc_g" = yes ; then
761				    $1="-g $$1"
762			    fi
763			    $1="$$1 -Wall"
764			    if test $ac_cv_lbl_gcc_vers -gt 1 ; then
765				    $1="$$1 -Wmissing-prototypes -Wstrict-prototypes"
766			    fi
767		    fi
768	    else
769		    case "$host_os" in
770
771		    irix6*)
772			    V_CCOPT="$V_CCOPT -n32"
773			    ;;
774
775		    *)
776			    ;;
777		    esac
778	    fi
779	    os=`echo $host_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
780	    name="lbl/os-$os.h"
781	    if test -f $name ; then
782		    ln -s $name os-proto.h
783		    AC_DEFINE(HAVE_OS_PROTO_H, 1,
784			[if there's an os_proto.h for this platform, to use additional prototypes])
785	    else
786		    AC_MSG_WARN(can't find $name)
787	    fi
788    fi])
789
790dnl
791dnl Improved version of AC_CHECK_LIB
792dnl
793dnl Thanks to John Hawkinson (jhawk@mit.edu)
794dnl
795dnl usage:
796dnl
797dnl	AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
798dnl	    ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
799dnl
800dnl results:
801dnl
802dnl	LIBS
803dnl
804dnl XXX - "AC_LBL_LIBRARY_NET" was redone to use "AC_SEARCH_LIBS"
805dnl rather than "AC_LBL_CHECK_LIB", so this isn't used any more.
806dnl We keep it around for reference purposes in case it's ever
807dnl useful in the future.
808dnl
809
810define(AC_LBL_CHECK_LIB,
811[AC_MSG_CHECKING([for $2 in -l$1])
812dnl Use a cache variable name containing the library, function
813dnl name, and extra libraries to link with, because the test really is
814dnl for library $1 defining function $2, when linked with potinal
815dnl library $5, not just for library $1.  Separate tests with the same
816dnl $1 and different $2's or $5's may have different results.
817ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
818AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
819[ac_save_LIBS="$LIBS"
820LIBS="-l$1 $5 $LIBS"
821AC_TRY_LINK(dnl
822ifelse([$2], [main], , dnl Avoid conflicting decl of main.
823[/* Override any gcc2 internal prototype to avoid an error.  */
824]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
825extern "C"
826#endif
827])dnl
828[/* We use char because int might match the return type of a gcc2
829    builtin and then its argument prototype would still apply.  */
830char $2();
831]),
832	    [$2()],
833	    eval "ac_cv_lbl_lib_$ac_lib_var=yes",
834	    eval "ac_cv_lbl_lib_$ac_lib_var=no")
835LIBS="$ac_save_LIBS"
836])dnl
837if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
838  AC_MSG_RESULT(yes)
839  ifelse([$3], ,
840[changequote(, )dnl
841  ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
842    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
843changequote([, ])dnl
844  AC_DEFINE_UNQUOTED($ac_tr_lib)
845  LIBS="-l$1 $LIBS"
846], [$3])
847else
848  AC_MSG_RESULT(no)
849ifelse([$4], , , [$4
850])dnl
851fi
852])
853
854dnl
855dnl AC_LBL_LIBRARY_NET
856dnl
857dnl This test is for network applications that need socket() and
858dnl gethostbyname() -ish functions.  Under Solaris, those applications
859dnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
860dnl with "-lnsl" but should *not* link with "-lsocket" because
861dnl libsocket.a breaks a number of things (for instance:
862dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
863dnl versions of IRIX).
864dnl
865dnl Unfortunately, many application developers are not aware of this,
866dnl and mistakenly write tests that cause -lsocket to be used under
867dnl IRIX.  It is also easy to write tests that cause -lnsl to be used
868dnl under operating systems where neither are necessary (or useful),
869dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
870dnl
871dnl This test exists so that every application developer does not test
872dnl this in a different, and subtly broken fashion.
873
874dnl It has been argued that this test should be broken up into two
875dnl seperate tests, one for the resolver libraries, and one for the
876dnl libraries necessary for using Sockets API. Unfortunately, the two
877dnl are carefully intertwined and allowing the autoconf user to use
878dnl them independantly potentially results in unfortunate ordering
879dnl dependancies -- as such, such component macros would have to
880dnl carefully use indirection and be aware if the other components were
881dnl executed. Since other autoconf macros do not go to this trouble,
882dnl and almost no applications use sockets without the resolver, this
883dnl complexity has not been implemented.
884dnl
885dnl The check for libresolv is in case you are attempting to link
886dnl statically and happen to have a libresolv.a lying around (and no
887dnl libnsl.a).
888dnl
889AC_DEFUN(AC_LBL_LIBRARY_NET, [
890    # Most operating systems have gethostbyname() in the default searched
891    # libraries (i.e. libc):
892    # Some OSes (eg. Solaris) place it in libnsl
893    # Some strange OSes (SINIX) have it in libsocket:
894    AC_SEARCH_LIBS(gethostbyname, nsl socket resolv)
895    # Unfortunately libsocket sometimes depends on libnsl and
896    # AC_SEARCH_LIBS isn't up to the task of handling dependencies like this.
897    if test "$ac_cv_search_gethostbyname" = "no"
898    then
899	AC_CHECK_LIB(socket, gethostbyname,
900                     LIBS="-lsocket -lnsl $LIBS", , -lnsl)
901    fi
902    AC_SEARCH_LIBS(socket, socket, ,
903	AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))
904    # DLPI needs putmsg under HPUX so test for -lstr while we're at it
905    AC_SEARCH_LIBS(putmsg, str)
906    ])
907
908dnl
909dnl Test for __attribute__
910dnl
911
912AC_DEFUN(AC_C___ATTRIBUTE__, [
913AC_MSG_CHECKING(for __attribute__)
914AC_CACHE_VAL(ac_cv___attribute__, [
915AC_COMPILE_IFELSE(
916  AC_LANG_SOURCE([[
917#include <stdlib.h>
918
919static void foo(void) __attribute__ ((noreturn));
920
921static void
922foo(void)
923{
924  exit(1);
925}
926
927int
928main(int argc, char **argv)
929{
930  foo();
931}
932  ]]),
933ac_cv___attribute__=yes,
934ac_cv___attribute__=no)])
935if test "$ac_cv___attribute__" = "yes"; then
936  AC_DEFINE(HAVE___ATTRIBUTE__, 1, [define if your compiler has __attribute__])
937  V_DEFS="$V_DEFS -D_U_=\"__attribute__((unused))\""
938else
939  V_DEFS="$V_DEFS -D_U_=\"\""
940fi
941AC_MSG_RESULT($ac_cv___attribute__)
942])
943
944dnl
945dnl Checks to see if tpacket_stats is defined in linux/if_packet.h
946dnl If so then pcap-linux.c can use this to report proper statistics.
947dnl
948dnl -Scott Barron
949dnl
950AC_DEFUN(AC_LBL_TPACKET_STATS,
951   [AC_MSG_CHECKING(if if_packet.h has tpacket_stats defined)
952   AC_CACHE_VAL(ac_cv_lbl_tpacket_stats,
953   AC_TRY_COMPILE([
954#  include <linux/if_packet.h>],
955   [struct tpacket_stats stats],
956   ac_cv_lbl_tpacket_stats=yes,
957   ac_cv_lbl_tpacket_stats=no))
958   AC_MSG_RESULT($ac_cv_lbl_tpacket_stats)
959   if test $ac_cv_lbl_tpacket_stats = yes; then
960       AC_DEFINE(HAVE_TPACKET_STATS,1,[if if_packet.h has tpacket_stats defined])
961   fi])
962
963dnl
964dnl Checks to see if the tpacket_auxdata struct has a tp_vlan_tci member.
965dnl
966dnl usage:
967dnl
968dnl	AC_LBL_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI
969dnl
970dnl results:
971dnl
972dnl	HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI (defined)
973dnl
974dnl NOTE: any compile failure means we conclude that it doesn't have
975dnl that member, so if we don't have tpacket_auxdata, we conclude it
976dnl doesn't have that member (which is OK, as either we won't be using
977dnl code that would use that member, or we wouldn't compile in any case).
978dnl
979AC_DEFUN(AC_LBL_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI,
980    [AC_MSG_CHECKING(if tpacket_auxdata struct has tp_vlan_tci member)
981    AC_CACHE_VAL(ac_cv_lbl_dl_hp_ppa_info_t_has_dl_module_id_1,
982	AC_TRY_COMPILE([
983#	include <linux/if_packet.h>],
984	[u_int i = sizeof(((struct tpacket_auxdata *)0)->tp_vlan_tci)],
985	ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci=yes,
986	ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci=no))
987    AC_MSG_RESULT($ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci)
988    if test $ac_cv_lbl_linux_tpacket_auxdata_tp_vlan_tci = yes ; then
989	    HAVE_LINUX_TPACKET_AUXDATA=tp_vlan_tci
990	    AC_SUBST(HAVE_LINUX_TPACKET_AUXDATA)
991	    AC_DEFINE(HAVE_LINUX_TPACKET_AUXDATA_TP_VLAN_TCI,1,[if tp_vlan_tci exists])
992    fi])
993
994dnl
995dnl Checks to see if Solaris has the dl_passive_req_t struct defined
996dnl in <sys/dlpi.h>.
997dnl
998dnl usage:
999dnl
1000dnl	AC_LBL_DL_PASSIVE_REQ_T
1001dnl
1002dnl results:
1003dnl
1004dnl 	HAVE_DLPI_PASSIVE (defined)
1005dnl
1006AC_DEFUN(AC_LBL_DL_PASSIVE_REQ_T,
1007        [AC_MSG_CHECKING(if dl_passive_req_t struct exists)
1008       AC_CACHE_VAL(ac_cv_lbl_has_dl_passive_req_t,
1009                AC_TRY_COMPILE([
1010#       include <sys/types.h>
1011#       include <sys/dlpi.h>],
1012        [u_int i = sizeof(dl_passive_req_t)],
1013        ac_cv_lbl_has_dl_passive_req_t=yes,
1014        ac_cv_lbl_has_dl_passive_req_t=no))
1015    AC_MSG_RESULT($ac_cv_lbl_has_dl_passive_req_t)
1016    if test $ac_cv_lbl_has_dl_passive_req_t = yes ; then
1017            AC_DEFINE(HAVE_DLPI_PASSIVE,1,[if passive_req_t primitive
1018		exists])
1019    fi])
1020