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