1dnl
2dnl AC_LBL_LIBRARY_NET
3dnl
4dnl This test is for network applications that need socket() and
5dnl gethostbyname() -ish functions.  Under Solaris, those applications
6dnl need to link with "-lsocket -lnsl".  Under IRIX, they need to link
7dnl with "-lnsl" but should *not* link with "-lsocket" because
8dnl libsocket.a breaks a number of things (for instance:
9dnl gethostbyname() under IRIX 5.2, and snoop sockets under most
10dnl versions of IRIX).
11dnl
12dnl Unfortunately, many application developers are not aware of this,
13dnl and mistakenly write tests that cause -lsocket to be used under
14dnl IRIX.  It is also easy to write tests that cause -lnsl to be used
15dnl under operating systems where neither are necessary (or useful),
16dnl such as SunOS 4.1.4, which uses -lnsl for TLI.
17dnl
18dnl This test exists so that every application developer does not test
19dnl this in a different, and subtly broken fashion.
20
21dnl It has been argued that this test should be broken up into two
22dnl seperate tests, one for the resolver libraries, and one for the
23dnl libraries necessary for using Sockets API. Unfortunately, the two
24dnl are carefully intertwined and allowing the autoconf user to use
25dnl them independantly potentially results in unfortunate ordering
26dnl dependancies -- as such, such component macros would have to
27dnl carefully use indirection and be aware if the other components were
28dnl executed. Since other autoconf macros do not go to this trouble,
29dnl and almost no applications use sockets without the resolver, this
30dnl complexity has not been implemented.
31dnl
32dnl The check for libresolv is in case you are attempting to link
33dnl statically and happen to have a libresolv.a lying around (and no
34dnl libnsl.a).
35dnl
36AC_DEFUN(AC_LBL_LIBRARY_NET, [
37    # Most operating systems have gethostbyname() in the default searched
38    # libraries (i.e. libc):
39    AC_CHECK_FUNC(gethostbyname, ,
40        # Some OSes (eg. Solaris) place it in libnsl:
41        AC_CHECK_LIB(nsl, gethostbyname, ,
42            # Some strange OSes (SINIX) have it in libsocket:
43            AC_CHECK_LIB(socket, gethostbyname, ,
44                # Unfortunately libsocket sometimes depends on libnsl.
45                # AC_CHECK_LIB's API is essentially broken so the
46                # following ugliness is necessary:
47                AC_CHECK_LIB(socket, gethostbyname,
48                    LIBS="-lsocket -lnsl $LIBS",
49                    AC_CHECK_LIB(resolv, gethostbyname),
50                    -lnsl))))
51    AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
52        AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", ,
53            -lnsl)))
54    # DLPI needs putmsg under HPUX so test for -lstr while we're at it
55    AC_CHECK_LIB(str, putmsg)
56    ])
57