Add epoll_* ioset backend.
[srvx.git] / configure.in
1 dnl Process this file with autoconf to create a configure script.
2
3 dnl General initialization.
4 AC_PREREQ(2.59)
5 AC_INIT([srvx],[1.3.1],[srvx-bugs@lists.sourceforge.net])
6 CODENAME=surge
7 AC_CONFIG_HEADERS(src/config.h)
8 AC_CONFIG_SRCDIR(src/opserv.c)
9 dnl AM_CANONICAL_TARGET must be before AM_INIT_AUTOMAKE() or autoconf whines
10 AC_CANONICAL_TARGET
11 AM_INIT_AUTOMAKE([gnu 1.6])
12 AM_MAINTAINER_MODE
13
14 dnl Compiler/runtime feature checks.
15 AC_TYPE_SIGNAL
16 AC_C_CONST
17 AC_C_INLINE
18
19 dnl Checks for programs.
20 AC_PROG_AWK
21 AC_PROG_CC
22 AC_PROG_INSTALL
23 AC_PROG_LIBTOOL
24 AC_PROG_LN_S
25 AC_PROG_MAKE_SET
26 AC_PROG_GCC_TRADITIONAL
27
28 dnl Look for a GNU Arch program
29 AC_CHECK_PROGS(GNU_ARCH, [baz tla])
30 AM_CONDITIONAL(HAS_GNU_ARCH, test z$GNU_ARCH != z)
31
32 dnl nice that unixes can all follow a standard.
33 case $target in
34   *-freebsd2* | *-freebsdelf2* | *-freebsd*out3*)
35     ANSI_SRC=""
36     ;;
37   *-freebsd3* | *-freebsdelf3* | *-freebsd*out3*)
38     ANSI_SRC=""
39     AC_DEFINE(BROKEN_REGEX, 1, [Define if the system regex library is unreliable.])
40         BROKEN_REGEX=yes
41     ;;
42   *-solaris*)
43     EXTRA_DEFINE="-D__SOLARIS__"
44     ANSI_SRC="-fno-builtin"
45     ;;
46   *-cygwin)
47     ANSI_SRC="-fno-builtin"
48     ;;
49   *-linux*)
50     dnl -D_GNU_SOURCE needed for strsignal()
51     EXTRA_DEFINE="-D_GNU_SOURCE"
52     ANSI_SRC=""
53     ;;
54   *)
55     ANSI_SRC=""
56     ;;
57 esac
58 CFLAGS="$CFLAGS $EXTRA_DEFINE"
59
60 dnl Checks for libraries.
61 AC_CHECK_LIB(socket, socket)
62 AC_CHECK_LIB(nsl, gethostbyname)
63
64 dnl Checks for header files.
65 AC_HEADER_STDC
66
67 dnl will be used for portability stuff
68 AC_HEADER_TIME
69 AC_STRUCT_TM
70
71 dnl Would rather not bail on headers, BSD has alot of the functions elsewhere. -Jedi
72 AC_CHECK_HEADERS(fcntl.h malloc.h netdb.h arpa/inet.h netinet/in.h sys/resource.h sys/timeb.h sys/times.h sys/param.h sys/socket.h sys/time.h sys/types.h sys/wait.h unistd.h getopt.h memory.h regex.h arpa/inet.h sys/mman.h sys/stat.h dirent.h sys/epoll.h,,)
73
74 dnl portability stuff, hurray! -Jedi
75 AC_CHECK_MEMBER([struct sockaddr.sa_len],
76                 [AC_DEFINE([HAVE_SOCKADDR_SA_LEN],,[Define if struct sockaddr has sa_len field])],
77                 [],[#include <sys/types.h>
78 #include <sys/socket.h>])
79 AC_CHECK_MEMBER([struct addrinfo.ai_flags],
80                 [AC_DEFINE([HAVE_STRUCT_ADDRINFO],,[Define if struct addrinfo declared])],
81                 [],[#include <sys/types.h>
82 #include <sys/socket.h>
83 #include <netdb.h>])
84 AC_CHECK_FUNCS(gettimeofday)
85 if test $ac_cv_func_gettimeofday = no; then
86   AC_CHECK_FUNCS(ftime,,AC_MSG_ERROR([ftime or gettimeofday required.  srvx build will fail.]))
87 fi
88
89 dnl We have fallbacks in case these are missing, so just check for them.
90 AC_CHECK_FUNCS(freeaddrinfo getaddrinfo getnameinfo getpagesize memcpy memset strdup strerror strsignal localtime_r setrlimit getopt getopt_long regcomp regexec regfree sysconf inet_aton epoll_create select,,)
91
92 dnl Check for absolutely required library functions.
93 AC_CHECK_FUNCS(socket strcspn strspn strtod strtoul,,AC_MSG_ERROR([a required function was not found.  srvx build will fail.]))
94
95 dnl Check for functions (and how to get them).
96 AC_FUNC_ALLOCA
97 AC_FUNC_MMAP
98
99 AC_CACHE_CHECK([for sin_len], ac_cv_sin_len,
100 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
101 #include <netinet/in.h>],[struct sockaddr_in *sin; sin->sin_len = 0;])],
102 ac_cv_sin_len="yes", ac_cv_sin_len="no")])
103 if test $ac_cv_sin_len = yes ; then
104   AC_DEFINE(HAVE_SIN_LEN, 1, [Define if struct sockaddr_in contains a sin_len field])
105 fi
106
107 dnl Check for socklen_t.  In traditional BSD this is an int, but some
108 dnl OSes use a different type.  Test until we find something that will
109 dnl work properly.  Test borrowed from a patch submitted for Python.
110 AC_CHECK_TYPE([socklen_t], ,[
111   AC_MSG_CHECKING([for socklen_t equivalent])
112   AC_CACHE_VAL([curl_cv_socklen_t_equiv],
113   [
114 dnl Systems have either "struct sockaddr*" or "void*" as second
115 dnl arg to getpeername.
116     curl_cv_socklen_t_equiv=
117     for arg2 in "struct sockaddr" void ; do
118       for t in int size_t unsigned long "unsigned long" ; do
119         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
120 #include <sys/socket.h>
121 int getpeername (int $arg2 *, $t *);]], [[$t len;
122   getpeername(0, 0, &len);]])],[curl_cv_socklen_t_equiv="$t"
123   break],[])
124       done
125     done
126   ])
127   AC_MSG_RESULT($curl_cv_socklen_t_equiv)
128   AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
129       [type to use in place of socklen_t if not defined])],
130   [#include <sys/types.h>
131 #include<sys/socket.h>])
132
133 dnl Can only check with -Werror, but the rest of configure doesn't like -Werror
134 OLD_CFLAGS=$CFLAGS
135 CFLAGS="$CFLAGS -W -Wall -Werror"
136
137 dnl Now figure out how to printf() a time_t
138 AC_MSG_CHECKING(for time_t format)
139 AC_CACHE_VAL(ac_cv_fmt_time_t, [
140 ac_cv_fmt_time_t=no
141 AC_COMPILE_IFELSE([#include <sys/types.h>
142 #include <stdio.h>
143 void myfunc(void) {
144   time_t test=0;
145   printf("%li", test);
146 }], ac_cv_fmt_time_t="\"%li\"")
147 if test $ac_cv_fmt_time_t = no; then
148 AC_COMPILE_IFELSE([#include <sys/types.h>
149 #include <stdio.h>
150 void myfunc(void) {
151   time_t test=0;
152   printf("%i", test);
153 }], ac_cv_fmt_time_t="\"%i\"")
154 fi
155 if test $ac_cv_fmt_time_t = no; then
156 AC_MSG_ERROR([Cannot detect format string for time_t
157 Please check sys/types.h for the typedef of time_t and submit to a developer])
158 fi
159 ])
160 AC_DEFINE_UNQUOTED(FMT_TIME_T, $ac_cv_fmt_time_t, [Define to printf format for a time_t variable])
161 AC_MSG_RESULT($ac_cv_fmt_time_t)
162
163 dnl How to copy one va_list to another?
164 AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy, [AC_LINK_IFELSE(
165   [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);])],
166   [ac_cv_c_va_copy="yes"],
167   [ac_cv_c_va_copy="no"]
168 )])
169 if test "$ac_cv_c_va_copy" = "yes" ; then
170   AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
171 fi
172
173 AC_CACHE_CHECK([for __va_copy], ac_cv_c___va_copy, [AC_LINK_IFELSE(
174   [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; __va_copy(ap1, ap2);])],
175   [ac_cv_c___va_copy="yes"],
176   [ac_cv_c___va_copy="no"]
177 )])
178 if test "$ac_cv_c___va_copy" = "yes" ; then
179   AC_DEFINE(HAVE___VA_COPY, 1, [Define if we have __va_copy])
180 fi
181
182 dnl Now fix things back up
183 CFLAGS=$OLD_CFLAGS
184
185 dnl Optional features.
186 AC_MSG_CHECKING(which malloc to use)
187 AC_ARG_WITH(malloc,
188 [  --with-malloc=type      Enables use of a special malloc library; one of:
189                           system (the default), boehm-gc, dmalloc, mpatrol, srvx, slab],
190 [],
191 [withval="system"])
192 if test "x$withval" = "xsystem" ; then
193   AC_MSG_RESULT(system)
194   AC_DEFINE(WITH_MALLOC_SYSTEM, 1, [Define if using the system's malloc])
195 elif test "x$withval" = "xdmalloc" ; then
196   AC_MSG_RESULT(dmalloc)
197   AC_CHECK_HEADERS(dmalloc.h,,AC_MSG_ERROR([dmalloc header file missing.  dmalloc build will fail.]))
198   AC_CHECK_LIB(dmalloc,malloc,,AC_MSG_ERROR([dmalloc library is missing.  dmalloc build will fail.]))
199   AC_DEFINE(WITH_MALLOC_DMALLOC, 1, [Define if using the dmalloc debugging malloc package])
200 elif test "x$withval" = "xmpatrol" ; then
201   AC_MSG_RESULT(mpatrol)
202   AC_CHECK_HEADERS(mpatrol.h,,AC_MSG_ERROR([mpatrol header file missing.  mpatrol build will fail.]))
203   dnl Using mpatrol requires linking against libelf, at least on Linux.
204   AC_CHECK_LIB(elf, elf_begin)
205   AC_CHECK_LIB(mpatrol,__mp_atexit,,AC_MSG_ERROR([mpatrol library is missing completely.  mpatrol build will fail.]))
206   AC_DEFINE(WITH_MALLOC_MPATROL, 1, [Define if using the mpatrol malloc debugging package])
207 elif test "x$withval" = "xboehm-gc" ; then
208   AC_MSG_RESULT(boehm-gc)
209   AC_CHECK_HEADERS(gc/gc.h,,AC_MSG_ERROR([Boehm GC header file missing.  boehm-gc build will fail.]))
210   AC_CHECK_LIB(dl, dlopen, , AC_MSG_ERROR([libdl library is missing.  boehm-gc build will fail.]))
211   AC_CHECK_LIB(gc, GC_gcollect, , AC_MSG_ERROR([Boehm GC library is missing.  boehm-gc build will fail.]))
212   AC_DEFINE(WITH_MALLOC_BOEHM_GC, 1, [Define if using the Boehm GC to garbage collect and check memory leaks])
213 elif test "x$withval" = "xsrvx" ; then
214   AC_MSG_RESULT(srvx)
215   AC_DEFINE(WITH_MALLOC_SRVX, 1, [Define if using the srvx internal debug allocator])
216   MODULE_OBJS="$MODULE_OBJS alloc-srvx.\$(OBJEXT)"
217 elif test "x$withval" = "xslab" ; then
218   AC_MSG_RESULT(slab)
219   AC_DEFINE(WITH_MALLOC_SLAB, 1, [Define if using the slab internal debug allocator])
220   MODULE_OBJS="$MODULE_OBJS alloc-slab.\$(OBJEXT)"
221 else
222   AC_MSG_ERROR([Unknown malloc type $withval])
223 fi
224
225 AC_MSG_CHECKING(which protocol to use)
226 AC_ARG_WITH(protocol,
227 [  --with-protocol=name    Choose IRC dialect to support; one of:
228                           p10 (the default), bahamut],
229 [],
230 [withval="p10"])
231 if test "x$withval" = "xp10" ; then
232   AC_MSG_RESULT(P10)
233   AC_DEFINE(WITH_PROTOCOL_P10, 1, [Define if using the P10 dialect of IRC])
234   MODULE_OBJS="$MODULE_OBJS proto-p10.\$(OBJEXT)"
235   PROTO_FILES=proto-p10.c
236 elif test "x$withval" = "xbahamut" ; then
237   AC_MSG_RESULT(Bahamut)
238   AC_DEFINE(WITH_PROTOCOL_BAHAMUT, 1, [Define if using the Bahamut dialect of IRC])
239   MODULE_OBJS="$MODULE_OBJS proto-bahamut.\$(OBJEXT)"
240 else
241   AC_MSG_ERROR([Unknown IRC dialect $withval])
242 fi
243
244 AC_MSG_CHECKING([I/O multiplexing backends])
245 IOMUXES=""
246
247 if test "x$ac_cv_func_select" = xyes ; then
248   AC_DEFINE(WITH_IOSET_SELECT, 1, [Define if using the select() I/O backend])
249   MODULE_OBJS="$MODULE_OBJS ioset-select.\$(OBJEXT)"
250   IOMUXES="$IOMUXES select"
251 fi
252
253 AC_ARG_WITH([epoll],
254 [  --without-epoll         Disables the epoll_*() I/O backend],
255 [],
256 [withval="$ac_cv_func_epoll_create"])
257 if test "x$withval" = xyes ; then
258   AC_DEFINE(WITH_IOSET_EPOLL, 1, [Define if using the epoll I/O backend])
259   MODULE_OBJS="$MODULE_OBJS ioset-epoll.\$(OBJEXT)"
260   IOMUXES="$IOMUXES epoll"
261 fi
262
263 IOMUXES=`echo $IOMUXES | sed 's/^ +//'`
264 if test "x$IOMUXES" = "x" ; then
265   AC_MSG_ERROR([No supported I/O multiplexing backend found])
266 else
267   AC_MSG_RESULT($IOMUXES)
268 fi
269
270 AC_ARG_WITH(getopt,
271 [  --without-getopt        Disables building of the GNU getopt library],
272 [if test "$withval" = no; then
273   AC_DEFINE(IGNORE_GETOPT, 1, [Define to disable built-in getopt library])
274 fi])
275
276 AC_MSG_CHECKING(whether to enable tokenization)
277 AC_ARG_ENABLE(tokens,
278 [  --disable-tokens        Disables tokenization of P10 protocol output
279                            (tokens required if linking to ircu 2.10.11)],
280 [],[enableval=yes])
281 if test "z$enableval" = zno ; then
282   AC_MSG_RESULT(no)
283 else
284   AC_DEFINE(ENABLE_TOKENS, 1, [Define if tokenized P10 desired])
285   AC_MSG_RESULT(yes)
286 fi
287
288 AC_MSG_CHECKING(whether to enable debug behaviors)
289 AC_ARG_ENABLE(debug,
290 [  --enable-debug          Enables debugging behaviors],
291 [
292   CPPFLAGS="$CPPFLAGS"
293   AC_MSG_RESULT(yes)
294 ],
295 [
296   CPPFLAGS="$CPPFLAGS -DNDEBUG"
297   AC_MSG_RESULT(no)
298 ])
299
300 if test -e src ; then
301   if test ! -d src ; then
302     AC_MSG_ERROR([src exists but is not a directory; please move it out of the way.])
303   fi
304 else
305   mkdir src
306 fi
307 AC_MSG_CHECKING(for extra module files)
308 MODULE_DEFINES="src/modules-list.h"
309 echo > $MODULE_DEFINES
310 touch $MODULE_DEFINES
311 AC_ARG_ENABLE(modules,
312 [  --enable-modules=list,of,modules   Enable extra modules],
313 [
314   OIFS="$IFS"
315   IFS=','
316   EXTRA_MODULE_OBJS=""
317   module_list=""
318   dnl Must use a separate file because autoconf can't stand newlines in an AC_SUBSTed variable.
319   for module in $enableval ; do
320     module=`echo $module | sed -e s/^mod-// -e s/\.c\$//`
321     EXTRA_MODULE_OBJS="$EXTRA_MODULE_OBJS mod-$module.\$(OBJEXT)"
322     module_list="$module_list $module"
323     echo "WITH_MODULE($module)" >> $MODULE_DEFINES
324   done
325   IFS="$OIFS"
326   MODULE_OBJS="$MODULE_OBJS $EXTRA_MODULE_OBJS"
327   AC_MSG_RESULT($module_list)
328 ],
329 [
330   AC_MSG_RESULT(none)
331 ])
332
333 MY_SUBDIRS=""
334 RX_INCLUDES=""
335 RX_LIBS=""
336 if test "${BROKEN_REGEX}" = yes -o "${ac_cv_func_regcomp}" = no; then
337   MY_SUBDIRS="rx $MY_SUBDIRS"
338   RX_INCLUDES="-I../rx"
339   RX_LIBS="../rx/librx.a"
340 fi
341 MY_SUBDIRS="$MY_SUBDIRS src"
342 CFLAGS="$CFLAGS $ANSI_SRC -W -Wall"
343 if test "z$USE_MAINTAINER_MODE" = zyes ; then
344   CFLAGS="$CFLAGS -Werror"
345 fi
346
347 AC_DEFINE_UNQUOTED(CODENAME, "${CODENAME}", [Code name for this release])
348 AC_SUBST(MODULE_OBJS)
349 AC_SUBST(MY_SUBDIRS)
350 AC_SUBST(RX_INCLUDES)
351 AC_SUBST(RX_LIBS)
352 AC_CONFIG_FILES(Makefile rx/Makefile src/Makefile)
353 AC_OUTPUT