- move to autoconf 2.52
[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 AC_CONFIG_SRCDIR([citserver.c])
6 AC_PREFIX_DEFAULT(/usr/local/citadel)
7 if test "$prefix" = NONE; then
8         AC_DEFINE_UNQUOTED(BBSDIR, "$ac_default_prefix")
9 else
10         AC_DEFINE_UNQUOTED(BBSDIR, "$prefix")
11 fi
12
13 AC_ARG_ENABLE(autologin, [  --disable-autologin     disable autologin (default is enabled if possible)])
14 AC_ARG_ENABLE(chkpwd, [  --disable-chkpwd        don't build 'chkpwd'])
15
16 AC_ARG_ENABLE(threaded-client, [  --disable-threaded-client
17                           disable multithreaded client])
18
19 AC_ARG_WITH(pam, [  --with-pam              use PAM if present (see PAM.txt before you try this)])
20 AC_ARG_WITH(kthread, [  --with-kthread          use kernel threads (on FreeBSD) (not recommended yet)])
21 AC_ARG_WITH(gdbm, [  --with-gdbm@<:@=DIR@:>@       use GDBM @<:@DIR=/usr/local@:>@])
22 AC_ARG_WITH(db, [  --with-db@<:@=DIR@:>@         use Sleepycat DB 3.x @<:@DIR=/usr/local/BerkeleyDB.3.@<:@123@:>@@:>@])
23
24 if test "x$with_gdbm" != xno -a "x$with_gdbm" != xyes -a "$with_gdbm"; then
25         db_dir="$with_gdbm"
26         with_gdbm=yes
27 else
28         test -f /usr/local/lib/libgdbm.a -o -f /usr/local/lib/libgdbm.so && db_dir=/usr/local
29 fi
30
31 if test "x$with_db" != xno -a "x$with_db" != xyes -a "$with_db"; then
32         db_dir="$with_db"
33         with_db=yes
34 else
35         test -d /usr/local/BerkeleyDB.3.1 && db_dir=/usr/local/BerkeleyDB.3.1
36         test -d /usr/local/BerkeleyDB.3.2 && db_dir=/usr/local/BerkeleyDB.3.2
37         test -d /usr/local/BerkeleyDB.3.3 && db_dir=/usr/local/BerkeleyDB.3.3
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 SO=.so
50 PTHREAD_DEFS=-D_REENTRANT
51 LINK_SHARED='$(CC) -shared -fPIC'
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                 SO=.mo
59                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
60         ;;
61         *-*-bsdi*)
62                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
63         ;;
64         dnl Digital Unix has an odd way to build for pthreads, and we can't
65         dnl build pthreads programs with gcc due to header problems.
66         alpha*-dec-osf*)
67                 test -z "$CC" && CC=cc
68                 PTHREAD_DEFS=-pthread
69                 PTHREAD_LIBS=-pthread
70                 check_pthread=no
71         ;;
72         dnl FreeBSD is similar to Digital UNIX:
73         *-*-freebsd*)
74                 if test "$with_kthread" = yes; then
75                         PTHREAD_LIBS=-kthread
76                 else
77                         PTHREAD_LIBS=-pthread
78                 fi
79                 check_pthread=no
80                 PTHREAD_DEFS=-D_THREAD_SAFE
81         ;;
82         *-*-openbsd*)
83                 PTHREAD_LIBS=-pthread
84                 check_pthread=no
85                 PTHREAD_DEFS=-pthread
86                 LINK_SHARED="ld -x -Bshareable"
87         ;;
88         *-*-solaris*)
89                 PTHREAD_DEFS="-D_REENTRANT -D_PTHREADS"
90         ;;
91 esac
92
93 dnl Checks for programs.
94 AC_PROG_CC
95
96 dnl Set up system-dependent compiler flags.
97 if test "$GCC" = yes; then
98         case "$host" in
99                 *-*-bsdi[123]*)
100                         CFLAGS="$CFLAGS -Wall -Wstrict-prototypes"
101                 ;;
102                 mips*-sgi-irix*)
103                         CFLAGS="$CFLAGS -Wall -Wstrict-prototypes"
104                         PICFLAGS=-fPIC
105                 ;;
106                 *-*-solaris*)
107                         CFLAGS="$CFLAGS -Wall -Wno-char-subscripts"
108                         PICFLAGS=-fPIC
109                 ;;
110                 *-*-hpux*)
111                         SERVER_LDFLAGS="$SERVER_LDFLAGS -Wl,-E"
112                         PICFLAGS=-fPIC
113                 ;;
114                 *)
115                         CFLAGS="$CFLAGS -Wall -Wstrict-prototypes"
116                         SERVER_LDFLAGS="$SERVER_LDFLAGS -rdynamic"
117                         PICFLAGS=-fPIC
118                 ;;
119         esac
120 fi
121 AC_PROG_RANLIB
122 AC_PROG_INSTALL
123 AC_PROG_YACC
124 missing_dir=`cd $ac_aux_dir && pwd`
125 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
126
127 dnl Checks for system services.
128 AC_EXEEXT
129
130 dnl Checks for libraries.
131
132 dnl libdl, libgdbm, and libcrypt are only used in the server, so the
133 dnl Makefile only passes $(LIBS) to that target. If other programs start
134 dnl requiring additional libraries, we'll have to use other variables, as is
135 dnl done with curses.
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, NETLIBS="-lnsl $NETLIBS")
144 fi
145
146 if test "$ac_cv_func_connect" = no; then
147         AC_CHECK_LIB(socket, connect, NETLIBS="-lsocket $NETLIBS",, $NETLIBS)
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 dyanmic 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.ro
193                 fi
194         fi
195 fi
196
197 test "$db_dir" && LDFLAGS="$LDFLAGS -L$db_dir/lib"
198 if test "x$with_db" != xno -a "x$with_gdbm" != xyes; then
199         AC_CHECK_LIB(db, db_env_create,
200                 [GDBM="$GDBM -ldb"
201                 DATABASE=database_sleepycat.c
202                 with_gdbm=no], [], [$NETLIBS])
203 fi
204
205 if test "x$with_gdbm" != xno -a "x$with_db" != xyes; then
206         AC_CHECK_LIB(gdbm, gdbm_open,
207                 [GDBM="$GDBM -lgdbm"
208                 DATABASE=database.c
209                 with_db=no])
210 fi
211
212 test -f /usr/local/lib/libresolv.a && LDFLAGS="$LDFLAGS -L/usr/local/lib"
213 AC_CHECK_LIB(resolv, res_query, RESOLV="$RESOLV -lresolv")
214
215 save_LIBS=$LIBS
216 LIBS=$CURSES
217 AC_SEARCH_LIBS(tgetent, [curses termcap])
218 AC_SEARCH_LIBS(initscr, [curses ncurses])
219 CURSES=$LIBS
220 LIBS=$save_LIBS
221
222 dnl Check for libpthread(s) if we're not using Digital UNIX or FreeBSD. (On
223 dnl which the -pthread flag takes care of this.)
224 if test "$check_pthread" != no; then
225         AC_CHECK_LIB(pthread, pthread_create,
226                 PTHREAD_LIBS="-lpthread $PTHREAD_LIBS")
227         AC_CHECK_LIB(pthreads, pthread_create,
228                 PTHREAD_LIBS="-lpthreads $PTHREAD_LIBS")
229 fi
230
231 dnl Checks for header files.
232 AC_HEADER_DIRENT
233 AC_HEADER_STDC
234 AC_HEADER_SYS_WAIT
235 test "$db_dir" && CPPFLAGS="$CPPFLAGS -I$db_dir/include"
236 AC_CHECK_HEADERS(curses.h dl.h dlfcn.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)
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_LDFLAGS=$LDFLAGS
285 LDFLAGS="$LDFLAGS $SERVER_LDFLAGS"
286 save_LIBS=$LIBS
287 LIBS="$PTHREAD_LIBS $LIBS"
288
289 dnl On some platforms, AC_CHECK_FUNC[S] doesn't work for pthreads programs;
290 dnl we need to include pthread.h
291 dnl AC_CHECK_FUNCS(pthread_cancel)
292
293 AC_CACHE_CHECK([for pthread_cancel], ac_cv_func_pthread_cancel,
294 [AC_TRY_LINK([#include <pthread.h>],
295 [       pthread_t thread;
296
297         /* The GNU C library defines this for functions which it implements
298            to always fail with ENOSYS.  Some functions are actually named
299            something starting with __ and the normal name is an alias.  */
300 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
301         choke me
302 #else
303         pthread_cancel(thread);
304 #endif],
305 ac_cv_func_pthread_cancel=yes, ac_cv_func_pthread_cancel=no)])
306 if test "$ac_cv_func_pthread_cancel" = yes; then
307         AC_DEFINE(HAVE_PTHREAD_CANCEL)
308 fi
309
310 dnl AC_CHECK_FUNC(pthread_create, TARGETS="client server utils serv_modules")
311
312 AC_CACHE_CHECK([for pthread_create], ac_cv_func_pthread_create,
313 [AC_TRY_LINK([#include <pthread.h>],
314 [       /* The GNU C library defines this for functions which it implements
315            to always fail with ENOSYS.  Some functions are actually named
316            something starting with __ and the normal name is an alias.  */
317 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
318         choke me
319 #else
320         pthread_create(NULL, NULL, NULL, NULL);
321 #endif],
322 ac_cv_func_pthread_create=yes, ac_cv_func_pthread_create=no)])
323 if test "$ac_cv_func_pthread_create" = yes; then
324         TARGETS="client server utils serv_modules"
325         if test "x$enable_threaded_client" != xno; then
326                 AC_DEFINE(THREADED_CLIENT)
327                 CLIENT_PTLIBS=$PTHREAD_LIBS
328                 CL_LIBOBJS='$(LIBOBJS:.o=.ro)'
329                 CX=.ro
330         fi
331 fi
332
333 if test "x$CX" != x.ro; then
334         CL_LIBOBJS='$(LIBOBJS)'
335         CX=.o
336 fi
337
338 dnl Now restore the old ldflags so we don't pass the wrong stuff to makefile
339 LDFLAGS=$save_LDFLAGS
340 LIBS=$save_LIBS
341
342 AC_REPLACE_FUNCS(snprintf getutline)
343
344 dnl Done! Now write the Makefile and sysdep.h
345 AC_SUBST(AUTH)
346 AC_SUBST(SO)
347 AC_SUBST(CHKPWD)
348 AC_SUBST(CURSES)
349 AC_SUBST(GDBM)
350 AC_SUBST(RESOLV)
351 AC_SUBST(NETLIBS)
352 AC_SUBST(chkpwd_LIBS)
353 AC_SUBST(TARGETS)
354 AC_SUBST(SERVER_LDFLAGS)
355 AC_SUBST(PICFLAGS)
356 AC_SUBST(LINK_SHARED)
357 AC_SUBST(PTHREAD_DEFS)
358 AC_SUBST(PTHREAD_LIBS)
359 AC_SUBST(CLIENT_PTLIBS)
360 AC_SUBST(CL_LIBOBJS)
361 AC_SUBST(CX)
362 AC_SUBST(DATABASE)
363 AC_CONFIG_HEADER(sysdep.h)
364 AC_CONFIG_FILES([Makefile weekly])
365 AC_OUTPUT