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