Fix the build with gcc 4.4 and newer versions of libtool.
[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=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 LT_INIT
14
15 dnl Compiler/runtime feature checks.
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_LN_S
24 AC_PROG_MAKE_SET
25 AC_PROG_GCC_TRADITIONAL
26
27 dnl Look for a git client
28 AC_CHECK_PROGS(GIT, [git])
29 AM_CONDITIONAL(HAS_GIT, test z$GIT != z)
30
31 dnl nice that unixes can all follow a standard.
32 case $target in
33   *-freebsd2* | *-freebsdelf2* | *-freebsd*out3*)
34     ANSI_SRC=""
35     ;;
36   *-freebsd3* | *-freebsdelf3* | *-freebsd*out3*)
37     ANSI_SRC=""
38     AC_DEFINE(BROKEN_REGEX, 1, [Define if the system regex library is unreliable.])
39         BROKEN_REGEX=yes
40     ;;
41   *-solaris*)
42     EXTRA_DEFINE="-D__SOLARIS__"
43     ANSI_SRC="-fno-builtin"
44     ;;
45   *-cygwin)
46     ANSI_SRC="-fno-builtin"
47     ;;
48   *-linux*)
49     dnl -D_GNU_SOURCE needed for strsignal()
50     EXTRA_DEFINE="-D_GNU_SOURCE"
51     ANSI_SRC=""
52     ;;
53   *)
54     ANSI_SRC=""
55     ;;
56 esac
57 CFLAGS="$CFLAGS $EXTRA_DEFINE"
58
59 dnl Checks for libraries.
60 AC_CHECK_LIB(socket, socket)
61 AC_CHECK_LIB(nsl, gethostbyname)
62
63 dnl Checks for header files.
64 AC_HEADER_STDC
65
66 dnl will be used for portability stuff
67 AC_HEADER_TIME
68 AC_STRUCT_TM
69
70 dnl Would rather not bail on headers, BSD has alot of the functions elsewhere. -Jedi
71 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,,)
72
73 dnl portability stuff, hurray! -Jedi
74 AC_CHECK_MEMBER([struct sockaddr.sa_len],
75                 [AC_DEFINE([HAVE_SOCKADDR_SA_LEN],[1],[Define if struct sockaddr has sa_len field])],
76                 [],[#include <sys/types.h>
77 #include <sys/socket.h>])
78 AC_CHECK_MEMBER([struct addrinfo.ai_flags],
79                 [AC_DEFINE([HAVE_STRUCT_ADDRINFO],[1],[Define if struct addrinfo declared])],
80                 [],[#include <sys/types.h>
81 #include <sys/socket.h>
82 #include <netdb.h>])
83
84 dnl We have fallbacks in case these are missing, so just check for them.
85 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,,)
86
87 dnl Check for the fallbacks for functions missing above.
88 if test $ac_cv_func_gettimeofday = no; then
89   AC_CHECK_FUNCS(ftime,,AC_MSG_ERROR([ftime or gettimeofday required.  srvx build will fail.]))
90 fi
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 if test "z$USE_MAINTAINER_MODE" = zyes ; then
137   CFLAGS="$CFLAGS -ansi"
138 fi
139
140 dnl Check for post-C89 keywords
141 AC_C_INLINE
142
143 dnl How to copy one va_list to another?
144 AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy, [AC_LINK_IFELSE(
145   [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);])],
146   [ac_cv_c_va_copy="yes"],
147   [ac_cv_c_va_copy="no"]
148 )])
149 if test "$ac_cv_c_va_copy" = "yes" ; then
150   AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
151 fi
152
153 AC_CACHE_CHECK([for __va_copy], ac_cv_c___va_copy, [AC_LINK_IFELSE(
154   [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; __va_copy(ap1, ap2);])],
155   [ac_cv_c___va_copy="yes"],
156   [ac_cv_c___va_copy="no"]
157 )])
158 if test "$ac_cv_c___va_copy" = "yes" ; then
159   AC_DEFINE(HAVE___VA_COPY, 1, [Define if we have __va_copy])
160 fi
161
162 dnl Now fix things back up
163 CFLAGS=$OLD_CFLAGS
164
165 dnl Optional features.
166 AC_MSG_CHECKING(which malloc to use)
167 AC_ARG_WITH(malloc,
168 [  --with-malloc=type      Enables use of a special malloc library; one of:
169                           system (the default), boehm-gc, dmalloc, mpatrol, srvx, slab],
170 [],
171 [withval="system"])
172 if test "x$withval" = "xsystem" ; then
173   AC_MSG_RESULT(system)
174   AC_DEFINE(WITH_MALLOC_SYSTEM, 1, [Define if using the system's malloc])
175 elif test "x$withval" = "xdmalloc" ; then
176   AC_MSG_RESULT(dmalloc)
177   AC_CHECK_HEADERS(dmalloc.h,,AC_MSG_ERROR([dmalloc header file missing.  dmalloc build will fail.]))
178   AC_CHECK_LIB(dmalloc,malloc,,AC_MSG_ERROR([dmalloc library is missing.  dmalloc build will fail.]))
179   AC_DEFINE(WITH_MALLOC_DMALLOC, 1, [Define if using the dmalloc debugging malloc package])
180 elif test "x$withval" = "xmpatrol" ; then
181   AC_MSG_RESULT(mpatrol)
182   AC_CHECK_HEADERS(mpatrol.h,,AC_MSG_ERROR([mpatrol header file missing.  mpatrol build will fail.]))
183   dnl Using mpatrol requires linking against libelf, at least on Linux.
184   AC_CHECK_LIB(elf, elf_begin)
185   AC_CHECK_LIB(mpatrol,__mp_atexit,,AC_MSG_ERROR([mpatrol library is missing completely.  mpatrol build will fail.]))
186   AC_DEFINE(WITH_MALLOC_MPATROL, 1, [Define if using the mpatrol malloc debugging package])
187 elif test "x$withval" = "xboehm-gc" ; then
188   AC_MSG_RESULT(boehm-gc)
189   AC_CHECK_HEADERS(gc/gc.h,,AC_MSG_ERROR([Boehm GC header file missing.  boehm-gc build will fail.]))
190   AC_CHECK_LIB(dl, dlopen, , AC_MSG_ERROR([libdl library is missing.  boehm-gc build will fail.]))
191   AC_CHECK_LIB(gc, GC_gcollect, , AC_MSG_ERROR([Boehm GC library is missing.  boehm-gc build will fail.]))
192   AC_DEFINE(WITH_MALLOC_BOEHM_GC, 1, [Define if using the Boehm GC to garbage collect and check memory leaks])
193 elif test "x$withval" = "xsrvx" ; then
194   AC_MSG_RESULT(srvx)
195   AC_DEFINE(WITH_MALLOC_SRVX, 1, [Define if using the srvx internal debug allocator])
196   MODULE_OBJS="$MODULE_OBJS alloc-srvx.\$(OBJEXT)"
197 elif test "x$withval" = "xslab" ; then
198   AC_MSG_RESULT(slab)
199   AC_DEFINE(WITH_MALLOC_SLAB, 1, [Define if using the slab internal debug allocator])
200   MODULE_OBJS="$MODULE_OBJS alloc-slab.\$(OBJEXT)"
201 else
202   AC_MSG_ERROR([Unknown malloc type $withval])
203 fi
204
205 AC_MSG_CHECKING(which protocol to use)
206 AC_ARG_WITH(protocol,
207 [  --with-protocol=name    Choose IRC dialect to support; one of:
208                           p10 (the default), bahamut],
209 [],
210 [withval="p10"])
211 if test "x$withval" = "xp10" ; then
212   AC_MSG_RESULT([P10])
213   AC_DEFINE(WITH_PROTOCOL_P10, 1, [Define if using the P10 dialect of IRC])
214   MODULE_OBJS="$MODULE_OBJS proto-p10.\$(OBJEXT)"
215 elif test "x$withval" = "xbahamut" ; then
216   AC_MSG_RESULT([Bahamut])
217   AC_DEFINE(WITH_PROTOCOL_BAHAMUT, 1, [Define if using the Bahamut dialect of IRC])
218   MODULE_OBJS="$MODULE_OBJS proto-bahamut.\$(OBJEXT)"
219 elif test -r "${srcdir}/src/proto-${withval}.c" ; then
220   AC_MSG_RESULT([$withval])
221   MODULE_OBJS="$MODULE_OBJS proto-${withval}.\$(OBJEXT)"
222 else
223   AC_MSG_ERROR([Unknown IRC dialect $withval])
224 fi
225
226 AC_MSG_CHECKING(how to send mail)
227 AC_ARG_WITH(mail,
228 [  --with-mail=name        How to send mail; one of:
229                           sendmail (the default), smtp],
230 [],
231 [withval="sendmail"])
232 if test -r "${srcdir}/src/mail-${withval}.c" ; then
233   AC_MSG_RESULT([$withval])
234   MODULE_OBJS="$MODULE_OBJS mail-${withval}.\$(OBJEXT)"
235 else
236   AC_MSG_ERROR([Unknown mail method $withval])
237 fi
238
239 AC_MSG_CHECKING([I/O multiplexing backends])
240 IOMUXES=""
241
242 if test "x$ac_cv_func_select" = xyes ; then
243   AC_DEFINE(WITH_IOSET_SELECT, 1, [Define if using the select() I/O backend])
244   MODULE_OBJS="$MODULE_OBJS ioset-select.\$(OBJEXT)"
245   IOMUXES="$IOMUXES select"
246 fi
247
248 AC_ARG_WITH([epoll],
249 [  --without-epoll         Disables the epoll_*() I/O backend],
250 [],
251 [withval="$ac_cv_func_epoll_create"])
252 if test "x$withval" = xyes ; then
253   AC_DEFINE(WITH_IOSET_EPOLL, 1, [Define if using the epoll I/O backend])
254   MODULE_OBJS="$MODULE_OBJS ioset-epoll.\$(OBJEXT)"
255   IOMUXES="$IOMUXES epoll"
256 fi
257
258 AC_ARG_WITH([kevent],
259 [  --without-kevent        Disables the kevent() I/O backend],
260 [],
261 [withval="$ac_cv_func_kevent"])
262 if test "x$withval" = xyes ; then
263   AC_DEFINE(WITH_IOSET_KEVENT, 1, [Define if using the kevent I/O backend])
264   MODULE_OBJS="$MODULE_OBJS ioset-kevent.\$(OBJEXT)"
265   IOMUXES="$IOMUXES kevent"
266 fi
267
268 AC_ARG_WITH([win32],
269 [  --with-win32            Enables the Win32 I/O backend],
270 [],
271 [withval="no"])
272 if test "x$withval" = xyes ; then
273   AC_DEFINE(WITH_IOSET_WIN32, 1, [Define if using the Win32 I/O backend])
274   MODULE_OBJS="$MODULE_OBJS ioset-win32.\$(OBJEXT)"
275   IOMUXES="$IOMUXES win32"
276 fi
277
278 IOMUXES=`echo $IOMUXES | sed 's/^ +//'`
279 if test "x$IOMUXES" = "x" ; then
280   AC_MSG_ERROR([No supported I/O multiplexing backend found])
281 else
282   AC_MSG_RESULT($IOMUXES)
283 fi
284
285 AC_ARG_WITH(getopt,
286 [  --without-getopt        Disables building of the GNU getopt library],
287 [if test "$withval" = no; then
288   AC_DEFINE(IGNORE_GETOPT, 1, [Define to disable built-in getopt library])
289 fi])
290
291 AC_MSG_CHECKING(whether to enable tokenization)
292 AC_ARG_ENABLE(tokens,
293 [  --disable-tokens        Disables tokenization of P10 protocol output
294                            (tokens required if linking to ircu 2.10.11)],
295 [],[enableval=yes])
296 if test "z$enableval" = zno ; then
297   AC_MSG_RESULT(no)
298 else
299   AC_DEFINE(ENABLE_TOKENS, 1, [Define if tokenized P10 desired])
300   AC_MSG_RESULT(yes)
301 fi
302
303 AC_MSG_CHECKING(whether to enable debug behaviors)
304 AC_ARG_ENABLE(debug,
305 [  --enable-debug          Enables debugging behaviors],
306 [
307   CPPFLAGS="$CPPFLAGS"
308   AC_MSG_RESULT(yes)
309 ],
310 [
311   CPPFLAGS="$CPPFLAGS -DNDEBUG"
312   AC_MSG_RESULT(no)
313 ])
314
315 if test -e src ; then
316   if test ! -d src ; then
317     AC_MSG_ERROR([src exists but is not a directory; please move it out of the way.])
318   fi
319 else
320   mkdir src
321 fi
322 AC_MSG_CHECKING(for extra module files)
323 MODULE_DEFINES="src/modules-list.h"
324 echo > $MODULE_DEFINES
325 touch $MODULE_DEFINES
326 AC_ARG_ENABLE(modules,
327 [  --enable-modules=list,of,modules   Enable extra modules],
328 [
329   OIFS="$IFS"
330   IFS=','
331   EXTRA_MODULE_OBJS=""
332   module_list=""
333   dnl Must use a separate file because autoconf can't stand newlines in an AC_SUBSTed variable.
334   for module in $enableval ; do
335     module=`echo $module | sed -e s/^mod-// -e s/\.c\$//`
336     EXTRA_MODULE_OBJS="$EXTRA_MODULE_OBJS mod-$module.\$(OBJEXT)"
337     module_list="$module_list $module"
338     echo "WITH_MODULE($module)" >> $MODULE_DEFINES
339   done
340   IFS="$OIFS"
341   MODULE_OBJS="$MODULE_OBJS $EXTRA_MODULE_OBJS"
342   AC_MSG_RESULT($module_list)
343 ],
344 [
345   AC_MSG_RESULT(none)
346 ])
347
348 MY_SUBDIRS=""
349 RX_INCLUDES=""
350 RX_LIBS=""
351 if test "${BROKEN_REGEX}" = yes -o "${ac_cv_func_regcomp}" = no; then
352   MY_SUBDIRS="rx $MY_SUBDIRS"
353   RX_INCLUDES="-I../rx"
354   RX_LIBS="../rx/librx.a"
355 fi
356 MY_SUBDIRS="$MY_SUBDIRS src"
357 CFLAGS="$CFLAGS $ANSI_SRC -W -Wall"
358 if test "z$USE_MAINTAINER_MODE" = zyes ; then
359   CFLAGS="$CFLAGS -Werror -Wshadow -ansi"
360 fi
361
362 AC_DEFINE_UNQUOTED(CODENAME, "${CODENAME}", [Code name for this release])
363 AC_SUBST(MODULE_OBJS)
364 AC_SUBST(MY_SUBDIRS)
365 AC_SUBST(RX_INCLUDES)
366 AC_SUBST(RX_LIBS)
367 AC_CONFIG_FILES(Makefile rx/Makefile src/Makefile)
368 AC_OUTPUT