Convert connection byte counters to 64-bit integers.
[ircu2.10.12-pk.git] / acinclude.m4
1 dnl
2 dnl Macro: unet_PIPE_CFLAGS
3 dnl
4 dnl   If the compiler understands -pipe, add it to CFLAGS if not already
5 dnl   there.
6 dnl
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
11   OLDCFLAGS="$CFLAGS"
12   CFLAGS="$CFLAGS -pipe"
13   AC_TRY_COMPILE(,,unet_cv_pipe_flags=yes,)
14   CFLAGS="$OLDCFLAGS"
15 fi
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"
21   fi
22 fi
23 ])
24
25 dnl
26 dnl Macro: unet_NONBLOCKING
27 dnl
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.
30 dnl
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>
36 #include <fcntl.h>
37 #include <sys/ioctl.h>
38 #include <sys/file.h>
39 #include <signal.h>
40 $ac_cv_type_signal alarmed() { exit(1); }
41 int main(void)
42 {
43   char b[12];
44   struct sockaddr x;
45   size_t l = sizeof(x);
46   int f = socket(AF_INET, SOCK_DGRAM, 0);
47   if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
48   {
49     signal(SIGALRM, alarmed);
50     alarm(2);
51     recvfrom(f, b, 12, 0, &x, &l);
52     alarm(0);
53     exit(0);
54   }
55   exit(1);
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.])
59 else
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>
63 #include <fcntl.h>
64 #include <sys/ioctl.h>
65 #include <sys/file.h>
66 #include <signal.h>
67 $ac_cv_type_signal alarmed() { exit(1); }
68 int main(void)
69 {
70   char b[12];
71   struct sockaddr x;
72   size_t l = sizeof(x);
73   int f = socket(AF_INET, SOCK_DGRAM, 0);
74   if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY)))
75   {
76     signal(SIGALRM, alarmed);
77     alarm(2);
78     recvfrom(f, b, 12, 0, &x, &l);
79     alarm(0);
80     exit(0);
81   }
82   exit(1);
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.])
86 else
87   AC_DEFINE([NBLOCK_SYSV],,[Define if you have SysV non-blocking sockets.])
88 fi
89 fi])
90
91 dnl
92 dnl Macro: unet_SIGNALS
93 dnl
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.
97 dnl
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.])
106 else
107 AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
108 [AC_TRY_RUN([#include <signal.h>
109 int calls = 0;
110 $ac_cv_type_signal handler()
111 {
112   if (calls) return;
113   calls++;
114   kill(getpid(), SIGTERM);
115   sleep(1);
116 }
117 int main(void)
118 {
119   signal(SIGTERM, handler);
120   kill(getpid(), SIGTERM);
121   exit (0);
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.])
125 else
126   AC_DEFINE([SYSV_UNRELIABLE_SIGNALS],,[Define if you have (unreliable) SysV signals.])
127 fi
128 fi])
129
130 dnl
131 dnl Macro: unet_CHECK_TYPE_SIZES
132 dnl
133 dnl Check the size of several types and define a valid int16_t and int32_t.
134 dnl
135 AC_DEFUN(unet_CHECK_TYPE_SIZES,
136 [dnl Check type sizes
137 AC_CHECK_SIZEOF(short)
138 AC_CHECK_SIZEOF(int)
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)
149 else
150   AC_MSG_ERROR([Cannot find a type with size of 16 bits])
151 fi
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)
161 else
162   AC_MSG_ERROR([Cannot find a type with size of 32 bits])
163 fi
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)
170 else
171   AC_MSG_ERROR([Cannot find a type with size of 64 bits])
172 fi])
173
174 dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
175 dnl Domain.
176 dnl
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
182 dnl IRIX).
183 dnl 
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.
189 dnl 
190 dnl This test exists so that every application developer does not test this in
191 dnl a different, and subtly broken fashion.
192 dnl 
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.
202 dnl
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).
205 dnl
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),
220              -lnsl)
221        )
222      )
223    )
224   AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
225     AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))
226   ])