2 dnl Macro: unet_PIPE_CFLAGS
4 dnl If the compiler understands -pipe, add it to CFLAGS if not already
7 AC_DEFUN(unet_PIPE_CFLAGS,
8 [AC_MSG_CHECKING([if the compiler understands -pipe])
9 unet_cv_pipe_flags="$ac_cv_prog_gcc"
10 if test "$ac_cv_prog_gcc" = no; then
12 CFLAGS="$CFLAGS -pipe"
13 AC_TRY_COMPILE(,,unet_cv_pipe_flags=yes,)
16 AC_MSG_RESULT($unet_cv_pipe_flags)
17 if test "$unet_cv_pipe_flags" = yes ; then
18 x=`echo $CFLAGS | grep 'pipe' 2>/dev/null`
19 if test "$x" = "" ; then
20 CFLAGS="$CFLAGS -pipe"
26 dnl Macro: unet_NONBLOCKING
28 dnl Check whether we have posix, bsd or sysv non-blocking sockets and
29 dnl define respectively NBLOCK_POSIX, NBLOCK_BSD or NBLOCK_SYSV.
31 AC_DEFUN(unet_NONBLOCKING,
32 [dnl Do we have posix, bsd or sysv non-blocking stuff ?
33 AC_CACHE_CHECK([for posix non-blocking], unet_cv_sys_nonblocking_posix,
34 [AC_TRY_RUN([#include <sys/types.h>
35 #include <sys/socket.h>
37 #include <sys/ioctl.h>
40 $ac_cv_type_signal alarmed() { exit(1); }
46 int f = socket(AF_INET, SOCK_DGRAM, 0);
47 if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
49 signal(SIGALRM, alarmed);
51 recvfrom(f, b, 12, 0, &x, &l);
56 }], unet_cv_sys_nonblocking_posix=yes, unet_cv_sys_nonblocking_posix=no)])
57 if test $unet_cv_sys_nonblocking_posix = yes; then
58 AC_DEFINE(NBLOCK_POSIX)
60 AC_CACHE_CHECK([for bsd non-blocking], unet_cv_sys_nonblocking_bsd,
61 [AC_TRY_RUN([#include <sys/types.h>
62 #include <sys/socket.h>
64 #include <sys/ioctl.h>
67 $ac_cv_type_signal alarmed() { exit(1); }
73 int f = socket(AF_INET, SOCK_DGRAM, 0);
74 if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY)))
76 signal(SIGALRM, alarmed);
78 recvfrom(f, b, 12, 0, &x, &l);
83 }], unet_cv_sys_nonblocking_bsd=yes, unet_cv_sys_nonblocking_bsd=no)])
84 if test $unet_cv_sys_nonblocking_bsd = yes; then
87 AC_DEFINE(NBLOCK_SYSV)
92 dnl Macro: unet_SIGNALS
94 dnl Check if we have posix signals, reliable bsd signals or
95 dnl unreliable sysv signals and define respectively POSIX_SIGNALS,
96 dnl BSD_RELIABLE_SIGNALS or SYSV_UNRELIABLE_SIGNALS.
98 AC_DEFUN(unet_SIGNALS,
99 [dnl Do we have posix signals, reliable bsd signals or unreliable sysv signals ?
100 AC_CACHE_CHECK([for posix signals], unet_cv_sys_signal_posix,
101 [AC_TRY_COMPILE([#include <signal.h>],
102 [sigaction(SIGTERM, (struct sigaction *)0L, (struct sigaction *)0L)],
103 unet_cv_sys_signal_posix=yes, unet_cv_sys_signal_posix=no)])
104 if test $unet_cv_sys_signal_posix = yes; then
105 AC_DEFINE(POSIX_SIGNALS)
107 AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
108 [AC_TRY_RUN([#include <signal.h>
110 $ac_cv_type_signal handler()
114 kill(getpid(), SIGTERM);
119 signal(SIGTERM, handler);
120 kill(getpid(), SIGTERM);
122 }], unet_cv_sys_signal_bsd=yes, unet_cv_sys_signal_bsd=no)])
123 if test $unet_cv_sys_signal_bsd = yes; then
124 AC_DEFINE(BSD_RELIABLE_SIGNALS)
126 AC_DEFINE(SYSV_UNRELIABLE_SIGNALS)
131 dnl Macro: unet_CHECK_TYPE_SIZES
133 dnl Check the size of several types and define a valid int16_t and int32_t.
135 AC_DEFUN(unet_CHECK_TYPE_SIZES,
136 [dnl Check type sizes
137 AC_CHECK_SIZEOF(short)
139 AC_CHECK_SIZEOF(long)
140 AC_CHECK_SIZEOF(void *)
141 if test "$ac_cv_sizeof_int" = 2 ; then
142 AC_CHECK_TYPE(int16_t, int)
143 AC_CHECK_TYPE(u_int16_t, unsigned int)
144 elif test "$ac_cv_sizeof_short" = 2 ; then
145 AC_CHECK_TYPE(int16_t, short)
146 AC_CHECK_TYPE(u_int16_t, unsigned short)
148 AC_MSG_ERROR([Cannot find a type with size of 16 bits])
150 if test "$ac_cv_sizeof_int" = 4 ; then
151 AC_CHECK_TYPE(int32_t, int)
152 AC_CHECK_TYPE(u_int32_t, unsigned int)
153 elif test "$ac_cv_sizeof_short" = 4 ; then
154 AC_CHECK_TYPE(int32_t, short)
155 AC_CHECK_TYPE(u_int32_t, unsigned short)
156 elif test "$ac_cv_sizeof_long" = 4 ; then
157 AC_CHECK_TYPE(int32_t, long)
158 AC_CHECK_TYPE(u_int32_t, unsigned long)
160 AC_MSG_ERROR([Cannot find a type with size of 32 bits])
163 dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
166 dnl This test is for network applications that need socket() and
167 dnl gethostbyname() -ish functions. Under Solaris, those applications need to
168 dnl link with "-lsocket -lnsl". Under IRIX, they should *not* link with
169 dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
170 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
173 dnl Unfortunately, many application developers are not aware of this, and
174 dnl mistakenly write tests that cause -lsocket to be used under IRIX. It is
175 dnl also easy to write tests that cause -lnsl to be used under operating
176 dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
177 dnl uses -lnsl for TLI.
179 dnl This test exists so that every application developer does not test this in
180 dnl a different, and subtly broken fashion.
182 dnl It has been argued that this test should be broken up into two seperate
183 dnl tests, one for the resolver libraries, and one for the libraries necessary
184 dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
185 dnl allowing the autoconf user to use them independantly potentially results in
186 dnl unfortunate ordering dependancies -- as such, such component macros would
187 dnl have to carefully use indirection and be aware if the other components were
188 dnl executed. Since other autoconf macros do not go to this trouble, and almost
189 dnl no applications use sockets without the resolver, this complexity has not
190 dnl been implemented.
192 dnl The check for libresolv is in case you are attempting to link statically
193 dnl and happen to have a libresolv.a lying around (and no libnsl.a).
195 AC_DEFUN(AC_LIBRARY_NET, [
196 # Most operating systems have gethostbyname() in the default searched
197 # libraries (i.e. libc):
198 AC_CHECK_FUNC(gethostbyname, ,
199 # Some OSes (eg. Solaris) place it in libnsl:
200 AC_CHECK_LIB(nsl, gethostbyname, ,
201 # Some strange OSes (SINIX) have it in libsocket:
202 AC_CHECK_LIB(socket, gethostbyname, ,
203 # Unfortunately libsocket sometimes depends on libnsl.
204 # AC_CHECK_LIB's API is essentially broken so the following
205 # ugliness is necessary:
206 AC_CHECK_LIB(socket, gethostbyname,
207 LIBS="-lsocket -lnsl $LIBS",
208 AC_CHECK_LIB(resolv, gethostbyname),
213 AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
214 AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))