restored the checks for /usr/include/db3 and /usr/local/include/db3
[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
25 if test "x$with_gdbm" != xno -a "x$with_gdbm" != xyes -a "$with_gdbm"; then
26         db_dir="$with_gdbm"
27         with_gdbm=yes
28 else
29         test -f /usr/local/lib/libgdbm.a -o -f /usr/local/lib/libgdbm.so && db_dir=/usr/local
30 fi
31
32 if test "x$with_db" != xno -a "x$with_db" != xyes -a "$with_db"; then
33         db_dir="$with_db"
34         with_db=yes
35 else
36         test -d /usr/local/BerkeleyDB.3.1 && db_dir=/usr/local/BerkeleyDB.3.1
37         test -d /usr/local/BerkeleyDB.3.2 && db_dir=/usr/local/BerkeleyDB.3.2
38         test -d /usr/local/BerkeleyDB.3.3 && db_dir=/usr/local/BerkeleyDB.3.3
39         test -d /usr/local/BerkeleyDB.4.0 && db_dir=/usr/local/BerkeleyDB.4.0
40 fi
41
42 if test "x$with_gdbm" = xyes -a "x$with_db" = xyes; then
43         AC_MSG_ERROR(can't enable both gdbm and db)
44 fi
45
46 dnl By default, we only build the client (citadel and whobbs) unless we can
47 dnl figure out how to build with POSIX threads.
48 TARGETS=client
49
50 AC_CANONICAL_HOST
51 PTHREAD_DEFS=-D_REENTRANT
52 case "$host" in
53         dnl BSDI 3.0 wants relocatable object modules instead of shared libs
54         dnl for dlopen(), and has a wrapper script to link with shared libs.
55         dnl Also has stupid non-reentrant gethostbyaddr() and friends.
56         *-*-bsdi[123]*)
57                 test -z "$CC" -a -x /usr/bin/shlicc2 && CC=shlicc2
58                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
59         ;;
60         *-*-bsdi*)
61                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
62         ;;
63         dnl Digital Unix has an odd way to build for pthreads, and we can't
64         dnl build pthreads programs with gcc due to header problems.
65         alpha*-dec-osf*)
66                 test -z "$CC" && CC=cc
67                 PTHREAD_LIBS="-lpthread -lexc"
68                 check_pthread=no
69         ;;
70         dnl FreeBSD is similar to Digital UNIX with DEC C, which has a -pthread flag:
71         *-*-freebsd*)
72                 if test "$with_kthread" = yes; then
73                         PTHREAD_LIBS=-kthread
74                 else
75                         PTHREAD_LIBS=-pthread
76                 fi
77                 check_pthread=no
78                 PTHREAD_DEFS=-D_THREAD_SAFE
79         ;;
80         *-*-openbsd*)
81                 PTHREAD_LIBS=-pthread
82                 check_pthread=no
83                 PTHREAD_DEFS=-pthread
84         ;;
85         *-*-solaris*)
86                 PTHREAD_DEFS="-D_REENTRANT -D_PTHREADS"
87         ;;
88 esac
89
90 dnl Checks for programs.
91 AC_PROG_CC
92
93 dnl Set up system-dependent compiler flags.
94 if test "$GCC" = yes; then
95         case "$host" in
96                 *-*-solaris*|alpha*-dec-osf*)
97                         CFLAGS="$CFLAGS -Wall -Wcast-align -Wno-char-subscripts"
98                 ;;
99                 *)
100                         CFLAGS="$CFLAGS -Wall -Wcast-align -Wstrict-prototypes"
101                 ;;
102         esac
103 fi
104 AC_LIBTOOL_DLOPEN
105 AC_LIBTOOL_WIN32_DLL
106 AC_DISABLE_STATIC
107 AC_PROG_LIBTOOL
108 AC_SUBST(LIBTOOL_DEPS)
109 AC_PROG_INSTALL
110 AC_PROG_YACC
111 missing_dir=`cd $ac_aux_dir && pwd`
112 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
113
114 dnl Checks for system services.
115
116 dnl Checks for libraries.
117
118 dnl libdl, libgdbm, and libcrypt are only used in the server, so the
119 dnl Makefile only passes $(LIBS) to that target. If other programs start
120 dnl requiring additional libraries, we'll have to use other variables, as is
121 dnl done with curses.
122
123 dnl We want to test for the following in libc before checking for their
124 dnl respective libraries, because some systems (like Irix) have both, and the
125 dnl non-libc versions may be broken.
126 AC_CHECK_FUNCS(crypt dlopen gethostbyname connect)
127
128 if test "$ac_cv_func_gethostbyname" = no; then
129         AC_CHECK_LIB(nsl, gethostbyname, NETLIBS="-lnsl $NETLIBS")
130 fi
131
132 if test "$ac_cv_func_connect" = no; then
133         AC_CHECK_LIB(socket, connect, NETLIBS="-lsocket $NETLIBS",, $NETLIBS)
134 fi
135
136 if test "$ac_cv_func_dlopen" = no; then
137         AC_CHECK_LIB(dl, dlopen, [LIBS="-ldl $LIBS"
138                test "$with_pam" = yes && chkpwd_LIBS="-ldl $chkpwd_LIBS"])
139 fi
140
141 dnl Check for HP/UX dyanmic loader. This should only be in -ldld.
142 AC_CHECK_LIB(dld, shl_load, LIBS="-ldld $LIBS")
143
144 dnl Check for Solaris realtime support
145 AC_CHECK_LIB(rt, sched_yield)
146
147 dnl Determine the system's authentication capabilities, if autologin is
148 dnl requested. We currently support PAM, standard getpwnam(), and getspnam()
149 dnl (Linux shadow passwords)
150 if test "$enable_autologin" != no; then
151         if test "$with_pam" = yes; then
152                 save_LIBS=$LIBS
153                 AC_CHECK_LIB(pam, pam_start, [chkpwd_LIBS="-lpam $chkpwd_LIBS"
154                         LIBS="-lpam $LIBS"])
155                 AC_CHECK_FUNCS(pam_start)
156                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
157         fi
158         if test "$ac_cv_func_pam_start" = no -o "$with_pam" != yes; then
159                 save_LIBS=$LIBS
160                 AC_SEARCH_LIBS(getspnam, shadow, [
161                         if test "$ac_cv_search_getspnam" = -lshadow; then
162                                 chkpwd_LIBS="-lshadow $chkpwd_LIBS"
163                         fi])
164                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
165                 if test "$ac_cv_func_crypt" = no; then
166                         AC_CHECK_LIB(crypt, crypt, [
167                                 chkpwd_LIBS="-lcrypt $chkpwd_LIBS"
168                                 test "$enable_chkpwd" = no && \
169                                         LIBS="-lcrypt $LIBS"])
170                 fi
171         fi
172         if test "$ac_cv_func_crypt" = yes -o "$ac_cv_lib_crypt_crypt" = yes -o "$ac_cv_func_pam_start" = yes; then
173                 AC_DEFINE(ENABLE_AUTOLOGIN)
174                 if test "$enable_chkpwd" != no; then
175                         AC_DEFINE(ENABLE_CHKPWD)
176                         CHKPWD=chkpwd
177                 else
178                         AUTH=auth.lo
179                 fi
180         fi
181 fi
182
183 test "$db_dir" && LDFLAGS="$LDFLAGS -L$db_dir/lib"
184 if test "x$with_db" != xno -a "x$with_gdbm" != xyes; then
185         AC_CHECK_LIB(db3, db_env_create,
186                 [GDBM="$GDBM -ldb3"
187                 DATABASE=database_sleepycat.c
188                 with_gdbm=no], [AC_CHECK_LIB(db, db_env_create,
189                                         [GDBM="$GDBM -ldb"
190                                         DATABASE=database_sleepycat.c
191                                         with_gdbm=no], [], [$NETLIBS])], [$NETLIBS])
192 fi
193
194 if test "x$with_gdbm" != xno -a "x$with_db" != xyes; then
195         AC_CHECK_LIB(gdbm, gdbm_open,
196                 [GDBM="$GDBM -lgdbm"
197                 DATABASE=database.c
198                 with_db=no])
199 fi
200
201 test -f /usr/local/lib/libresolv.a && LDFLAGS="$LDFLAGS -L/usr/local/lib"
202 AC_CHECK_LIB(resolv, res_query, RESOLV="$RESOLV -lresolv")
203
204 save_LIBS=$LIBS
205 LIBS=$CURSES
206 AC_SEARCH_LIBS(tgetent, [curses termcap])
207 AC_SEARCH_LIBS(initscr, [curses ncurses])
208 CURSES=$LIBS
209 LIBS=$save_LIBS
210
211 dnl Check for libpthread(s) if we're not using Digital UNIX or FreeBSD. (On
212 dnl which the -pthread flag takes care of this.)
213 if test "$check_pthread" != no; then
214         AC_CHECK_LIB(pthread, pthread_create,
215                 PTHREAD_LIBS="-lpthread $PTHREAD_LIBS")
216         AC_CHECK_LIB(pthreads, pthread_create,
217                 PTHREAD_LIBS="-lpthreads $PTHREAD_LIBS")
218 fi
219
220 dnl Checks for header files.
221 AC_HEADER_DIRENT
222 AC_HEADER_STDC
223 AC_HEADER_SYS_WAIT
224
225 test "$db_dir" && CPPFLAGS="$CPPFLAGS -I$db_dir/include" || \
226         ( test -d /usr/include/db3 && CPPFLAGS="$CPPFLAGS -I/usr/include/db3" ) || \
227         ( test -d /usr/local/include/db3 && CPPFLAGS="$CPPFLAGS -I/usr/local/include/db3" )
228
229 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)
230
231 AC_CHECK_HEADER(resolv.h, [SMTP=modules/libsmtp.la; DOMAIN=domain.c])
232 AC_SUBST(SMTP)
233 AC_SUBST(DOMAIN)
234
235 dnl some systems require -pthread, -D_REENTRANT, etc to be passed to cc if we
236 dnl include pthread.h:
237 save_CPPFLAGS=$CPPFLAGS
238 CPPFLAGS="$CPPFLAGS $PTHREAD_DEFS"
239 AC_CHECK_HEADERS(pthread.h)
240 CPPFLAGS=$save_CPPFLAGS
241
242 dnl Checks for typedefs, structures, and compiler characteristics.
243 AC_C_CONST
244 AC_TYPE_PID_T
245 AC_TYPE_SIZE_T
246 AC_HEADER_TIME
247 AC_STRUCT_TM
248
249 dnl Check the size of various builtin types; see typesize.h (error)
250 AC_CHECK_SIZEOF(char, 0)
251 AC_CHECK_SIZEOF(short, 0)
252 AC_CHECK_SIZEOF(int, 0)
253 AC_CHECK_SIZEOF(long, 0)
254 dnl AC_CHECK_SIZEOF(long long, 0)
255
256 AC_CACHE_CHECK([for ut_type in struct utmp], ac_cv_struct_ut_type,
257 [AC_TRY_COMPILE([#include <sys/types.h>
258 #include <utmp.h>], [struct utmp ut; ut.ut_type;],
259 ac_cv_struct_ut_type=yes, ac_cv_struct_ut_type=no)])
260 if test $ac_cv_struct_ut_type = yes; then
261         AC_DEFINE(HAVE_UT_TYPE)
262 fi
263
264 AC_CACHE_CHECK([for ut_host in struct utmp], ac_cv_struct_ut_host,
265 [AC_TRY_COMPILE([#include <sys/types.h>
266 #include <utmp.h>], [struct utmp ut; ut.ut_host;],
267 ac_cv_struct_ut_host=yes, ac_cv_struct_ut_host=no)])
268 if test $ac_cv_struct_ut_host = yes; then
269         AC_DEFINE(HAVE_UT_HOST)
270 fi
271
272 dnl Checks for library functions.
273 AC_FUNC_GETPGRP
274 AC_PROG_GCC_TRADITIONAL
275 AC_TYPE_SIGNAL
276 AC_FUNC_VPRINTF
277 AC_CHECK_FUNCS(getspnam getutxline mkdir mkfifo mktime rmdir select socket strerror strcasecmp strncasecmp)
278
279 dnl Now check for pthreads -- set up variables so that the compiler will be run
280 dnl with proper flags for pthread programs
281 save_LIBS=$LIBS
282 LIBS="$PTHREAD_LIBS $LIBS"
283
284 dnl On some platforms, AC_CHECK_FUNC[S] doesn't work for pthreads programs;
285 dnl we need to include pthread.h
286
287 AC_CACHE_CHECK([for pthread_cancel], ac_cv_func_pthread_cancel,
288 [AC_TRY_LINK([#include <pthread.h>],
289 [       pthread_t thread;
290
291         /* The GNU C library defines this for functions which it implements
292            to always fail with ENOSYS.  Some functions are actually named
293            something starting with __ and the normal name is an alias.  */
294 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
295         choke me
296 #else
297         pthread_cancel(thread);
298 #endif],
299 ac_cv_func_pthread_cancel=yes, ac_cv_func_pthread_cancel=no)])
300 if test "$ac_cv_func_pthread_cancel" = yes; then
301         AC_DEFINE(HAVE_PTHREAD_CANCEL)
302 fi
303
304 AC_CACHE_CHECK([for pthread_create], ac_cv_func_pthread_create,
305 [AC_TRY_LINK([#include <pthread.h>],
306 [       /* The GNU C library defines this for functions which it implements
307            to always fail with ENOSYS.  Some functions are actually named
308            something starting with __ and the normal name is an alias.  */
309 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
310         choke me
311 #else
312         pthread_create(NULL, NULL, NULL, NULL);
313 #endif],
314 ac_cv_func_pthread_create=yes, ac_cv_func_pthread_create=no)])
315 if test "$ac_cv_func_pthread_create" = yes; then
316         test "$DATABASE" && TARGETS="client server utils serv_modules"
317         if test "x$enable_threaded_client" != xno; then
318                 AC_DEFINE(THREADED_CLIENT)
319                 CLIENT_PTLIBS=$PTHREAD_LIBS
320                 CL_LIBOBJS='$(LIBOBJS:.o=.ro)'
321                 CX=.ro
322         fi
323 fi
324
325 if test "x$CX" != x.ro; then
326         CL_LIBOBJS='$(LIBOBJS)'
327         CX=.o
328 fi
329
330 dnl Now restore the old libs so we don't pass the wrong stuff to makefile
331 LIBS=$save_LIBS
332
333 AC_REPLACE_FUNCS(snprintf getutline)
334
335 dnl Done! Now write the Makefile and sysdep.h
336 AC_SUBST(AUTH)
337 AC_SUBST(CHKPWD)
338 AC_SUBST(CURSES)
339 AC_SUBST(GDBM)
340 AC_SUBST(RESOLV)
341 AC_SUBST(NETLIBS)
342 AC_SUBST(chkpwd_LIBS)
343 AC_SUBST(TARGETS)
344 AC_SUBST(PTHREAD_DEFS)
345 AC_SUBST(PTHREAD_LIBS)
346 AC_SUBST(CLIENT_PTLIBS)
347 AC_SUBST(CL_LIBOBJS)
348 AC_SUBST(CX)
349 AC_SUBST(DATABASE)
350 AC_CONFIG_HEADER(sysdep.h)
351 AC_CONFIG_FILES([Makefile weekly])
352 AC_OUTPUT
353
354 if test -z "$DATABASE"; then
355         AC_MSG_WARN([No database driver was found. Please install Berkeley DB.])
356 fi