-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure.in
461 lines (410 loc) · 13.5 KB
/
configure.in
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
dnl configure.in for libd
dnl awiebe, april 2009
AC_INIT
AC_CONFIG_HEADER(include/setup.h)
AC_DEFINE(PACKAGE_NAME, "libd")
AC_DEFINE(PACKAGE_BUGREPORT, "[email protected]")
AC_DEFINE(PACKAGE_STRING, "Daemon library")
AC_DEFINE(PACKAGE_VERSION, "0.1")
# autoheader templates
AH_TEMPLATE([BROKEN_FD_SETSIZE],[If on a system with a broken FD_SETSIZE])
AH_TEMPLATE([HAVE_ENCRYPTION_ON],[If we support encryption])
AH_TEMPLATE([HAVE_COMPRESSION_ON],[If we support compression])
AH_TEMPLATE([SYS_ERRLIST_DECLARED],[If the sys_errlist array is defined])
AH_TEMPLATE([MAXCONNECTIONS],[Maximum Connections we allow])
AH_TEMPLATE([WRITEV_IOV],[Maxmimum number of iovecs supported by writev()])
AH_TEMPLATE([USE_SSL],[Defined if we want to compile in SSL support])
dnl Put our options of here for ease of reading.
AC_ARG_ENABLE(openssl,
[ --enable-openssl[=DIR] Enable OpenSSL support (DIR optional).
--disable-openssl Disable OpenSSL support. ],
[ cf_enable_openssl=$enableval ],
[ cf_enable_openssl="auto" ])
AC_ARG_WITH(socketengine,
[ --with-socketengine=TYPE Set the socketengine type. Choices are:
kqueue epoll devpoll poll select ],
[ check_sengine=$withval ],
[ check_sengine="yes" ])
AC_ARG_WITH(maxconnections,
[ --with-maxconnections=NUMBER Set the maximum number of sockets.],
[ check_maxconnections=$withval ],
[ check_maxconnections="auto" ])
DEBUG=yes
dnl
dnl load custom checks
builtin(include, ./m4/ax_gcc_x86_cpuid.m4)
builtin(include, ./m4/ax_gcc_archflag.m4)
builtin(include, ./m4/ax_compiler_vendor.m4)
builtin(include, ./m4/ax_check_compiler_flags.m4)
builtin(include, ./m4/ax_cflags_warn_all_ansi.m4)
builtin(include, ./m4/ax_cflags_strict_prototypes.m4)
builtin(include, ./m4/ax_cc_maxopt.m4)
dnl end custom checks load
dnl
dnl Checks!
AC_PROG_CC_C99
AX_CC_MAXOPT
AX_CFLAGS_STRICT_PROTOTYPES
AC_CANONICAL_SYSTEM
AX_CFLAGS_WARN_ALL_ANSI
AC_ISC_POSIX
AC_PROG_MAKE_SET
AC_PATH_PROG(RM, rm)
AC_PATH_PROG(CP, cp)
AC_PATH_PROG(MV, mv)
AC_PATH_PROG(SED, sed)
AC_PROG_INSTALL
dnl Replace `main' with a function in -lnsl:
AC_CHECK_LIB(socket, socket, zlib)
AC_CHECK_FUNC(crypt,, AC_CHECK_LIB(descrypt, crypt,,AC_CHECK_LIB(crypt, crypt,,)))
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h netinet/in.h stdlib.h string.h sys/socket.h sys/time.h unistd.h])
AC_C_CONST
AC_HEADER_TIME
AC_FUNC_ERROR_AT_LINE
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC
AC_FUNC_SELECT_ARGTYPES
AC_CHECK_FUNCS([memset socket strerror])
AC_PROG_GCC_TRADITIONAL
dnl check for various OSes
case "$target" in
*-solaris2*)
solaris2="yes"
AC_DEFINE_UNQUOTED(WRITEV_IOV, 16)
;;
*-freebsd*)
freebsd="yes"
AC_DEFINE_UNQUOTED(WRITEV_IOV, 32)
;;
*-netbsd*)
AC_DEFINE_UNQUOTED(WRITEV_IOV, 32)
;;
*-openbsd*)
AC_DEFINE_UNQUOTED(WRITEV_IOV, 32)
;;
*-linux*)
linux="yes"
AC_DEFINE_UNQUOTED(WRITEV_IOV, 32)
;;
*-darwin*)
AC_DEFINE_UNQUOTED(WRITEV_IOV, 32)
;;
esac
dnl Checks for loadable hook module support
dnl Check for sys_errlist
dnl Stolen from BitchX
AC_MSG_CHECKING(for sys_errlist declaration)
AC_TRY_RUN([
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
main()
{
char *s = sys_errlist[0];
exit(0);
}
],
AC_MSG_RESULT(yes)
AC_DEFINE(SYS_ERRLIST_DECLARED),
AC_MSG_RESULT(no), AC_MSG_RESULT(cross compiling))
dnl Openssl checks - combination of our old way and the hybrid7 method
save_LIBS="$LIBS"
AC_MSG_CHECKING(for OpenSSL)
if test "X$cf_enable_openssl" != "Xno" ; then
cf_openssl_basedir=""
if test "X$cf_enable_openssl" != "Xauto" &&
test "X$cf_enable_openssl" != "Xyes"; then
dnl Support for --enable-openssl=/some/place
cf_openssl_basedir="${cf_enable_openssl}"
else
dnl Do the auto-probe here. Check some common directory paths.
for dirs in /usr/local/ssl /usr/pkg /usr/local /usr/lib /usr/lib/ssl\
/opt /opt/openssl /usr/local/openssl ; do
if test -f "${dirs}/include/openssl/opensslv.h" ; then
cf_openssl_basedir="${dirs}"
break
fi
done
unset dirs
fi
dnl Now check cf_openssl_found to see if we found anything.
if test "X$cf_openssl_basedir" != "X" ; then
if test -f "${cf_openssl_basedir}/include/openssl/opensslv.h" ; then
SSL_INCLUDES="-I${cf_openssl_basedir}/include"
SSL_LIBS="-L${cf_openssl_basedir}/lib"
else
dnl OpenSSL wasn't found in the directory specified. Naughty
dnl administrator...
cf_openssl_basedir=""
fi
else
dnl Check for stock FreeBSD 4.x and 5.x systems, since their files
dnl are in /usr/include and /usr/lib. In this case, we don't want to
dnl change INCLUDES or LIBS, but still want to enable OpenSSL.
dnl We can't do this check above, because some people want two versions
dnl of OpenSSL installed (stock FreeBSD 4.x/5.x and /usr/local/ssl)
dnl and they want /usr/local/ssl to have preference.
if test -f "/usr/include/openssl/opensslv.h" ; then
cf_openssl_basedir="/usr"
fi
fi
dnl If we have a basedir defined, then everything is okay. Otherwise,
dnl we have a problem.
if test "X$cf_openssl_basedir" != "X" ; then
LIBS="$save_LIBS $SSL_LIBS -lssl"
AC_MSG_RESULT($cf_openssl_basedir)
cf_enable_openssl="yes"
encryption="enabled"
AC_DEFINE(USE_SSL)
else
AC_MSG_RESULT(not found. Please check your path.)
cf_enable_openssl="no"
encryption="disabled"
fi
unset cf_openssl_basedir
else
dnl If --disable-openssl was specified
encryption="disabled"
AC_MSG_RESULT(disabled)
fi
unset save_LIBS
dnl end of openssl library test
dnl once we add epoll and /dev/poll support, these will be
dnl updated with the appropriate checks
if test "$check_sengine" = "yes"; then
engine="select"
if test "$freebsd" = "yes"; then
AC_CHECK_FUNC(kevent, [ engine="kqueue" ], )
elif test "$solaris2" = "yes"; then
engine="poll"
AC_CHECK_HEADER(sys/devpoll.h, engine="devpoll", )
elif test "$linux" = "yes"; then
AC_CHECK_FUNC(poll, [ engine="poll" ], )
AC_CHECK_HEADER(sys/epoll.h, HAVE_EPOLL_H=yes, HAVE_EPOLL_H=no)
AC_CHECK_LIB(epoll, epoll_create,
[LIBS="$LIBS -lepoll"; have_epoll_lib="yes"; engine="epoll"],
have_epoll_lib="no")
if test "$HAVE_EPOLL_H $have_epoll_lib" = "yes no"; then
AC_MSG_CHECKING(for epoll_create [without -lepoll])
AC_TRY_RUN([
#include <stdint.h>
#include <sys/epoll.h>
#include <errno.h>
#include <asm/unistd.h>
int main(int argc, char **argv) { return epoll_create(5) < 1; }
],
have_epoll_lib="yes", have_epoll_lib="no")
AC_MSG_RESULT($have_epoll_lib)
fi
if test "$HAVE_EPOLL_H $have_epoll_lib" = "yes yes"; then
engine="epoll";
fi
else
AC_CHECK_FUNC(poll, [ engine="poll"], )
fi
elif test "$check_sengine" = "kqueue"; then
AC_CHECK_FUNC(kevent, [ engine="kqueue" ], )
if test "X$engine" = "X"; then
AC_MSG_NOTICE()
AC_MSG_NOTICE(kqueue not supported on this platform!)
AC_MSG_ERROR()
fi
AC_MSG_NOTICE(setting socketengine type to kqueue)
elif test "$check_sengine" = "poll"; then
AC_CHECK_FUNC(poll, [ engine="poll" ], )
if test "X$engine" = "X"; then
AC_MSG_NOTICE()
AC_MSG_NOTICE(poll not supported on this platform!)
AC_MSG_ERROR()
fi
AC_MSG_NOTICE(setting socketengine type to poll)
elif test "$check_sengine" = "devpoll"; then
AC_CHECK_HEADER(sys/devpoll.h, engine="devpoll", )
if test "X$engine" = "X"; then
AC_MSG_NOTICE()
AC_MSG_NOTICE(/dev/poll not supported on this system)
AC_MSG_ERROR()
fi
AC_MSG_NOTICE(setting socketengine to devpoll)
elif test "$check_sengine" = "epoll"; then
AC_CHECK_HEADER(sys/epoll.h, HAVE_EPOLL_H=yes, HAVE_EPOLL_H=no)
AC_CHECK_LIB(epoll, epoll_create,
[LIBS="$LIBS -lepoll"; have_epoll_lib="yes"; engine="epoll"],
have_epoll_lib="no")
if test "$HAVE_EPOLL_H $have_epoll_lib" = "yes no"; then
AC_MSG_CHECKING(for epoll_create [without -lepoll])
AC_TRY_RUN([
#include <stdint.h>
#include <sys/epoll.h>
#include <errno.h>
#include <asm/unistd.h>
int main(int argc, char **argv) { return epoll_create(5) < 1; }
],
have_epoll_lib="yes", have_epoll_lib="no")
AC_MSG_RESULT($have_epoll_lib)
fi
if test "$HAVE_EPOLL_H $have_epoll_lib" != "yes yes"; then
AC_MSG_NOTICE()
AC_MSG_ERROR(epoll is not supported on this machine)
AC_MSG_ERROR()
fi
AC_MSG_NOTICE(setting socketengine type to epoll)
engine="epoll";
elif test "$check_sengine" = "select"; then
AC_MSG_NOTICE(setting socketengine type to select.. for some stupid reason)
engine="select"
else
AC_MSG_NOTICE()
AC_MSG_NOTICE(socket engine type incorrect!)
AC_MSG_ERROR()
fi
SENGINE="socketengine_$engine.c"
dnl Check to see if we have a broken FD_SETSIZE
if test $engine = "select"; then
AC_MSG_CHECKING(to see if FD_SETSIZE is broken)
AC_TRY_RUN([
#define FD_SETSIZE 666
#include <sys/types.h>
#include <sys/time.h>
int main()
{
if(FD_SETSIZE != 666)
exit(1);
exit(0);
}
],
AC_MSG_RESULT(no),
[
AC_MSG_RESULT(YES)
AC_MSG_WARN(FD_SETSIZE is hard set by your operating system)
AC_MSG_WARN(MAXCONNECTIONS must be no higher than the hardwired FD_SETSIZE)
AC_DEFINE(BROKEN_FD_SETSIZE)
broken_fd_setsize="yes"
],
AC_MSG_RESULT(can't tell))
fi
if test "$check_maxconnections" = "auto"; then
AC_MSG_CHECKING(Maximum file descriptors);
AC_CACHE_VAL(maxconnections,
[
AC_LANG_CONFTEST(
[AC_LANG_SOURCE([[
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <stdio.h>
#ifdef RLIMIT_FDMAX
#define RLIMIT_FD_MAX RLIMIT_FDMAX
#else
#ifdef RLIMIT_NOFILE
#define RLIMIT_FD_MAX RLIMIT_NOFILE
#else
#ifdef RLIMIT_OPEN_MAX
#define RLIMIT_FD_MAX RLIMIT_OPEN_MAX
#else
#undef RLIMIT_FD_MAX
#endif
#endif
#endif
int main()
{
#ifndef BROKEN_FD_SETSIZE
#ifdef RLIMIT_FD_MAX
struct rlimit limit;
if(!getrlimit(RLIMIT_FD_MAX, &limit))
{
if(limit.rlim_max > 32768)
printf("32768");
else
printf("%ld", (long) limit.rlim_max);
}
else
#endif
printf("256");
#else
printf("%d", FD_SETSIZE);
#endif
return 0;
}
]])
])
$CC -o conftest conftest.c >/dev/null 2>&1
maxconnections=`./conftest`
AC_MSG_RESULT($maxconnections)
$RM -f conftest conftest.c
])
AC_DEFINE_UNQUOTED(MAXCONNECTIONS, ${maxconnections})
else
maxconnections=$check_maxconnections
AC_DEFINE_UNQUOTED(MAXCONNECTIONS, ${maxconnections})
fi
# zlib test
# ripped from http://autoconf-archive.cryp.to/check_zlib.html
#
ZLIB_HOME=/usr/local
if test ! -f "${ZLIB_HOME}/include/zlib.h"
then
ZLIB_HOME=/usr
fi
if test -n "${ZLIB_HOME}"
then
ZLIB_OLD_LDFLAGS=$LDFLAGS
ZLIB_OLD_CPPFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -L${ZLIB_HOME}/lib"
CPPFLAGS="$CPPFLAGS -I${ZLIB_HOME}/include"
AC_LANG_SAVE
AC_LANG_C
AC_CHECK_LIB(z, inflateEnd, [zlib_cv_libz=yes], [zlib_cv_libz=no])
AC_CHECK_HEADER(zlib.h, [zlib_cv_zlib_h=yes], [zlib_cv_zlib_h=no])
AC_LANG_RESTORE
if test "$zlib_cv_libz" = "yes" -a "$zlib_cv_zlib_h" = "yes"
then
#
# If both library and header were found, use them
#
AC_CHECK_LIB(z, inflateEnd)
AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
AC_MSG_RESULT(ok)
else
#
# If either header or library was not found, revert and bomb
#
AC_MSG_CHECKING(zlib in ${ZLIB_HOME})
LDFLAGS="$ZLIB_OLD_LDFLAGS"
CPPFLAGS="$ZLIB_OLD_CPPFLAGS"
AC_MSG_RESULT(failed)
AC_MSG_ERROR(either specify a valid zlib installation with --with-zlib=DIR or disable zlib usage with --without-zlib)
fi
fi
if test "$engine" = "select" && test "$broken_fd_setsize" != "yes"; then
CFLAGS="$CFLAGS -DUSE_SELECT -DFD_SETSIZE=$maxconnections"
elif test "$engine" = "select"; then
CFLAGS="$CFLAGS -DUSE_SELECT"
elif test "$engine" = "poll"; then
CFLAGS="$CFLAGS -DUSE_POLL"
elif test "$engine" = "epoll"; then
CFLAGS="$CFLAGS -DUSE_EPOLL"
elif test "$engine" = "kqueue"; then
CFLAGS="$CFLAGS -DUSE_KQUEUE"
elif test "$engine" = "devpoll"; then
CFLAGS="$CFLAGS -DUSE_DEVPOLL"
fi
INSTALL_DIR="${prefix}"
AC_SUBST(SSL_INCLUDES)
AC_SUBST(SSL_LIBS)
AC_SUBST(LIBS)
AC_SUBST(SENGINE)
AC_SUBST(INSTALL_DIR)
AC_OUTPUT(src/Makefile)
echo ""
echo " *********** libd configuration **********"
echo " System Build Type: $target"
echo " Socket Engine Type: $engine"
echo " Encryption: $encryption"
echo " Maximum Connections: $maxconnections"
echo " Install Directory: $prefix"
echo " CFLAGS: $CFLAGS"
echo " CPPFLAGS: $CPPFLAGS"
echo " LDFLAGS: $LDFLAGS"
echo ""