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