source: trunk/third/traceroute/aclocal.m4 @ 14596

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