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],,[Define if you have POSIX non-blocking sockets.])
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
85 AC_DEFINE([NBLOCK_BSD],,[Define if you have BSD non-blocking sockets.])
87 AC_DEFINE([NBLOCK_SYSV],,[Define if you have SysV non-blocking sockets.])
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],,[Define if you have 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],,[Define if you have (reliable) BSD signals.])
126 AC_DEFINE([SYSV_UNRELIABLE_SIGNALS],,[Define if you have (unreliable) SysV 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 AC_CHECK_SIZEOF(int64_t)
142 AC_CHECK_SIZEOF(long long)
143 if test "$ac_cv_sizeof_int" = 2 ; then
144 AC_CHECK_TYPE(int16_t, int)
145 AC_CHECK_TYPE(uint16_t, unsigned int)
146 elif test "$ac_cv_sizeof_short" = 2 ; then
147 AC_CHECK_TYPE(int16_t, short)
148 AC_CHECK_TYPE(uint16_t, unsigned short)
150 AC_MSG_ERROR([Cannot find a type with size of 16 bits])
152 if test "$ac_cv_sizeof_int" = 4 ; then
153 AC_CHECK_TYPE(int32_t, int)
154 AC_CHECK_TYPE(uint32_t, unsigned int)
155 elif test "$ac_cv_sizeof_short" = 4 ; then
156 AC_CHECK_TYPE(int32_t, short)
157 AC_CHECK_TYPE(uint32_t, unsigned short)
158 elif test "$ac_cv_sizeof_long" = 4 ; then
159 AC_CHECK_TYPE(int32_t, long)
160 AC_CHECK_TYPE(uint32_t, unsigned long)
162 AC_MSG_ERROR([Cannot find a type with size of 32 bits])
164 if test "$ac_cv_sizeof_int64_t" = 8 ; then
165 AC_CHECK_TYPE(int64_t)
166 AC_CHECK_TYPE(uint64_t)
167 elif test "$ac_cv_sizeof_long_long" = 8 ; then
168 AC_CHECK_TYPE(int64_t, long long)
169 AC_CHECK_TYPE(uint64_t, unsigned long long)
171 AC_MSG_ERROR([Cannot find a type with size of 64 bits])
174 dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
177 dnl This test is for network applications that need socket() and
178 dnl gethostbyname() -ish functions. Under Solaris, those applications need to
179 dnl link with "-lsocket -lnsl". Under IRIX, they should *not* link with
180 dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
181 dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
184 dnl Unfortunately, many application developers are not aware of this, and
185 dnl mistakenly write tests that cause -lsocket to be used under IRIX. It is
186 dnl also easy to write tests that cause -lnsl to be used under operating
187 dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
188 dnl uses -lnsl for TLI.
190 dnl This test exists so that every application developer does not test this in
191 dnl a different, and subtly broken fashion.
193 dnl It has been argued that this test should be broken up into two seperate
194 dnl tests, one for the resolver libraries, and one for the libraries necessary
195 dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
196 dnl allowing the autoconf user to use them independantly potentially results in
197 dnl unfortunate ordering dependancies -- as such, such component macros would
198 dnl have to carefully use indirection and be aware if the other components were
199 dnl executed. Since other autoconf macros do not go to this trouble, and almost
200 dnl no applications use sockets without the resolver, this complexity has not
201 dnl been implemented.
203 dnl The check for libresolv is in case you are attempting to link statically
204 dnl and happen to have a libresolv.a lying around (and no libnsl.a).
206 AC_DEFUN(AC_LIBRARY_NET, [
207 # Most operating systems have gethostbyname() in the default searched
208 # libraries (i.e. libc):
209 AC_CHECK_FUNC(gethostbyname, ,
210 # Some OSes (eg. Solaris) place it in libnsl:
211 AC_CHECK_LIB(nsl, gethostbyname, ,
212 # Some strange OSes (SINIX) have it in libsocket:
213 AC_CHECK_LIB(socket, gethostbyname, ,
214 # Unfortunately libsocket sometimes depends on libnsl.
215 # AC_CHECK_LIB's API is essentially broken so the following
216 # ugliness is necessary:
217 AC_CHECK_LIB(socket, gethostbyname,
218 LIBS="-lsocket -lnsl $LIBS",
219 AC_CHECK_LIB(resolv, gethostbyname),
224 AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
225 AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))