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