]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - contrib/traceroute/aclocal.m4
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / contrib / traceroute / aclocal.m4
1 dnl @(#) $Header: aclocal.m4,v 1.73 99/08/14 16:50:02 leres Exp $ (LBL)
2 dnl
3 dnl Copyright (c) 1995, 1996, 1997, 1998, 1999
4 dnl     The Regents of the University of California.  All rights reserved.
5 dnl
6 dnl Redistribution and use in source and binary forms, with or without
7 dnl modification, are permitted provided that: (1) source code distributions
8 dnl retain the above copyright notice and this paragraph in its entirety, (2)
9 dnl distributions including binary code include the above copyright notice and
10 dnl this paragraph in its entirety in the documentation or other materials
11 dnl provided with the distribution, and (3) all advertising materials mentioning
12 dnl features or use of this software display the following acknowledgement:
13 dnl ``This product includes software developed by the University of California,
14 dnl Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 dnl the University nor the names of its contributors may be used to endorse
16 dnl or promote products derived from this software without specific prior
17 dnl written permission.
18 dnl THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 dnl WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 dnl MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 dnl
22 dnl LBL autoconf macros
23 dnl
24
25 dnl
26 dnl Determine which compiler we're using (cc or gcc)
27 dnl If using gcc, determine the version number
28 dnl If using cc, require that it support ansi prototypes
29 dnl If using gcc, use -O2 (otherwise use -O)
30 dnl If using cc, explicitly specify /usr/local/include
31 dnl
32 dnl usage:
33 dnl
34 dnl     AC_LBL_C_INIT(copt, incls)
35 dnl
36 dnl results:
37 dnl
38 dnl     $1 (copt set)
39 dnl     $2 (incls set)
40 dnl     CC
41 dnl     LDFLAGS
42 dnl     LBL_CFLAGS
43 dnl
44 AC_DEFUN(AC_LBL_C_INIT,
45     [AC_PREREQ(2.12)
46     AC_BEFORE([$0], [AC_PROG_CC])
47     AC_BEFORE([$0], [AC_LBL_FIXINCLUDES])
48     AC_BEFORE([$0], [AC_LBL_DEVEL])
49     AC_ARG_WITH(gcc, [  --without-gcc           don't use gcc])
50     $1="-O"
51     $2=""
52     if test "${srcdir}" != "." ; then
53             $2="-I\$\(srcdir\)"
54     fi
55     if test "${CFLAGS+set}" = set; then
56             LBL_CFLAGS="$CFLAGS"
57     fi
58     if test -z "$CC" ; then
59             case "$target_os" in
60
61             bsdi*)
62                     AC_CHECK_PROG(SHLICC2, shlicc2, yes, no)
63                     if test $SHLICC2 = yes ; then
64                             CC=shlicc2
65                             export CC
66                     fi
67                     ;;
68             esac
69     fi
70     if test -z "$CC" -a "$with_gcc" = no ; then
71             CC=cc
72             export CC
73     fi
74     AC_PROG_CC
75     if test "$GCC" != yes ; then
76             AC_MSG_CHECKING(that $CC handles ansi prototypes)
77             AC_CACHE_VAL(ac_cv_lbl_cc_ansi_prototypes,
78                 AC_TRY_COMPILE(
79                     [#include <sys/types.h>],
80                     [int frob(int, char *)],
81                     ac_cv_lbl_cc_ansi_prototypes=yes,
82                     ac_cv_lbl_cc_ansi_prototypes=no))
83             AC_MSG_RESULT($ac_cv_lbl_cc_ansi_prototypes)
84             if test $ac_cv_lbl_cc_ansi_prototypes = no ; then
85                     case "$target_os" in
86
87                     hpux*)
88                             AC_MSG_CHECKING(for HP-UX ansi compiler ($CC -Aa -D_HPUX_SOURCE))
89                             savedcflags="$CFLAGS"
90                             CFLAGS="-Aa -D_HPUX_SOURCE $CFLAGS"
91                             AC_CACHE_VAL(ac_cv_lbl_cc_hpux_cc_aa,
92                                 AC_TRY_COMPILE(
93                                     [#include <sys/types.h>],
94                                     [int frob(int, char *)],
95                                     ac_cv_lbl_cc_hpux_cc_aa=yes,
96                                     ac_cv_lbl_cc_hpux_cc_aa=no))
97                             AC_MSG_RESULT($ac_cv_lbl_cc_hpux_cc_aa)
98                             if test $ac_cv_lbl_cc_hpux_cc_aa = no ; then
99                                     AC_MSG_ERROR(see the INSTALL doc for more info)
100                             fi
101                             CFLAGS="$savedcflags"
102                             $1="-Aa $$1"
103                             AC_DEFINE(_HPUX_SOURCE)
104                             ;;
105
106                     *)
107                             AC_MSG_ERROR(see the INSTALL doc for more info)
108                             ;;
109                     esac
110             fi
111             $2="$$2 -I/usr/local/include"
112             LDFLAGS="$LDFLAGS -L/usr/local/lib"
113
114             case "$target_os" in
115
116             irix*)
117                     $1="$$1 -xansi -signed -g3"
118                     ;;
119
120             osf*)
121                     $1="$$1 -std1 -g3"
122                     ;;
123
124             ultrix*)
125                     AC_MSG_CHECKING(that Ultrix $CC hacks const in prototypes)
126                     AC_CACHE_VAL(ac_cv_lbl_cc_const_proto,
127                         AC_TRY_COMPILE(
128                             [#include <sys/types.h>],
129                             [struct a { int b; };
130                             void c(const struct a *)],
131                             ac_cv_lbl_cc_const_proto=yes,
132                             ac_cv_lbl_cc_const_proto=no))
133                     AC_MSG_RESULT($ac_cv_lbl_cc_const_proto)
134                     if test $ac_cv_lbl_cc_const_proto = no ; then
135                             AC_DEFINE(const,)
136                     fi
137                     ;;
138             esac
139     fi
140 ])
141
142 dnl
143 dnl Use pfopen.c if available and pfopen() not in standard libraries
144 dnl Require libpcap
145 dnl Look for libpcap in ..
146 dnl Use the installed libpcap if there is no local version
147 dnl
148 dnl usage:
149 dnl
150 dnl     AC_LBL_LIBPCAP(pcapdep, incls)
151 dnl
152 dnl results:
153 dnl
154 dnl     $1 (pcapdep set)
155 dnl     $2 (incls appended)
156 dnl     LIBS
157 dnl     LDFLAGS
158 dnl     LBL_LIBS
159 dnl
160 AC_DEFUN(AC_LBL_LIBPCAP,
161     [AC_REQUIRE([AC_LBL_LIBRARY_NET])
162     dnl
163     dnl save a copy before locating libpcap.a
164     dnl
165     LBL_LIBS="$LIBS"
166     pfopen=/usr/examples/packetfilter/pfopen.c
167     if test -f $pfopen ; then
168             AC_CHECK_FUNCS(pfopen)
169             if test $ac_cv_func_pfopen = "no" ; then
170                     AC_MSG_RESULT(Using $pfopen)
171                     LIBS="$LIBS $pfopen"
172             fi
173     fi
174     AC_MSG_CHECKING(for local pcap library)
175     libpcap=FAIL
176     lastdir=FAIL
177     places=`ls .. | sed -e 's,/$,,' -e 's,^,../,' | \
178         egrep '/libpcap-[[0-9]]*\.[[0-9]]*(\.[[0-9]]*)?([[ab]][[0-9]]*)?$'`
179     for dir in $places ../libpcap libpcap ; do
180             basedir=`echo $dir | sed -e 's/[[ab]][[0-9]]*$//'`
181             if test $lastdir = $basedir ; then
182                     dnl skip alphas when an actual release is present
183                     continue;
184             fi
185             lastdir=$dir
186             if test -r $dir/pcap.c ; then
187                     libpcap=$dir/libpcap.a
188                     d=$dir
189                     dnl continue and select the last one that exists
190             fi
191     done
192     if test "x$libpcap" = xFAIL ; then
193             AC_MSG_RESULT(not found)
194             unset ac_cv_lbl_lib_pcap_pcap_open_live_
195             AC_LBL_CHECK_LIB(pcap, pcap_open_live, libpcap="-lpcap")
196             if test "x$libpcap" = xFAIL ; then
197                     unset ac_cv_lbl_lib_pcap_pcap_open_live_
198                     CFLAGS="$CFLAGS -I/usr/local/include"
199                     LIBS="$LIBS -L/usr/local/lib"
200                     AC_LBL_CHECK_LIB(pcap, pcap_open_live, libpcap="-lpcap")
201                     if test "x$libpcap" = xFAIL ; then
202                             AC_MSG_ERROR(see the INSTALL doc for more info)
203                     fi
204                     $2="$$2 -I/usr/local/include"
205             fi
206             LIBS="$LIBS -lpcap"
207     else
208             $1=$libpcap
209             $2="-I$d $$2"
210             AC_MSG_RESULT($libpcap)
211     fi
212     if test "x$libpcap" != "x-lpcap" ; then
213             LIBS="$libpcap $LIBS"
214     fi
215     case "$target_os" in
216
217     aix*)
218             pseexe="/lib/pse.exp"
219             AC_MSG_CHECKING(for $pseexe)
220             if test -f $pseexe ; then
221                     AC_MSG_RESULT(yes)
222                     LIBS="$LIBS -I:$pseexe"
223             fi
224             ;;
225     esac])
226
227 dnl
228 dnl Define RETSIGTYPE and RETSIGVAL
229 dnl
230 dnl usage:
231 dnl
232 dnl     AC_LBL_TYPE_SIGNAL
233 dnl
234 dnl results:
235 dnl
236 dnl     RETSIGTYPE (defined)
237 dnl     RETSIGVAL (defined)
238 dnl
239 AC_DEFUN(AC_LBL_TYPE_SIGNAL,
240     [AC_BEFORE([$0], [AC_LBL_LIBPCAP])
241     AC_TYPE_SIGNAL
242     if test "$ac_cv_type_signal" = void ; then
243             AC_DEFINE(RETSIGVAL,)
244     else
245             AC_DEFINE(RETSIGVAL,(0))
246     fi
247     case "$target_os" in
248
249     irix*)
250             AC_DEFINE(_BSD_SIGNALS)
251             ;;
252
253     *)
254             dnl prefer sigset() to sigaction()
255             AC_CHECK_FUNCS(sigset)
256             if test $ac_cv_func_sigset = yes ; then
257                     AC_DEFINE(signal,sigset)
258             else
259                     AC_CHECK_FUNCS(sigaction)
260             fi
261             ;;
262     esac])
263
264 dnl
265 dnl If using gcc, make sure we have ANSI ioctl definitions
266 dnl
267 dnl usage:
268 dnl
269 dnl     AC_LBL_FIXINCLUDES
270 dnl
271 AC_DEFUN(AC_LBL_FIXINCLUDES,
272     [if test "$GCC" = yes ; then
273             AC_MSG_CHECKING(for ANSI ioctl definitions)
274             AC_CACHE_VAL(ac_cv_lbl_gcc_fixincludes,
275                 AC_TRY_COMPILE(
276                     [/*
277                      * This generates a "duplicate case value" when fixincludes
278                      * has not be run.
279                      */
280 #               include <sys/types.h>
281 #               include <sys/time.h>
282 #               include <sys/ioctl.h>
283 #               ifdef HAVE_SYS_IOCCOM_H
284 #               include <sys/ioccom.h>
285 #               endif],
286                     [switch (0) {
287                     case _IO('A', 1):;
288                     case _IO('B', 1):;
289                     }],
290                     ac_cv_lbl_gcc_fixincludes=yes,
291                     ac_cv_lbl_gcc_fixincludes=no))
292             AC_MSG_RESULT($ac_cv_lbl_gcc_fixincludes)
293             if test $ac_cv_lbl_gcc_fixincludes = no ; then
294                     # Don't cache failure
295                     unset ac_cv_lbl_gcc_fixincludes
296                     AC_MSG_ERROR(see the INSTALL for more info)
297             fi
298     fi])
299
300 dnl
301 dnl Check for flex, default to lex
302 dnl Require flex 2.4 or higher
303 dnl Check for bison, default to yacc
304 dnl Default to lex/yacc if both flex and bison are not available
305 dnl Define the yy prefix string if using flex and bison
306 dnl
307 dnl usage:
308 dnl
309 dnl     AC_LBL_LEX_AND_YACC(lex, yacc, yyprefix)
310 dnl
311 dnl results:
312 dnl
313 dnl     $1 (lex set)
314 dnl     $2 (yacc appended)
315 dnl     $3 (optional flex and bison -P prefix)
316 dnl
317 AC_DEFUN(AC_LBL_LEX_AND_YACC,
318     [AC_ARG_WITH(flex, [  --without-flex          don't use flex])
319     AC_ARG_WITH(bison, [  --without-bison         don't use bison])
320     if test "$with_flex" = no ; then
321             $1=lex
322     else
323             AC_CHECK_PROGS($1, flex, lex)
324     fi
325     if test "$$1" = flex ; then
326             # The -V flag was added in 2.4
327             AC_MSG_CHECKING(for flex 2.4 or higher)
328             AC_CACHE_VAL(ac_cv_lbl_flex_v24,
329                 if flex -V >/dev/null 2>&1; then
330                         ac_cv_lbl_flex_v24=yes
331                 else
332                         ac_cv_lbl_flex_v24=no
333                 fi)
334             AC_MSG_RESULT($ac_cv_lbl_flex_v24)
335             if test $ac_cv_lbl_flex_v24 = no ; then
336                     s="2.4 or higher required"
337                     AC_MSG_WARN(ignoring obsolete flex executable ($s))
338                     $1=lex
339             fi
340     fi
341     if test "$with_bison" = no ; then
342             $2=yacc
343     else
344             AC_CHECK_PROGS($2, bison, yacc)
345     fi
346     if test "$$2" = bison ; then
347             $2="$$2 -y"
348     fi
349     if test "$$1" != lex -a "$$2" = yacc -o "$$1" = lex -a "$$2" != yacc ; then
350             AC_MSG_WARN(don't have both flex and bison; reverting to lex/yacc)
351             $1=lex
352             $2=yacc
353     fi
354     if test "$$1" = flex -a -n "$3" ; then
355             $1="$$1 -P$3"
356             $2="$$2 -p $3"
357     fi])
358
359 dnl
360 dnl Checks to see if union wait is used with WEXITSTATUS()
361 dnl
362 dnl usage:
363 dnl
364 dnl     AC_LBL_UNION_WAIT
365 dnl
366 dnl results:
367 dnl
368 dnl     DECLWAITSTATUS (defined)
369 dnl
370 AC_DEFUN(AC_LBL_UNION_WAIT,
371     [AC_MSG_CHECKING(if union wait is used)
372     AC_CACHE_VAL(ac_cv_lbl_union_wait,
373         AC_TRY_COMPILE([
374 #       include <sys/types.h>
375 #       include <sys/wait.h>],
376             [int status;
377             u_int i = WEXITSTATUS(status);
378             u_int j = waitpid(0, &status, 0);],
379             ac_cv_lbl_union_wait=no,
380             ac_cv_lbl_union_wait=yes))
381     AC_MSG_RESULT($ac_cv_lbl_union_wait)
382     if test $ac_cv_lbl_union_wait = yes ; then
383             AC_DEFINE(DECLWAITSTATUS,union wait)
384     else
385             AC_DEFINE(DECLWAITSTATUS,int)
386     fi])
387
388 dnl
389 dnl Checks to see if the sockaddr struct has the 4.4 BSD sa_len member
390 dnl
391 dnl usage:
392 dnl
393 dnl     AC_LBL_SOCKADDR_SA_LEN
394 dnl
395 dnl results:
396 dnl
397 dnl     HAVE_SOCKADDR_SA_LEN (defined)
398 dnl
399 AC_DEFUN(AC_LBL_SOCKADDR_SA_LEN,
400     [AC_MSG_CHECKING(if sockaddr struct has sa_len member)
401     AC_CACHE_VAL(ac_cv_lbl_sockaddr_has_sa_len,
402         AC_TRY_COMPILE([
403 #       include <sys/types.h>
404 #       include <sys/socket.h>],
405         [u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
406         ac_cv_lbl_sockaddr_has_sa_len=yes,
407         ac_cv_lbl_sockaddr_has_sa_len=no))
408     AC_MSG_RESULT($ac_cv_lbl_sockaddr_has_sa_len)
409     if test $ac_cv_lbl_sockaddr_has_sa_len = yes ; then
410             AC_DEFINE(HAVE_SOCKADDR_SA_LEN)
411     fi])
412
413 dnl
414 dnl Checks to see if the IFF_LOOPBACK exists as a define or enum
415 dnl
416 dnl   (stupidly some versions of linux use an enum...)
417 dnl
418 dnl usage:
419 dnl
420 dnl     AC_LBL_IFF_LOOPBACK
421 dnl
422 dnl results:
423 dnl
424 dnl     HAVE_IFF_LOOPBACK (defined)
425 dnl
426 AC_DEFUN(AC_LBL_IFF_LOOPBACK,
427     [AC_MSG_CHECKING(for IFF_LOOPBACK define/enum)
428     AC_CACHE_VAL(ac_cv_lbl_have_iff_loopback,
429         AC_TRY_COMPILE([
430 #       include <sys/param.h>
431 #       include <sys/file.h>
432 #       include <sys/ioctl.h>
433 #       include <sys/socket.h>
434 #       ifdef HAVE_SYS_SOCKIO_H
435 #       include <sys/sockio.h>
436 #       endif
437 #       include <sys/time.h>
438 #       include <net/if.h>
439 #       include <netinet/in.h>],
440         [int i = IFF_LOOPBACK],
441         ac_cv_lbl_have_iff_loopback=yes,
442         ac_cv_lbl_have_iff_loopback=no))
443     AC_MSG_RESULT($ac_cv_lbl_have_iff_loopback)
444     if test $ac_cv_lbl_have_iff_loopback = yes ; then
445             AC_DEFINE(HAVE_IFF_LOOPBACK)
446     fi])
447
448 dnl
449 dnl Checks to see if -R is used
450 dnl
451 dnl usage:
452 dnl
453 dnl     AC_LBL_HAVE_RUN_PATH
454 dnl
455 dnl results:
456 dnl
457 dnl     ac_cv_lbl_have_run_path (yes or no)
458 dnl
459 AC_DEFUN(AC_LBL_HAVE_RUN_PATH,
460     [AC_MSG_CHECKING(for ${CC-cc} -R)
461     AC_CACHE_VAL(ac_cv_lbl_have_run_path,
462         [echo 'main(){}' > conftest.c
463         ${CC-cc} -o conftest conftest.c -R/a1/b2/c3 >conftest.out 2>&1
464         if test ! -s conftest.out ; then
465                 ac_cv_lbl_have_run_path=yes
466         else
467                 ac_cv_lbl_have_run_path=no
468         fi
469         rm -f conftest*])
470     AC_MSG_RESULT($ac_cv_lbl_have_run_path)
471     ])
472
473 dnl
474 dnl Due to the stupid way it's implemented, AC_CHECK_TYPE is nearly useless.
475 dnl
476 dnl usage:
477 dnl
478 dnl     AC_LBL_CHECK_TYPE
479 dnl
480 dnl results:
481 dnl
482 dnl     int32_t (defined)
483 dnl     u_int32_t (defined)
484 dnl
485 AC_DEFUN(AC_LBL_CHECK_TYPE,
486     [AC_MSG_CHECKING(for $1 using $CC)
487     AC_CACHE_VAL(ac_cv_lbl_have_$1,
488         AC_TRY_COMPILE([
489 #       include "confdefs.h"
490 #       include <sys/types.h>
491 #       if STDC_HEADERS
492 #       include <stdlib.h>
493 #       include <stddef.h>
494 #       endif],
495         [$1 i],
496         ac_cv_lbl_have_$1=yes,
497         ac_cv_lbl_have_$1=no))
498     AC_MSG_RESULT($ac_cv_lbl_have_$1)
499     if test $ac_cv_lbl_have_$1 = no ; then
500             AC_DEFINE($1, $2)
501     fi])
502
503 dnl
504 dnl Checks to see if unaligned memory accesses fail
505 dnl
506 dnl usage:
507 dnl
508 dnl     AC_LBL_UNALIGNED_ACCESS
509 dnl
510 dnl results:
511 dnl
512 dnl     LBL_ALIGN (DEFINED)
513 dnl
514 AC_DEFUN(AC_LBL_UNALIGNED_ACCESS,
515     [AC_MSG_CHECKING(if unaligned accesses fail)
516     AC_CACHE_VAL(ac_cv_lbl_unaligned_fail,
517         [case "$target_cpu" in
518
519         alpha|hp*|mips|sparc)
520                 ac_cv_lbl_unaligned_fail=yes
521                 ;;
522
523         *)
524                 cat >conftest.c <<EOF
525 #               include <sys/types.h>
526 #               include <sys/wait.h>
527 #               include <stdio.h>
528                 unsigned char a[[5]] = { 1, 2, 3, 4, 5 };
529                 main() {
530                 unsigned int i;
531                 pid_t pid;
532                 int status;
533                 /* avoid "core dumped" message */
534                 pid = fork();
535                 if (pid <  0)
536                         exit(2);
537                 if (pid > 0) {
538                         /* parent */
539                         pid = waitpid(pid, &status, 0);
540                         if (pid < 0)
541                                 exit(3);
542                         exit(!WIFEXITED(status));
543                 }
544                 /* child */
545                 i = *(unsigned int *)&a[[1]];
546                 printf("%d\n", i);
547                 exit(0);
548                 }
549 EOF
550                 ${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS \
551                     conftest.c $LIBS >/dev/null 2>&1
552                 if test ! -x conftest ; then
553                         dnl failed to compile for some reason
554                         ac_cv_lbl_unaligned_fail=yes
555                 else
556                         ./conftest >conftest.out
557                         if test ! -s conftest.out ; then
558                                 ac_cv_lbl_unaligned_fail=yes
559                         else
560                                 ac_cv_lbl_unaligned_fail=no
561                         fi
562                 fi
563                 rm -f conftest* core core.conftest
564                 ;;
565         esac])
566     AC_MSG_RESULT($ac_cv_lbl_unaligned_fail)
567     if test $ac_cv_lbl_unaligned_fail = yes ; then
568             AC_DEFINE(LBL_ALIGN)
569     fi])
570
571 dnl
572 dnl add all warning option to CFLAGS
573 dnl
574 dnl usage:
575 dnl
576 dnl     AC_LBL_CHECK_WALL(copt)
577 dnl
578 dnl results:
579 dnl
580 dnl     $1 (copt appended)
581 dnl     ac_cv_lbl_gcc_vers
582 dnl
583 AC_DEFUN(AC_LBL_CHECK_WALL,
584     [ if test "$GCC" = yes ; then
585             if test "$SHLICC2" = yes ; then
586                     ac_cv_lbl_gcc_vers=2
587                     $1="`echo $$1 | sed -e 's/-O/-O2/'`"
588             else
589                     AC_MSG_CHECKING(gcc version)
590                     AC_CACHE_VAL(ac_cv_lbl_gcc_vers,
591                         ac_cv_lbl_gcc_vers=`$CC --version 2>&1 | \
592                             sed -e 's/\..*//'`)
593                     AC_MSG_RESULT($ac_cv_lbl_gcc_vers)
594                     if test $ac_cv_lbl_gcc_vers -gt 1 ; then
595                             $1="`echo $$1 | sed -e 's/-O/-O2/'`"
596                     fi
597             fi
598             if test "${LBL_CFLAGS+set}" != set; then
599                     if test "$ac_cv_prog_cc_g" = yes ; then
600                             $1="-g $$1"
601                     fi
602                     $1="$$1 -Wall"
603                     if test $ac_cv_lbl_gcc_vers -gt 1 ; then
604                             $1="$$1 -Wmissing-prototypes -Wstrict-prototypes"
605                     fi
606             fi
607     else
608             case "$target_os" in
609
610             irix6*)
611                     $1="$$1 -fullwarn -n32"
612                     ;;
613
614             *)
615                     ;;
616             esac
617     fi])
618
619 dnl
620 dnl If using gcc and the file .devel exists:
621 dnl     Compile with -g (if supported) and -Wall
622 dnl     If using gcc 2, do extra prototype checking
623 dnl     If an os prototype include exists, symlink os-proto.h to it
624 dnl
625 dnl usage:
626 dnl
627 dnl     AC_LBL_DEVEL(copt)
628 dnl
629 dnl results:
630 dnl
631 dnl     $1 (copt appended)
632 dnl     HAVE_OS_PROTO_H (defined)
633 dnl     os-proto.h (symlinked)
634 dnl
635 AC_DEFUN(AC_LBL_DEVEL,
636     [rm -f os-proto.h
637     if test "${LBL_CFLAGS+set}" = set; then
638             $1="$$1 ${LBL_CFLAGS}"
639     fi
640     if test -f .devel ; then
641             AC_LBL_CHECK_WALL($1)
642             os=`echo $target_os | sed -e 's/\([[0-9]][[0-9]]*\)[[^0-9]].*$/\1/'`
643             name="lbl/os-$os.h"
644             if test -f $name ; then
645                     ln -s $name os-proto.h
646                     AC_DEFINE(HAVE_OS_PROTO_H)
647             else
648                     AC_MSG_WARN(can't find $name)
649             fi
650     fi])
651
652 dnl
653 dnl Improved version of AC_CHECK_LIB
654 dnl
655 dnl Thanks to John Hawkinson (jhawk@mit.edu)
656 dnl
657 dnl usage:
658 dnl
659 dnl     AC_LBL_CHECK_LIB(LIBRARY, FUNCTION [, ACTION-IF-FOUND [,
660 dnl         ACTION-IF-NOT-FOUND [, OTHER-LIBRARIES]]])
661 dnl
662 dnl results:
663 dnl
664 dnl     LIBS
665 dnl
666
667 define(AC_LBL_CHECK_LIB,
668 [AC_MSG_CHECKING([for $2 in -l$1])
669 dnl Use a cache variable name containing both the library and function name,
670 dnl because the test really is for library $1 defining function $2, not
671 dnl just for library $1.  Separate tests with the same $1 and different $2's
672 dnl may have different results.
673 ac_lib_var=`echo $1['_']$2['_']$5 | sed 'y%./+- %__p__%'`
674 AC_CACHE_VAL(ac_cv_lbl_lib_$ac_lib_var,
675 [ac_save_LIBS="$LIBS"
676 LIBS="-l$1 $5 $LIBS"
677 AC_TRY_LINK(dnl
678 ifelse([$2], [main], , dnl Avoid conflicting decl of main.
679 [/* Override any gcc2 internal prototype to avoid an error.  */
680 ]ifelse(AC_LANG, CPLUSPLUS, [#ifdef __cplusplus
681 extern "C"
682 #endif
683 ])dnl
684 [/* We use char because int might match the return type of a gcc2
685     builtin and then its argument prototype would still apply.  */
686 char $2();
687 ]),
688             [$2()],
689             eval "ac_cv_lbl_lib_$ac_lib_var=yes",
690             eval "ac_cv_lbl_lib_$ac_lib_var=no")
691 LIBS="$ac_save_LIBS"
692 ])dnl
693 if eval "test \"`echo '$ac_cv_lbl_lib_'$ac_lib_var`\" = yes"; then
694   AC_MSG_RESULT(yes)
695   ifelse([$3], ,
696 [changequote(, )dnl
697   ac_tr_lib=HAVE_LIB`echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g' \
698     -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
699 changequote([, ])dnl
700   AC_DEFINE_UNQUOTED($ac_tr_lib)
701   LIBS="-l$1 $LIBS"
702 ], [$3])
703 else
704   AC_MSG_RESULT(no)
705 ifelse([$4], , , [$4
706 ])dnl
707 fi
708 ])
709
710 dnl
711 dnl AC_LBL_LIBRARY_NET
712 dnl
713 dnl This test is for network applications that need socket() and
714 dnl gethostbyname() -ish functions.  Under Solaris, those applications
715 dnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
716 dnl with "-lnsl" but should *not* link with "-lsocket" because
717 dnl libsocket.a breaks a number of things (for instance:
718 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
719 dnl versions of IRIX).
720 dnl
721 dnl Unfortunately, many application developers are not aware of this,
722 dnl and mistakenly write tests that cause -lsocket to be used under
723 dnl IRIX.  It is also easy to write tests that cause -lnsl to be used
724 dnl under operating systems where neither are necessary (or useful),
725 dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
726 dnl
727 dnl This test exists so that every application developer does not test
728 dnl this in a different, and subtly broken fashion.
729
730 dnl It has been argued that this test should be broken up into two
731 dnl seperate tests, one for the resolver libraries, and one for the
732 dnl libraries necessary for using Sockets API. Unfortunately, the two
733 dnl are carefully intertwined and allowing the autoconf user to use
734 dnl them independantly potentially results in unfortunate ordering
735 dnl dependancies -- as such, such component macros would have to
736 dnl carefully use indirection and be aware if the other components were
737 dnl executed. Since other autoconf macros do not go to this trouble,
738 dnl and almost no applications use sockets without the resolver, this
739 dnl complexity has not been implemented.
740 dnl
741 dnl The check for libresolv is in case you are attempting to link
742 dnl statically and happen to have a libresolv.a lying around (and no
743 dnl libnsl.a).
744 dnl
745 AC_DEFUN(AC_LBL_LIBRARY_NET, [
746     # Most operating systems have gethostbyname() in the default searched
747     # libraries (i.e. libc):
748     AC_CHECK_FUNC(gethostbyname, ,
749         # Some OSes (eg. Solaris) place it in libnsl:
750         AC_LBL_CHECK_LIB(nsl, gethostbyname, , 
751             # Some strange OSes (SINIX) have it in libsocket:
752             AC_LBL_CHECK_LIB(socket, gethostbyname, ,
753                 # Unfortunately libsocket sometimes depends on libnsl.
754                 # AC_CHECK_LIB's API is essentially broken so the
755                 # following ugliness is necessary:
756                 AC_LBL_CHECK_LIB(socket, gethostbyname,
757                     LIBS="-lsocket -lnsl $LIBS",
758                     AC_CHECK_LIB(resolv, gethostbyname),
759                     -lnsl))))
760     AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
761         AC_LBL_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", ,
762             -lnsl)))
763     # DLPI needs putmsg under HPUX so test for -lstr while we're at it
764     AC_CHECK_LIB(str, putmsg)
765     ])