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