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