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