* aclocal.m4 (WITH_NETLIB): Use AC_LIBRARY_NET.
authorEzra Peisach <epeisach@mit.edu>
Tue, 28 Oct 1997 16:56:29 +0000 (16:56 +0000)
committerEzra Peisach <epeisach@mit.edu>
Tue, 28 Oct 1997 16:56:29 +0000 (16:56 +0000)
             (AC_LIBRARY_NET): Written by jhawk@mit.edu to
     better determine if libsocket and libnsl are needed.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10256 dc483132-0cff-0310-8789-dd5450dbe970

src/ChangeLog
src/aclocal.m4

index 90addf2b02d1db21e9240685dac2a563282b1027..7db491195829b67e3e810201b8b40fc349526231 100644 (file)
@@ -1,3 +1,9 @@
+Tue Oct 28 11:49:55 1997  Ezra Peisach  <epeisach@mit.edu>
+
+       * aclocal.m4 (WITH_NETLIB): Use AC_LIBRARY_NET.
+                    (AC_LIBRARY_NET): Written by jhawk@mit.edu to 
+                       better determine if libsocket and libnsl are needed.
+
 Thu Oct 23 12:08:24 1997  Ezra Peisach  <epeisach@mit.edu>
 
        * aclocal.m4 (TCL_WITH): Check for libtcl8.0.
index da2219f2522a19d86dd9a3fc6fd5913574d24b94..df4b67a585520636b1a1fa95f7e27c3572f430c6 100644 (file)
@@ -658,10 +658,7 @@ AC_ARG_WITH([netlib],
        AC_MSG_RESULT("netlib will use \'$withval\'")
   fi
 ,dnl
-[if test "`(uname) 2>/dev/null`" != IRIX ; then
-  AC_CHECK_LIB(socket,main)
-fi
-AC_CHECK_LIB(nsl,main)]
+[AC_LIBRARY_NET]
 )])dnl
 dnl
 dnl HAS_ANSI_VOLATILE
@@ -1373,3 +1370,58 @@ mips-*-netbsd*)
        RUN_ENV='LIBPATH=`echo $(PROG_LIBPATH) | sed -e "s/-L//g" -e "s/ /:/g"`:$(PROG_RPATH):/usr/lib:/usr/local/lib; export LIBPATH; '
 
 esac])
+dnl
+dnl The following was written by jhawk@mit.edu
+dnl
+dnl AC_LIBRARY_NET: Id: net.m4,v 1.4 1997/10/25 20:49:53 jhawk Exp 
+dnl
+dnl This test is for network applications that need socket() and
+dnl gethostbyname() -ish functions.  Under Solaris, those applications need to
+dnl link with "-lsocket -lnsl".  Under IRIX, they should *not* link with
+dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
+dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
+dnl IRIX).
+dnl 
+dnl Unfortunately, many application developers are not aware of this, and
+dnl mistakenly write tests that cause -lsocket to be used under IRIX.  It is
+dnl also easy to write tests that cause -lnsl to be used under operating
+dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
+dnl uses -lnsl for TLI.
+dnl 
+dnl This test exists so that every application developer does not test this in
+dnl a different, and subtly broken fashion.
+dnl 
+dnl It has been argued that this test should be broken up into two seperate
+dnl tests, one for the resolver libraries, and one for the libraries necessary
+dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
+dnl allowing the autoconf user to use them independantly potentially results in
+dnl unfortunate ordering dependancies -- as such, such component macros would
+dnl have to carefully use indirection and be aware if the other components were
+dnl executed. Since other autoconf macros do not go to this trouble, and almost
+dnl no applications use sockets without the resolver, this complexity has not
+dnl been implemented.
+dnl
+dnl The check for libresolv is in case you are attempting to link statically
+dnl and happen to have a libresolv.a lying around (and no libnsl.a).
+dnl
+AC_DEFUN(AC_LIBRARY_NET, [
+   # Most operating systems have gethostbyname() in the default searched
+   # libraries (i.e. libc):
+   AC_CHECK_FUNC(gethostbyname, ,
+     # Some OSes (eg. Solaris) place it in libnsl:
+     AC_CHECK_LIB(nsl, gethostbyname, , 
+       # Some strange OSes (SINIX) have it in libsocket:
+       AC_CHECK_LIB(socket, gethostbyname, ,
+          # Unfortunately libsocket sometimes depends on libnsl.
+          # AC_CHECK_LIB's API is essentially broken so the following
+          # ugliness is necessary:
+          AC_CHECK_LIB(socket, gethostbyname,
+             LIBS="-lsocket -lnsl $LIBS",
+               AC_CHECK_LIB(resolv, gethostbyname),
+             -lnsl)
+       )
+     )
+   )
+  AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
+    AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))
+  ])