* configure.ac check for malloc.h header file (Mac OS X needs this)
[citadel.git] / citadel / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 dnl $Id$
3 AC_PREREQ(2.52)
4 AC_INIT([Citadel/UX], [5.91], [http://uncensored.citadel.org/])
5 AC_REVISION([$Revision$])
6 AC_CONFIG_SRCDIR([citserver.c])
7 AC_PREFIX_DEFAULT(/usr/local/citadel)
8 if test "$prefix" = NONE; then
9         AC_DEFINE_UNQUOTED(BBSDIR, "$ac_default_prefix")
10 else
11         AC_DEFINE_UNQUOTED(BBSDIR, "$prefix")
12 fi
13
14 AC_ARG_ENABLE(autologin, [  --disable-autologin     disable autologin (default is enabled if possible)])
15 AC_ARG_ENABLE(chkpwd, [  --disable-chkpwd        don't build 'chkpwd'])
16
17 AC_ARG_ENABLE(threaded-client, [  --disable-threaded-client
18                           disable multithreaded client])
19
20 AC_ARG_WITH(pam, [  --with-pam              use PAM if present (see PAM.txt before you try this)])
21 AC_ARG_WITH(kthread, [  --with-kthread          use kernel threads (on FreeBSD) (not recommended yet)])
22 AC_ARG_WITH(gdbm, [  --with-gdbm@<:@=DIR@:>@       use GDBM @<:@DIR=/usr/local@:>@])
23 AC_ARG_WITH(db, [  --with-db@<:@=DIR@:>@         use Sleepycat DB 3.x @<:@DIR=/usr/local/BerkeleyDB.3.@<:@123@:>@@:>@])
24 AC_ARG_WITH(ssl,
25         [  --with-ssl=PATH     Specify path to OpenSSL installation ],
26         [
27                 if test "x$withval" != "xno" ; then
28                         tryssldir=$withval
29                 fi
30         ]
31 )
32 AC_ARG_WITH(ncurses, [  --without-ncurses       don't use ncurses])
33
34 AC_ARG_WITH(with_zlib, [  --with-zlib             use zlib compression if present])
35 AC_ARG_WITH(with_libical, [  --with-libical          use libical calendaring library])
36
37 if test "x$with_gdbm" != xno -a "x$with_gdbm" != xyes -a "$with_gdbm"; then
38         db_dir="$with_gdbm"
39         with_gdbm=yes
40 fi
41
42 if test "x$with_db" != xno -a "x$with_db" != xyes -a "$with_db"; then
43         db_dir="$with_db"
44         with_db=yes
45 else
46         test -f /usr/local/lib/libdb.a -o -f /usr/local/lib/libdb.so \
47           -o -f /usr/local/lib/libdb4.a -o -f /usr/local/lib/libdb4.so \
48           -o -f /usr/local/lib/libdb3.a -o -f /usr/local/lib/libdb3.so && db_dir=/usr/local
49
50         test -d /usr/local/BerkeleyDB.3.1 && db_dir=/usr/local/BerkeleyDB.3.1
51         test -d /usr/local/BerkeleyDB.3.2 && db_dir=/usr/local/BerkeleyDB.3.2
52         test -d /usr/local/BerkeleyDB.3.3 && db_dir=/usr/local/BerkeleyDB.3.3
53         test -d /usr/local/BerkeleyDB.4.0 && db_dir=/usr/local/BerkeleyDB.4.0
54 fi
55
56 if test "x$with_gdbm" = xyes -a "x$with_db" = xyes; then
57         AC_MSG_ERROR(can't enable both gdbm and db)
58 fi
59
60 dnl By default, we only build the client (citadel and whobbs) unless we can
61 dnl figure out how to build with POSIX threads.
62 TARGETS=client
63
64 AC_CANONICAL_HOST
65 PTHREAD_DEFS=-D_REENTRANT
66 case "$host" in
67         dnl BSDI 3.0 wants relocatable object modules instead of shared libs
68         dnl for dlopen(), and has a wrapper script to link with shared libs.
69         dnl Also has stupid non-reentrant gethostbyaddr() and friends.
70         *-*-bsdi[123]*)
71                 test -z "$CC" -a -x /usr/bin/shlicc2 && CC=shlicc2
72                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
73         ;;
74         *-*-bsdi*)
75                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
76         ;;
77         dnl Digital Unix has an odd way to build for pthreads, and we can't
78         dnl build pthreads programs with gcc due to header problems.
79         alpha*-dec-osf*)
80                 test -z "$CC" && CC=cc
81                 LIBS="-lpthread -lexc $LIBS"
82                 check_pthread=no
83         ;;
84         dnl FreeBSD is similar to Digital UNIX with DEC C, which has a -pthread flag:
85         *-*-freebsd*)
86                 if test "$with_kthread" = yes; then
87                         LIBS="-kthread $LIBS"
88                 else
89                         LIBS="-pthread $LIBS"
90                 fi
91                 check_pthread=no
92                 PTHREAD_DEFS=-D_THREAD_SAFE
93         ;;
94         *-*-openbsd*)
95                 LIBS="-pthread $LIBS"
96                 check_pthread=no
97                 PTHREAD_DEFS=-pthread
98         ;;
99         *-*-solaris*)
100                 PTHREAD_DEFS="-D_REENTRANT -D_PTHREADS"
101         ;;
102 esac
103 DEFS="$DEFS $PTHREAD_DEFS"
104
105 dnl Checks for programs.
106 AC_PROG_CC
107
108 dnl Set up system-dependent compiler flags.
109 if test "$GCC" = yes; then
110         case "$host" in
111                 *-*-solaris*|alpha*-dec-osf*)
112                         CFLAGS="$CFLAGS -Wall -Wcast-qual -Wcast-align -Wno-char-subscripts"
113                 ;;
114                 *)
115                         CFLAGS="$CFLAGS -Wall -Wcast-qual -Wcast-align -Wstrict-prototypes"
116                 ;;
117         esac
118 fi
119 AC_LIBTOOL_DLOPEN
120 AC_LIBTOOL_WIN32_DLL
121 AC_DISABLE_STATIC
122 AC_PROG_LIBTOOL
123 AC_SUBST(LIBTOOL_DEPS)
124 AC_PROG_INSTALL
125 AC_PROG_YACC
126 missing_dir=`cd $ac_aux_dir && pwd`
127 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
128 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
129
130 dnl Checks for system services.
131
132 dnl Check the size of various builtin types; see typesize.h (error)
133 AC_CHECK_SIZEOF(char, 0)
134 AC_CHECK_SIZEOF(short, 0)
135 AC_CHECK_SIZEOF(int, 0)
136 AC_CHECK_SIZEOF(long, 0)
137 dnl AC_CHECK_SIZEOF(long long, 0)
138
139 dnl Checks for libraries.
140
141 dnl We want to test for the following in libc before checking for their
142 dnl respective libraries, because some systems (like Irix) have both, and the
143 dnl non-libc versions may be broken.
144 AC_CHECK_FUNCS(crypt dlopen gethostbyname connect)
145
146 if test "$ac_cv_func_gethostbyname" = no; then
147         AC_CHECK_LIB(nsl, gethostbyname)
148 fi
149
150 if test "$ac_cv_func_connect" = no; then
151         AC_CHECK_LIB(socket, connect)
152 fi
153
154 if test "$ac_cv_func_dlopen" = no; then
155         AC_CHECK_LIB(dl, dlopen, [LIBS="-ldl $LIBS"
156                test "$with_pam" = yes && chkpwd_LIBS="-ldl $chkpwd_LIBS"])
157 fi
158
159 dnl Check for HP/UX dynamic loader. This should only be in -ldld.
160 AC_CHECK_LIB(dld, shl_load, LIBS="-ldld $LIBS")
161
162 dnl Check for Solaris realtime support
163 AC_CHECK_LIB(rt, sched_yield)
164
165 dnl Determine the system's authentication capabilities, if autologin is
166 dnl requested. We currently support PAM, standard getpwnam(), and getspnam()
167 dnl (Linux shadow passwords)
168 if test "$enable_autologin" != no; then
169         if test "$with_pam" = yes; then
170                 save_LIBS=$LIBS
171                 AC_CHECK_LIB(pam, pam_start, [chkpwd_LIBS="-lpam $chkpwd_LIBS"
172                         LIBS="-lpam $LIBS"])
173                 AC_CHECK_FUNCS(pam_start)
174                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
175         fi
176         if test "$ac_cv_func_pam_start" = no -o "$with_pam" != yes; then
177                 save_LIBS=$LIBS
178                 AC_SEARCH_LIBS(getspnam, shadow, [
179                         if test "$ac_cv_search_getspnam" = -lshadow; then
180                                 chkpwd_LIBS="-lshadow $chkpwd_LIBS"
181                         fi])
182                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
183                 if test "$ac_cv_func_crypt" = no; then
184                         AC_CHECK_LIB(crypt, crypt, [
185                                 chkpwd_LIBS="-lcrypt $chkpwd_LIBS"
186                                 test "$enable_chkpwd" = no && \
187                                         LIBS="-lcrypt $LIBS"])
188                 fi
189         fi
190         if test "$ac_cv_func_crypt" = yes -o "$ac_cv_lib_crypt_crypt" = yes -o "$ac_cv_func_pam_start" = yes; then
191                 AC_DEFINE(ENABLE_AUTOLOGIN)
192                 if test "$enable_chkpwd" != no; then
193                         AC_DEFINE(ENABLE_CHKPWD)
194                         CHKPWD=chkpwd
195                 else
196                         AUTH=auth.lo
197                 fi
198         fi
199 fi
200
201 test -f /usr/local/lib/libresolv.a && LDFLAGS="$LDFLAGS -L/usr/local/lib"
202 AC_CHECK_LIB(resolv, res_query, RESOLV="$RESOLV -lresolv")
203
204 if test "x$with_ncurses" != "xno"; then
205         AC_SEARCH_LIBS(tgetent, [ncurses curses termcap])
206         AC_SEARCH_LIBS(scrollok, [ncurses curses])
207         AC_SEARCH_LIBS(initscr, [ncurses curses])
208 else
209         AC_SEARCH_LIBS(tgetent, [curses termcap])
210         AC_SEARCH_LIBS(initscr, [curses])
211 fi
212 AC_CHECK_FUNCS(vw_printw wcolor_set resizeterm wresize)
213
214 dnl Check for libpthread(s) if we're not using Digital UNIX or FreeBSD. (On
215 dnl which the -pthread flag takes care of this.)
216 if test "$check_pthread" != no; then
217         AC_CHECK_LIB(pthread, pthread_create)
218         AC_CHECK_LIB(pthreads, pthread_create)
219 fi
220
221 # The big search for OpenSSL
222 if test "$with_ssl" != "no"; then
223         saved_LIBS="$LIBS"
224         saved_LDFLAGS="$LDFLAGS"
225         saved_CFLAGS="$CFLAGS"
226         if test "x$prefix" != "xNONE"; then
227                 tryssldir="$tryssldir $prefix"
228         fi
229         AC_CACHE_CHECK([for OpenSSL], ac_cv_openssldir, [
230                 for ssldir in $tryssldir "" /usr /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/pkg /opt /opt/openssl ; do
231                         CFLAGS="$saved_CFLAGS"
232                         LDFLAGS="$saved_LDFLAGS"
233                         LIBS="$saved_LIBS -lssl -lcrypto"
234         
235                         # Skip directories if they don't exist
236                         if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
237                                 continue;
238                         fi
239                         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
240                                 # Try to use $ssldir/lib if it exists, otherwise
241                                 # $ssldir
242                                 if test -d "$ssldir/lib" ; then
243                                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
244                                         if test ! -z "$need_dash_r" ; then
245                                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
246                                         fi
247                                 else
248                                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
249                                         if test ! -z "$need_dash_r" ; then
250                                                 LDFLAGS="-R$ssldir $LDFLAGS"
251                                         fi
252                                 fi
253                                 # Try to use $ssldir/include if it exists, otherwise
254                                 # $ssldir
255                                 if test -d "$ssldir/include" ; then
256                                         CFLAGS="-I$ssldir/include $saved_CFLAGS"
257                                 else
258                                         CFLAGS="-I$ssldir $saved_CFLAGS"
259                                 fi
260                         fi
261         
262                         # Basic test to check for compatible version and correct linking
263                         # *does not* test for RSA - that comes later.
264                         AC_TRY_RUN(
265                                 [
266         #include <string.h>
267         #include <openssl/rand.h>
268         int main(void)
269         {
270                 char a[2048];
271                 memset(a, 0, sizeof(a));
272                 RAND_add(a, sizeof(a), sizeof(a));
273                 return(RAND_status() <= 0);
274         }
275                                 ],
276                                 [
277                                         found_crypto=1
278                                         break;
279                                 ], []
280                         )
281         
282                         if test ! -z "$found_crypto" ; then
283                                 break;
284                         fi
285                 done
286         
287                 if test -z "$ssldir" ; then
288                         ssldir="(system)"
289                 fi
290         
291                 if test ! -z "$found_crypto" ; then
292                         ac_cv_openssldir=$ssldir
293                 else
294                         ac_cv_openssldir="no"
295                 fi
296         ])
297         LIBS="$saved_LIBS"
298         LDFLAGS="$saved_LDFLAGS"
299         CFLAGS="$saved_CFLAGS"
300         
301         if test "x$ac_cv_openssldir" != "xno" ; then
302                 AC_DEFINE(HAVE_OPENSSL)
303                 LIBS="-lssl -lcrypto $LIBS"
304                 dnl Need to recover ssldir - test above runs in subshell
305                 ssldir=$ac_cv_openssldir
306                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr" -a "x$ssldir" != "x(system)"; then
307                         # Try to use $ssldir/lib if it exists, otherwise
308                         # $ssldir
309                         if test -d "$ssldir/lib" ; then
310                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
311                                 if test ! -z "$need_dash_r" ; then
312                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
313                                 fi
314                         else
315                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
316                                 if test ! -z "$need_dash_r" ; then
317                                         LDFLAGS="-R$ssldir $LDFLAGS"
318                                 fi
319                         fi
320                         # Try to use $ssldir/include if it exists, otherwise
321                         # $ssldir
322                         if test -d "$ssldir/include" ; then
323                                 CFLAGS="-I$ssldir/include $saved_CFLAGS"
324                         else
325                                 CFLAGS="-I$ssldir $saved_CFLAGS"
326                         fi
327                 fi
328         fi
329 fi
330
331 if test "x$with_db" != xno -a "x$with_gdbm" != xyes; then
332         test "$db_dir" && LDFLAGS="$LDFLAGS -L$db_dir/lib"
333
334         dblib=""
335
336         if test -d "$db_dir/include/db4"; then
337                 CPPFLAGS="$CPPFLAGS -I$db_dir/include/db4"
338                 dblib="db4"
339         elif test -d "$db_dir/include/db3"; then
340                 CPPFLAGS="$CPPFLAGS -I$db_dir/include/db3"
341                 dblib="db3"
342         elif test "$db_dir"; then
343                 CPPFLAGS="$CPPFLAGS -I$db_dir/include"
344         elif test -d /usr/include/db4; then
345                 CPPFLAGS="$CPPFLAGS -I/usr/include/db4"
346                 dblib="db4"
347         elif test -d /usr/include/db3; then
348                 CPPFLAGS="$CPPFLAGS -I/usr/include/db3"
349                 dblib="db3"
350         fi
351
352         AC_SEARCH_LIBS(db_env_create, [$dblib db db4 db3], [
353                 DATABASE=database_sleepycat.c
354                 with_gdbm=no
355         ])
356
357 fi
358
359 if test "x$with_gdbm" != xno -a "x$with_db" != xyes; then
360         test -f /usr/local/lib/libgdbm.a -o -f /usr/local/lib/libgdbm.so && db_dir=/usr/local
361         test "$db_dir" && LDFLAGS="$LDFLAGS -L$db_dir/lib"
362
363         test "$db_dir" && CPPFLAGS="$CPPFLAGS -I$db_dir/include"
364
365         AC_CHECK_LIB(gdbm, gdbm_open,
366                 [LIBS="-lgdbm $LIBS"
367                 DATABASE=database.c
368                 with_db=no])
369 fi
370
371
372
373 dnl Checks for the zlib compression library.
374 if test "x$with_zlib" != xno ; then
375         AC_CHECK_HEADERS(zlib.h,
376                 [AC_CHECK_LIB(z, zlibVersion,
377                         [ok_zlib=yes],,
378         )])
379 fi
380
381 if test "x$ok_zlib" = xyes ; then
382         LIBS="-lz $LIBS"
383         AC_DEFINE(HAVE_ZLIB)
384 fi
385
386
387
388 dnl Checks for the libical calendaring library.
389 if test "x$with_libical" != xno ; then
390         AC_CHECK_HEADERS(ical.h,
391                 [AC_CHECK_LIB(ical, icalcomponent_new,
392                         [ok_libical=yes],,
393         )])
394 fi
395
396 if test "x$ok_libical" = xyes ; then
397         LIBS="-lical $LIBS"
398         AC_DEFINE(HAVE_LIBICAL)
399 fi
400
401
402
403 dnl Checks for header files.
404 AC_HEADER_DIRENT
405 AC_HEADER_STDC
406 AC_HEADER_SYS_WAIT
407
408 dnl
409 dnl TODO: for the DB header checks, we should check whether the headers
410 dnl define db_env_create, somehow
411 dnl
412 AC_CHECK_HEADERS(curses.h dl.h fcntl.h limits.h malloc.h termios.h sys/ioctl.h sys/select.h sys/time.h syslog.h unistd.h utmp.h utmpx.h paths.h db.h db3/db.h db4/db.h pthread.h netinet/in.h)
413
414 dnl
415 dnl need to check if this is actually compilable, sometimes there are
416 dnl conflicts with the system's headers (eg solaris xpg4 style headers)
417 dnl
418 if test "x$with_ncurses" != xno; then
419         AC_CHECK_HEADERS(ncurses.h,,,[ ])
420 fi
421
422 AC_CHECK_HEADER(resolv.h, [SMTP=modules/libsmtp.la; DOMAIN=domain.c],,
423 [#ifdef HAVE_SYS_TYPES_H
424 #include <sys/types.h>
425 #endif
426 #ifdef HAVE_NETINET_IN_H
427 #include <netinet/in.h>
428 #endif])
429
430 AC_SUBST(SMTP)
431 AC_SUBST(DOMAIN)
432
433 dnl Checks for typedefs, structures, and compiler characteristics.
434 AC_C_CONST
435 AC_TYPE_PID_T
436 AC_TYPE_SIZE_T
437 AC_HEADER_TIME
438
439 dnl defined in acinclude.m4:
440 CIT_STRUCT_TM
441
442 AC_CACHE_CHECK([for ut_type in struct utmp], ac_cv_struct_ut_type,
443 [AC_TRY_COMPILE([#include <sys/types.h>
444 #include <utmp.h>], [struct utmp ut; ut.ut_type;],
445 ac_cv_struct_ut_type=yes, ac_cv_struct_ut_type=no)])
446 if test $ac_cv_struct_ut_type = yes; then
447         AC_DEFINE(HAVE_UT_TYPE)
448 fi
449
450 AC_CACHE_CHECK([for ut_host in struct utmp], ac_cv_struct_ut_host,
451 [AC_TRY_COMPILE([#include <sys/types.h>
452 #include <utmp.h>], [struct utmp ut; ut.ut_host;],
453 ac_cv_struct_ut_host=yes, ac_cv_struct_ut_host=no)])
454 if test $ac_cv_struct_ut_host = yes; then
455         AC_DEFINE(HAVE_UT_HOST)
456 fi
457
458 dnl Checks for library functions.
459 AC_FUNC_GETPGRP
460 AC_PROG_GCC_TRADITIONAL
461 AC_TYPE_SIGNAL
462 AC_FUNC_VPRINTF
463 AC_CHECK_FUNCS(getspnam getutxline mkdir mkfifo mktime rmdir select socket strerror strcasecmp strncasecmp)
464
465 dnl Now check for pthreads
466
467 dnl On some platforms, AC_CHECK_FUNC[S] doesn't work for pthreads programs;
468 dnl we need to include pthread.h
469
470 AC_CACHE_CHECK([for pthread_cancel], ac_cv_func_pthread_cancel,
471 [AC_TRY_LINK([#include <pthread.h>],
472 [       pthread_t thread;
473
474         /* The GNU C library defines this for functions which it implements
475            to always fail with ENOSYS.  Some functions are actually named
476            something starting with __ and the normal name is an alias.  */
477 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
478         choke me
479 #else
480         pthread_cancel(thread);
481 #endif],
482 ac_cv_func_pthread_cancel=yes, ac_cv_func_pthread_cancel=no)])
483 if test "$ac_cv_func_pthread_cancel" = yes; then
484         AC_DEFINE(HAVE_PTHREAD_CANCEL)
485 fi
486
487 AC_CACHE_CHECK([for pthread_create], ac_cv_func_pthread_create,
488 [AC_TRY_LINK([#include <pthread.h>],
489 [       /* The GNU C library defines this for functions which it implements
490            to always fail with ENOSYS.  Some functions are actually named
491            something starting with __ and the normal name is an alias.  */
492 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
493         choke me
494 #else
495         pthread_create(NULL, NULL, NULL, NULL);
496 #endif],
497 ac_cv_func_pthread_create=yes, ac_cv_func_pthread_create=no)])
498 if test "$ac_cv_func_pthread_create" = yes; then
499         test "$DATABASE" && TARGETS="client server utils serv_modules"
500         if test "x$enable_threaded_client" != xno; then
501                 AC_DEFINE(THREADED_CLIENT)
502         fi
503 fi
504
505 AC_REPLACE_FUNCS(snprintf getutline)
506
507 dnl Done! Now write the Makefile and sysdep.h
508 AC_SUBST(AUTH)
509 AC_SUBST(CHKPWD)
510 AC_SUBST(RESOLV)
511 AC_SUBST(chkpwd_LIBS)
512 AC_SUBST(TARGETS)
513 AC_SUBST(DATABASE)
514 AC_CONFIG_HEADER(sysdep.h)
515 AC_CONFIG_FILES([Makefile weekly])
516 AC_OUTPUT
517
518 if test -z "$DATABASE"; then
519         AC_MSG_WARN([No database driver was found. Please install Berkeley DB.])
520 fi
521
522 echo ...
523 echo ...
524 echo "... On many operating systems, you must use GNU make (gmake) to compile"
525 echo ... Citadel.
526 echo ...
527 echo ...