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