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