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