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