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