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