-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathacinclude.m4
More file actions
292 lines (284 loc) · 9.23 KB
/
Copy pathacinclude.m4
File metadata and controls
292 lines (284 loc) · 9.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
dnl
dnl Macro: unet_NONBLOCKING
dnl
dnl Check whether we have posix, bsd or sysv non-blocking sockets and
dnl define respectively NBLOCK_POSIX, NBLOCK_BSD or NBLOCK_SYSV.
dnl
AC_DEFUN([unet_NONBLOCKING],
[dnl Do we have posix, bsd or sysv non-blocking stuff ?
AC_CACHE_CHECK([for posix non-blocking], unet_cv_sys_nonblocking_posix,
[AC_RUN_IFELSE([AC_LANG_SOURCE([#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <signal.h>
$ac_cv_type_signal alarmed() { exit(1); }
int main(void)
{
char b[12];
struct sockaddr x;
size_t l = sizeof(x);
int f = socket(AF_INET, SOCK_DGRAM, 0);
if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
{
signal(SIGALRM, alarmed);
alarm(2);
recvfrom(f, b, 12, 0, &x, &l);
alarm(0);
exit(0);
}
exit(1);
}])], [unet_cv_sys_nonblocking_posix=yes], [unet_cv_sys_nonblocking_posix=no])])
if test $unet_cv_sys_nonblocking_posix = yes; then
AC_DEFINE([NBLOCK_POSIX],,[Define if you have POSIX non-blocking sockets.])
else
AC_CACHE_CHECK([for bsd non-blocking], unet_cv_sys_nonblocking_bsd,
[AC_RUN_IFELSE([AC_LANG_SOURCE([#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <signal.h>
$ac_cv_type_signal alarmed() { exit(1); }
int main(void)
{
char b[12];
struct sockaddr x;
size_t l = sizeof(x);
int f = socket(AF_INET, SOCK_DGRAM, 0);
if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY)))
{
signal(SIGALRM, alarmed);
alarm(2);
recvfrom(f, b, 12, 0, &x, &l);
alarm(0);
exit(0);
}
exit(1);
}])], [unet_cv_sys_nonblocking_bsd=yes], [unet_cv_sys_nonblocking_bsd=no])])
if test $unet_cv_sys_nonblocking_bsd = yes; then
AC_DEFINE([NBLOCK_BSD],,[Define if you have BSD non-blocking sockets.])
else
AC_DEFINE([NBLOCK_SYSV],,[Define if you have SysV non-blocking sockets.])
fi
fi])
dnl
dnl Macro: unet_SIGNALS
dnl
dnl Check if we have posix signals, reliable bsd signals or
dnl unreliable sysv signals and define respectively POSIX_SIGNALS,
dnl BSD_RELIABLE_SIGNALS or SYSV_UNRELIABLE_SIGNALS.
dnl
AC_DEFUN([unet_SIGNALS],
[dnl Do we have posix signals, reliable bsd signals or unreliable sysv signals ?
AC_CACHE_CHECK([for posix signals], unet_cv_sys_signal_posix,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([#include <signal.h>
int main(void) {
sigaction(SIGTERM, (struct sigaction *)0L, (struct sigaction *)0L);
return 0;
}])], [unet_cv_sys_signal_posix=yes], [unet_cv_sys_signal_posix=no])])
if test $unet_cv_sys_signal_posix = yes; then
AC_DEFINE([POSIX_SIGNALS],,[Define if you have POSIX signals.])
else
AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
[AC_RUN_IFELSE([AC_LANG_SOURCE([#include <signal.h>
int calls = 0;
$ac_cv_type_signal handler()
{
if (calls) return;
calls++;
kill(getpid(), SIGTERM);
sleep(1);
}
int main(void)
{
signal(SIGTERM, handler);
kill(getpid(), SIGTERM);
exit (0);
}])], [unet_cv_sys_signal_bsd=yes], [unet_cv_sys_signal_bsd=no])])
if test $unet_cv_sys_signal_bsd = yes; then
AC_DEFINE([BSD_RELIABLE_SIGNALS],,[Define if you have (reliable) BSD signals.])
else
AC_DEFINE([SYSV_UNRELIABLE_SIGNALS],,[Define if you have (unreliable) SysV signals.])
fi
fi])
dnl
dnl Macro: unet_CHECK_TYPE_SIZES
dnl
dnl Check the size of several types and define a valid int16_t and int32_t.
dnl
AC_DEFUN([unet_CHECK_TYPE_SIZES],
[dnl Check type sizes
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(int64_t)
AC_CHECK_SIZEOF(long long)
if test "$ac_cv_sizeof_int" = 2 ; then
AC_CHECK_TYPE(int16_t, int)
AC_CHECK_TYPE(uint16_t, unsigned int)
elif test "$ac_cv_sizeof_short" = 2 ; then
AC_CHECK_TYPE(int16_t, short)
AC_CHECK_TYPE(uint16_t, unsigned short)
else
AC_MSG_ERROR([Cannot find a type with size of 16 bits])
fi
if test "$ac_cv_sizeof_int" = 4 ; then
AC_CHECK_TYPE(int32_t, int)
AC_CHECK_TYPE(uint32_t, unsigned int)
elif test "$ac_cv_sizeof_short" = 4 ; then
AC_CHECK_TYPE(int32_t, short)
AC_CHECK_TYPE(uint32_t, unsigned short)
elif test "$ac_cv_sizeof_long" = 4 ; then
AC_CHECK_TYPE(int32_t, long)
AC_CHECK_TYPE(uint32_t, unsigned long)
else
AC_MSG_ERROR([Cannot find a type with size of 32 bits])
fi
if test "$ac_cv_sizeof_int64_t" = 8 ; then
AC_CHECK_TYPE(int64_t)
AC_CHECK_TYPE(uint64_t)
elif test "$ac_cv_sizeof_long_long" = 8 ; then
AC_CHECK_TYPE(int64_t, long long)
AC_CHECK_TYPE(uint64_t, unsigned long long)
else
AC_MSG_ERROR([Cannot find a type with size of 64 bits])
fi])
dnl
dnl Macro: unet_TLS
dnl
dnl Set unet_cv_with_tls and TLS_C to an available TLS implementation.
dnl
AC_DEFUN([unet_TLS],
[dnl Perform some preliminary checks for system TLS libraries.
AX_CHECK_OPENSSL(, [:])
PKG_CHECK_MODULES([GNUTLS], [gnutls], , [:])
dnl --with-tls allows selection of the TLS library.
AC_MSG_CHECKING([for a TLS library])
AC_ARG_WITH([tls],
[ --with-tls=library TLS library to use (none, openssl, gnutls, libtls)],
[unet_cv_with_tls=$with_tls],
[AC_CACHE_VAL(unet_cv_with_tls,
[unet_cv_with_tls=yes])])
TLS_C=""
dnl If --with-tls or --with-tls=yes, try to autodetect: OpenSSL first.
if test x"$unet_cv_with_tls" = xyes ; then
if test x"$OPENSSL_LIBS" != x ; then
unet_cv_with_tls=openssl
fi
fi
dnl Try gnutls next.
if test x"$unet_cv_with_tls" = xyes ; then
if test x"$GNUTLS_LIBS" != x ; then
unet_cv_with_tls=gnutls
fi
fi
dnl Try libtls next.
if test x"$unet_cv_with_tls" = xyes ; then
dnl Temporarily disable pkg-config to force fallback path
dnl PKG_CHECK_MODULES([LIBTLS], [libtls], [
dnl unet_cv_with_tls=libtls
dnl ], [
dnl Fallback for OpenBSD base (no .pc): header + symbol link test.
AC_CHECK_HEADER([tls.h], [
AC_CHECK_LIB([tls], [tls_init], [
unet_cv_with_tls=libtls
LIBTLS_LIBS="-ltls"
LIBTLS_CFLAGS=""
LIBTLS_LDFLAGS=""
])
])
dnl ])
fi
case x"$unet_cv_with_tls" in
xopenssl)
CFLAGS="$CFLAGS $OPENSSL_CFLAGS"
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
LIBS="$LIBS $OPENSSL_LIBS"
TLS_C="tls_openssl.c"
;;
xgnutls)
CFLAGS="$CFLAGS $GNUTLS_CFLAGS"
LDFLAGS="$LDFLAGS $GNUTLS_LDFLAGS"
LIBS="$LIBS $GNUTLS_LIBS"
TLS_C="tls_gnutls.c"
;;
xlibtls)
# Ensure LIBTLS_LIBS is set even when explicitly specified
if test x"$LIBTLS_LIBS" = x ; then
LIBTLS_LIBS="-ltls"
fi
CFLAGS="$CFLAGS $LIBTLS_CFLAGS"
LDFLAGS="$LDFLAGS $LIBTLS_LDFLAGS"
LIBS="$LIBS $LIBTLS_LIBS"
TLS_C="tls_libtls.c"
;;
xyes|xno)
unet_cv_with_tls="none"
TLS_C="tls_none.c"
;;
esac
if test x"$TLS_C" = x ; then
AC_MSG_WARN([Unknown TLS library $unet_cv_with_tls])
TLS_C="tls_none.c"
fi
AC_MSG_RESULT([$unet_cv_with_tls])
AC_SUBST([TLS_C])
if test x"$unet_cv_with_tls" = xopenssl ; then
AC_CHECK_FUNCS([SSL_set_ciphersuites])
fi])
dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
dnl Domain.
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)))
])