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