]> jfr.im git - irc/quakenet/snircd.git/blame - acinclude.m4
Merged revisions 126-137 via svnmerge from
[irc/quakenet/snircd.git] / acinclude.m4
CommitLineData
189935b1 1dnl
2dnl Macro: unet_NONBLOCKING
3dnl
4dnl Check whether we have posix, bsd or sysv non-blocking sockets and
5dnl define respectively NBLOCK_POSIX, NBLOCK_BSD or NBLOCK_SYSV.
6dnl
7AC_DEFUN(unet_NONBLOCKING,
8[dnl Do we have posix, bsd or sysv non-blocking stuff ?
9AC_CACHE_CHECK([for posix non-blocking], unet_cv_sys_nonblocking_posix,
10[AC_TRY_RUN([#include <sys/types.h>
11#include <sys/socket.h>
12#include <fcntl.h>
13#include <sys/ioctl.h>
14#include <sys/file.h>
15#include <signal.h>
16$ac_cv_type_signal alarmed() { exit(1); }
17int main(void)
18{
19 char b[12];
20 struct sockaddr x;
21 size_t l = sizeof(x);
22 int f = socket(AF_INET, SOCK_DGRAM, 0);
23 if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
24 {
25 signal(SIGALRM, alarmed);
26 alarm(2);
27 recvfrom(f, b, 12, 0, &x, &l);
28 alarm(0);
29 exit(0);
30 }
31 exit(1);
32}], unet_cv_sys_nonblocking_posix=yes, unet_cv_sys_nonblocking_posix=no)])
33if test $unet_cv_sys_nonblocking_posix = yes; then
34 AC_DEFINE([NBLOCK_POSIX],,[Define if you have POSIX non-blocking sockets.])
35else
36AC_CACHE_CHECK([for bsd non-blocking], unet_cv_sys_nonblocking_bsd,
37[AC_TRY_RUN([#include <sys/types.h>
38#include <sys/socket.h>
39#include <fcntl.h>
40#include <sys/ioctl.h>
41#include <sys/file.h>
42#include <signal.h>
43$ac_cv_type_signal alarmed() { exit(1); }
44int main(void)
45{
46 char b[12];
47 struct sockaddr x;
48 size_t l = sizeof(x);
49 int f = socket(AF_INET, SOCK_DGRAM, 0);
50 if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY)))
51 {
52 signal(SIGALRM, alarmed);
53 alarm(2);
54 recvfrom(f, b, 12, 0, &x, &l);
55 alarm(0);
56 exit(0);
57 }
58 exit(1);
59}], unet_cv_sys_nonblocking_bsd=yes, unet_cv_sys_nonblocking_bsd=no)])
60if test $unet_cv_sys_nonblocking_bsd = yes; then
61 AC_DEFINE([NBLOCK_BSD],,[Define if you have BSD non-blocking sockets.])
62else
63 AC_DEFINE([NBLOCK_SYSV],,[Define if you have SysV non-blocking sockets.])
64fi
65fi])
66
67dnl
68dnl Macro: unet_SIGNALS
69dnl
70dnl Check if we have posix signals, reliable bsd signals or
71dnl unreliable sysv signals and define respectively POSIX_SIGNALS,
72dnl BSD_RELIABLE_SIGNALS or SYSV_UNRELIABLE_SIGNALS.
73dnl
74AC_DEFUN(unet_SIGNALS,
75[dnl Do we have posix signals, reliable bsd signals or unreliable sysv signals ?
76AC_CACHE_CHECK([for posix signals], unet_cv_sys_signal_posix,
77[AC_TRY_COMPILE([#include <signal.h>],
78[sigaction(SIGTERM, (struct sigaction *)0L, (struct sigaction *)0L)],
79unet_cv_sys_signal_posix=yes, unet_cv_sys_signal_posix=no)])
80if test $unet_cv_sys_signal_posix = yes; then
81 AC_DEFINE([POSIX_SIGNALS],,[Define if you have POSIX signals.])
82else
83AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
84[AC_TRY_RUN([#include <signal.h>
85int calls = 0;
86$ac_cv_type_signal handler()
87{
88 if (calls) return;
89 calls++;
90 kill(getpid(), SIGTERM);
91 sleep(1);
92}
93int main(void)
94{
95 signal(SIGTERM, handler);
96 kill(getpid(), SIGTERM);
97 exit (0);
98}], unet_cv_sys_signal_bsd=yes, unet_cv_sys_signal_bsd=no)])
99if test $unet_cv_sys_signal_bsd = yes; then
100 AC_DEFINE([BSD_RELIABLE_SIGNALS],,[Define if you have (reliable) BSD signals.])
101else
102 AC_DEFINE([SYSV_UNRELIABLE_SIGNALS],,[Define if you have (unreliable) SysV signals.])
103fi
104fi])
105
106dnl
107dnl Macro: unet_CHECK_TYPE_SIZES
108dnl
109dnl Check the size of several types and define a valid int16_t and int32_t.
110dnl
111AC_DEFUN(unet_CHECK_TYPE_SIZES,
112[dnl Check type sizes
113AC_CHECK_SIZEOF(short)
114AC_CHECK_SIZEOF(int)
115AC_CHECK_SIZEOF(long)
116AC_CHECK_SIZEOF(void *)
117AC_CHECK_SIZEOF(int64_t)
118AC_CHECK_SIZEOF(long long)
119if test "$ac_cv_sizeof_int" = 2 ; then
120 AC_CHECK_TYPE(int16_t, int)
121 AC_CHECK_TYPE(uint16_t, unsigned int)
122elif test "$ac_cv_sizeof_short" = 2 ; then
123 AC_CHECK_TYPE(int16_t, short)
124 AC_CHECK_TYPE(uint16_t, unsigned short)
125else
126 AC_MSG_ERROR([Cannot find a type with size of 16 bits])
127fi
128if test "$ac_cv_sizeof_int" = 4 ; then
129 AC_CHECK_TYPE(int32_t, int)
130 AC_CHECK_TYPE(uint32_t, unsigned int)
131elif test "$ac_cv_sizeof_short" = 4 ; then
132 AC_CHECK_TYPE(int32_t, short)
133 AC_CHECK_TYPE(uint32_t, unsigned short)
134elif test "$ac_cv_sizeof_long" = 4 ; then
135 AC_CHECK_TYPE(int32_t, long)
136 AC_CHECK_TYPE(uint32_t, unsigned long)
137else
138 AC_MSG_ERROR([Cannot find a type with size of 32 bits])
139fi
140if test "$ac_cv_sizeof_int64_t" = 8 ; then
141 AC_CHECK_TYPE(int64_t)
142 AC_CHECK_TYPE(uint64_t)
143elif test "$ac_cv_sizeof_long_long" = 8 ; then
144 AC_CHECK_TYPE(int64_t, long long)
145 AC_CHECK_TYPE(uint64_t, unsigned long long)
146else
147 AC_MSG_ERROR([Cannot find a type with size of 64 bits])
148fi])
149
150dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
151dnl Domain.
152dnl
153dnl This test is for network applications that need socket() and
154dnl gethostbyname() -ish functions. Under Solaris, those applications need to
155dnl link with "-lsocket -lnsl". Under IRIX, they should *not* link with
156dnl "-lsocket" because libsocket.a breaks a number of things (for instance:
157dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of
158dnl IRIX).
159dnl
160dnl Unfortunately, many application developers are not aware of this, and
161dnl mistakenly write tests that cause -lsocket to be used under IRIX. It is
162dnl also easy to write tests that cause -lnsl to be used under operating
163dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which
164dnl uses -lnsl for TLI.
165dnl
166dnl This test exists so that every application developer does not test this in
167dnl a different, and subtly broken fashion.
168dnl
169dnl It has been argued that this test should be broken up into two seperate
170dnl tests, one for the resolver libraries, and one for the libraries necessary
171dnl for using Sockets API. Unfortunately, the two are carefully intertwined and
172dnl allowing the autoconf user to use them independantly potentially results in
173dnl unfortunate ordering dependancies -- as such, such component macros would
174dnl have to carefully use indirection and be aware if the other components were
175dnl executed. Since other autoconf macros do not go to this trouble, and almost
176dnl no applications use sockets without the resolver, this complexity has not
177dnl been implemented.
178dnl
179dnl The check for libresolv is in case you are attempting to link statically
180dnl and happen to have a libresolv.a lying around (and no libnsl.a).
181dnl
182AC_DEFUN(AC_LIBRARY_NET, [
183 # Most operating systems have gethostbyname() in the default searched
184 # libraries (i.e. libc):
185 AC_CHECK_FUNC(gethostbyname, ,
186 # Some OSes (eg. Solaris) place it in libnsl:
187 AC_CHECK_LIB(nsl, gethostbyname, ,
188 # Some strange OSes (SINIX) have it in libsocket:
189 AC_CHECK_LIB(socket, gethostbyname, ,
190 # Unfortunately libsocket sometimes depends on libnsl.
191 # AC_CHECK_LIB's API is essentially broken so the following
192 # ugliness is necessary:
193 AC_CHECK_LIB(socket, gethostbyname,
194 LIBS="-lsocket -lnsl $LIBS",
195 AC_CHECK_LIB(resolv, gethostbyname),
196 -lnsl)
197 )
198 )
199 )
200 AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
201 AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))
202 ])