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