Update version tag for 1.4.0-rc2.
[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.4.0-rc2],[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 dnl "const" *should* be in the -Werror section, but that breaks Linux. gg gcc.
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 git client
29 AC_CHECK_PROGS(GIT, [git])
30 AM_CONDITIONAL(HAS_GIT, test z$GIT != 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 sys/event.h stdint.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
85 dnl We have fallbacks in case these are missing, so just check for them.
86 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,,)
87
88 dnl Check for the fallbacks for functions missing above.
89 if test $ac_cv_func_gettimeofday = no; then
90   AC_CHECK_FUNCS(ftime,,AC_MSG_ERROR([ftime or gettimeofday required.  srvx build will fail.]))
91 fi
92
93 dnl Check for absolutely required library functions.
94 AC_CHECK_FUNCS(socket strcspn strspn strtod strtoul,,AC_MSG_ERROR([a required function was not found.  srvx build will fail.]))
95
96 dnl Check for functions (and how to get them).
97 AC_FUNC_ALLOCA
98 AC_FUNC_MMAP
99
100 AC_CACHE_CHECK([for sin_len], ac_cv_sin_len,
101 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <sys/types.h>
102 #include <netinet/in.h>],[struct sockaddr_in *sin; sin->sin_len = 0;])],
103 ac_cv_sin_len="yes", ac_cv_sin_len="no")])
104 if test $ac_cv_sin_len = yes ; then
105   AC_DEFINE(HAVE_SIN_LEN, 1, [Define if struct sockaddr_in contains a sin_len field])
106 fi
107
108 dnl Check for socklen_t.  In traditional BSD this is an int, but some
109 dnl OSes use a different type.  Test until we find something that will
110 dnl work properly.  Test borrowed from a patch submitted for Python.
111 AC_CHECK_TYPE([socklen_t], ,[
112   AC_MSG_CHECKING([for socklen_t equivalent])
113   AC_CACHE_VAL([curl_cv_socklen_t_equiv],
114   [
115 dnl Systems have either "struct sockaddr*" or "void*" as second
116 dnl arg to getpeername.
117     curl_cv_socklen_t_equiv=
118     for arg2 in "struct sockaddr" void ; do
119       for t in int size_t unsigned long "unsigned long" ; do
120         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/types.h>
121 #include <sys/socket.h>
122 int getpeername (int $arg2 *, $t *);]], [[$t len;
123   getpeername(0, 0, &len);]])],[curl_cv_socklen_t_equiv="$t"
124   break],[])
125       done
126     done
127   ])
128   AC_MSG_RESULT($curl_cv_socklen_t_equiv)
129   AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
130       [type to use in place of socklen_t if not defined])],
131   [#include <sys/types.h>
132 #include<sys/socket.h>])
133
134 dnl Can only check with -Werror, but the rest of configure doesn't like -Werror
135 OLD_CFLAGS=$CFLAGS
136 CFLAGS="$CFLAGS -W -Wall -Werror"
137 if test "z$USE_MAINTAINER_MODE" = zyes ; then
138   CFLAGS="$CFLAGS -ansi"
139 fi
140
141 dnl Check for post-C89 keywords
142 AC_C_INLINE
143
144 dnl How to copy one va_list to another?
145 AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy, [AC_LINK_IFELSE(
146   [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);])],
147   [ac_cv_c_va_copy="yes"],
148   [ac_cv_c_va_copy="no"]
149 )])
150 if test "$ac_cv_c_va_copy" = "yes" ; then
151   AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
152 fi
153
154 AC_CACHE_CHECK([for __va_copy], ac_cv_c___va_copy, [AC_LINK_IFELSE(
155   [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; __va_copy(ap1, ap2);])],
156   [ac_cv_c___va_copy="yes"],
157   [ac_cv_c___va_copy="no"]
158 )])
159 if test "$ac_cv_c___va_copy" = "yes" ; then
160   AC_DEFINE(HAVE___VA_COPY, 1, [Define if we have __va_copy])
161 fi
162
163 dnl Now fix things back up
164 CFLAGS=$OLD_CFLAGS
165
166 dnl Optional features.
167 AC_MSG_CHECKING(which malloc to use)
168 AC_ARG_WITH(malloc,
169 [  --with-malloc=type      Enables use of a special malloc library; one of:
170                           system (the default), boehm-gc, dmalloc, mpatrol, srvx, slab],
171 [],
172 [withval="system"])
173 if test "x$withval" = "xsystem" ; then
174   AC_MSG_RESULT(system)
175   AC_DEFINE(WITH_MALLOC_SYSTEM, 1, [Define if using the system's malloc])
176 elif test "x$withval" = "xdmalloc" ; then
177   AC_MSG_RESULT(dmalloc)
178   AC_CHECK_HEADERS(dmalloc.h,,AC_MSG_ERROR([dmalloc header file missing.  dmalloc build will fail.]))
179   AC_CHECK_LIB(dmalloc,malloc,,AC_MSG_ERROR([dmalloc library is missing.  dmalloc build will fail.]))
180   AC_DEFINE(WITH_MALLOC_DMALLOC, 1, [Define if using the dmalloc debugging malloc package])
181 elif test "x$withval" = "xmpatrol" ; then
182   AC_MSG_RESULT(mpatrol)
183   AC_CHECK_HEADERS(mpatrol.h,,AC_MSG_ERROR([mpatrol header file missing.  mpatrol build will fail.]))
184   dnl Using mpatrol requires linking against libelf, at least on Linux.
185   AC_CHECK_LIB(elf, elf_begin)
186   AC_CHECK_LIB(mpatrol,__mp_atexit,,AC_MSG_ERROR([mpatrol library is missing completely.  mpatrol build will fail.]))
187   AC_DEFINE(WITH_MALLOC_MPATROL, 1, [Define if using the mpatrol malloc debugging package])
188 elif test "x$withval" = "xboehm-gc" ; then
189   AC_MSG_RESULT(boehm-gc)
190   AC_CHECK_HEADERS(gc/gc.h,,AC_MSG_ERROR([Boehm GC header file missing.  boehm-gc build will fail.]))
191   AC_CHECK_LIB(dl, dlopen, , AC_MSG_ERROR([libdl library is missing.  boehm-gc build will fail.]))
192   AC_CHECK_LIB(gc, GC_gcollect, , AC_MSG_ERROR([Boehm GC library is missing.  boehm-gc build will fail.]))
193   AC_DEFINE(WITH_MALLOC_BOEHM_GC, 1, [Define if using the Boehm GC to garbage collect and check memory leaks])
194 elif test "x$withval" = "xsrvx" ; then
195   AC_MSG_RESULT(srvx)
196   AC_DEFINE(WITH_MALLOC_SRVX, 1, [Define if using the srvx internal debug allocator])
197   MODULE_OBJS="$MODULE_OBJS alloc-srvx.\$(OBJEXT)"
198 elif test "x$withval" = "xslab" ; then
199   AC_MSG_RESULT(slab)
200   AC_DEFINE(WITH_MALLOC_SLAB, 1, [Define if using the slab internal debug allocator])
201   MODULE_OBJS="$MODULE_OBJS alloc-slab.\$(OBJEXT)"
202 else
203   AC_MSG_ERROR([Unknown malloc type $withval])
204 fi
205
206 AC_MSG_CHECKING(which protocol to use)
207 AC_ARG_WITH(protocol,
208 [  --with-protocol=name    Choose IRC dialect to support; one of:
209                           p10 (the default), bahamut],
210 [],
211 [withval="p10"])
212 if test "x$withval" = "xp10" ; then
213   AC_MSG_RESULT([P10])
214   AC_DEFINE(WITH_PROTOCOL_P10, 1, [Define if using the P10 dialect of IRC])
215   MODULE_OBJS="$MODULE_OBJS proto-p10.\$(OBJEXT)"
216 elif test "x$withval" = "xbahamut" ; then
217   AC_MSG_RESULT([Bahamut])
218   AC_DEFINE(WITH_PROTOCOL_BAHAMUT, 1, [Define if using the Bahamut dialect of IRC])
219   MODULE_OBJS="$MODULE_OBJS proto-bahamut.\$(OBJEXT)"
220 elif test -r "${srcdir}/src/proto-${withval}.c" ; then
221   AC_MSG_RESULT([$withval])
222   MODULE_OBJS="$MODULE_OBJS proto-${withval}.\$(OBJEXT)"
223 else
224   AC_MSG_ERROR([Unknown IRC dialect $withval])
225 fi
226
227 AC_MSG_CHECKING(how to send mail)
228 AC_ARG_WITH(mail,
229 [  --with-mail=name        How to send mail; one of:
230                           sendmail (the default)],
231 [],
232 [withval="sendmail"])
233 if test -r "${srcdir}/src/mail-${withval}.c" ; then
234   AC_MSG_RESULT([$withval])
235   MODULE_OBJS="$MODULE_OBJS mail-${withval}.\$(OBJEXT)"
236 else
237   AC_MSG_ERROR([Unknown mail method $withval])
238 fi
239
240 AC_MSG_CHECKING([I/O multiplexing backends])
241 IOMUXES=""
242
243 if test "x$ac_cv_func_select" = xyes ; then
244   AC_DEFINE(WITH_IOSET_SELECT, 1, [Define if using the select() I/O backend])
245   MODULE_OBJS="$MODULE_OBJS ioset-select.\$(OBJEXT)"
246   IOMUXES="$IOMUXES select"
247 fi
248
249 AC_ARG_WITH([epoll],
250 [  --without-epoll         Disables the epoll_*() I/O backend],
251 [],
252 [withval="$ac_cv_func_epoll_create"])
253 if test "x$withval" = xyes ; then
254   AC_DEFINE(WITH_IOSET_EPOLL, 1, [Define if using the epoll I/O backend])
255   MODULE_OBJS="$MODULE_OBJS ioset-epoll.\$(OBJEXT)"
256   IOMUXES="$IOMUXES epoll"
257 fi
258
259 AC_ARG_WITH([kevent],
260 [  --without-kevent         Disables the kevent() I/O backend],
261 [],
262 [withval="$ac_cv_func_kevent"])
263 if test "x$withval" = xyes ; then
264   AC_DEFINE(WITH_IOSET_KEVENT, 1, [Define if using the kevent I/O backend])
265   MODULE_OBJS="$MODULE_OBJS ioset-kevent.\$(OBJEXT)"
266   IOMUXES="$IOMUXES kevent"
267 fi
268
269 AC_ARG_WITH([win32],
270 [  --with-win32             Enables the Win32 I/O backend],
271 [],
272 [withval="no"])
273 if test "x$withval" = xyes ; then
274   AC_DEFINE(WITH_IOSET_WIN32, 1, [Define if using the Win32 I/O backend])
275   MODULE_OBJS="$MODULE_OBJS ioset-win32.\$(OBJEXT)"
276   IOMUXES="$IOMUXES win32"
277 fi
278
279 IOMUXES=`echo $IOMUXES | sed 's/^ +//'`
280 if test "x$IOMUXES" = "x" ; then
281   AC_MSG_ERROR([No supported I/O multiplexing backend found])
282 else
283   AC_MSG_RESULT($IOMUXES)
284 fi
285
286 AC_ARG_WITH(getopt,
287 [  --without-getopt        Disables building of the GNU getopt library],
288 [if test "$withval" = no; then
289   AC_DEFINE(IGNORE_GETOPT, 1, [Define to disable built-in getopt library])
290 fi])
291
292 AC_MSG_CHECKING(whether to enable tokenization)
293 AC_ARG_ENABLE(tokens,
294 [  --disable-tokens        Disables tokenization of P10 protocol output
295                            (tokens required if linking to ircu 2.10.11)],
296 [],[enableval=yes])
297 if test "z$enableval" = zno ; then
298   AC_MSG_RESULT(no)
299 else
300   AC_DEFINE(ENABLE_TOKENS, 1, [Define if tokenized P10 desired])
301   AC_MSG_RESULT(yes)
302 fi
303
304 AC_MSG_CHECKING(whether to enable debug behaviors)
305 AC_ARG_ENABLE(debug,
306 [  --enable-debug          Enables debugging behaviors],
307 [
308   CPPFLAGS="$CPPFLAGS"
309   AC_MSG_RESULT(yes)
310 ],
311 [
312   CPPFLAGS="$CPPFLAGS -DNDEBUG"
313   AC_MSG_RESULT(no)
314 ])
315
316 if test -e src ; then
317   if test ! -d src ; then
318     AC_MSG_ERROR([src exists but is not a directory; please move it out of the way.])
319   fi
320 else
321   mkdir src
322 fi
323 AC_MSG_CHECKING(for extra module files)
324 MODULE_DEFINES="src/modules-list.h"
325 echo > $MODULE_DEFINES
326 touch $MODULE_DEFINES
327 AC_ARG_ENABLE(modules,
328 [  --enable-modules=list,of,modules   Enable extra modules],
329 [
330   OIFS="$IFS"
331   IFS=','
332   EXTRA_MODULE_OBJS=""
333   module_list=""
334   dnl Must use a separate file because autoconf can't stand newlines in an AC_SUBSTed variable.
335   for module in $enableval ; do
336     module=`echo $module | sed -e s/^mod-// -e s/\.c\$//`
337     EXTRA_MODULE_OBJS="$EXTRA_MODULE_OBJS mod-$module.\$(OBJEXT)"
338     module_list="$module_list $module"
339     echo "WITH_MODULE($module)" >> $MODULE_DEFINES
340   done
341   IFS="$OIFS"
342   MODULE_OBJS="$MODULE_OBJS $EXTRA_MODULE_OBJS"
343   AC_MSG_RESULT($module_list)
344 ],
345 [
346   AC_MSG_RESULT(none)
347 ])
348
349 MY_SUBDIRS=""
350 RX_INCLUDES=""
351 RX_LIBS=""
352 if test "${BROKEN_REGEX}" = yes -o "${ac_cv_func_regcomp}" = no; then
353   MY_SUBDIRS="rx $MY_SUBDIRS"
354   RX_INCLUDES="-I../rx"
355   RX_LIBS="../rx/librx.a"
356 fi
357 MY_SUBDIRS="$MY_SUBDIRS src"
358 CFLAGS="$CFLAGS $ANSI_SRC -W -Wall"
359 if test "z$USE_MAINTAINER_MODE" = zyes ; then
360   CFLAGS="$CFLAGS -Werror -ansi"
361 fi
362
363 AC_DEFINE_UNQUOTED(CODENAME, "${CODENAME}", [Code name for this release])
364 AC_SUBST(MODULE_OBJS)
365 AC_SUBST(MY_SUBDIRS)
366 AC_SUBST(RX_INCLUDES)
367 AC_SUBST(RX_LIBS)
368 AC_CONFIG_FILES(Makefile rx/Makefile src/Makefile)
369 AC_OUTPUT