* Makefile.in: generate parsedate.c automatically
[citadel.git] / citadel / configure.in
1 dnl Process this file with autoconf to produce a configure script.
2 dnl $Id$
3 AC_PREREQ(2.13)
4 AC_INIT(citserver.c)
5 AC_PREFIX_DEFAULT(/usr/local/citadel)
6 if test "$prefix" = NONE; then
7         AC_DEFINE_UNQUOTED(BBSDIR, "$ac_default_prefix")
8 else
9         AC_DEFINE_UNQUOTED(BBSDIR, "$prefix")
10 fi
11
12 AC_ARG_ENABLE(autologin, [  --disable-autologin     disable autologin (default is enabled if possible)])
13 AC_ARG_ENABLE(chkpwd, [  --disable-chkpwd        don't build 'chkpwd'])
14
15 AC_ARG_ENABLE(icq,             [  --enable-icq            include server ICQ support], [
16         if test "x$enableval" = xyes; then
17                 SERV_ICQ='modules/serv_icq$(SO)'
18         fi])
19 AC_ARG_ENABLE(threaded-client, [  --disable-threaded-client
20                           disable multithreaded client])
21
22 AC_ARG_WITH(pam, [  --with-pam              use PAM if present (see PAM.txt before you try this)])
23 AC_ARG_WITH(kthread, [  --with-kthread          use kernel threads (on FreeBSD) (not recommended yet)])
24
25 dnl By default, we only build the client (citadel and whobbs) unless we can
26 dnl figure out how to build with POSIX threads.
27 TARGETS=client
28
29 AC_CANONICAL_HOST
30 SO=.so
31 PTHREAD_DEFS=-D_REENTRANT
32 LINK_SHARED='$(CC) -shared'
33 case "$host" in
34         dnl BSDI 3.0 wants relocatable object modules instead of shared libs
35         dnl for dlopen(), and has a wrapper script to link with shared libs.
36         dnl Also has stupid non-reentrant gethostbyaddr() and friends.
37         *-*-bsdi[123]*)
38                 test -z "$CC" -a -x /usr/bin/shlicc2 && CC=shlicc2
39                 SO=.mo
40                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
41         ;;
42         *-*-bsdi*)
43                 AC_DEFINE(HAVE_NONREENTRANT_NETDB)
44         ;;
45         dnl Digital Unix has an odd way to build for pthreads, and we can't
46         dnl build pthreads programs with gcc due to header problems.
47         alpha*-dec-osf*)
48                 test -z "$CC" && CC=cc
49                 PTHREAD_DEFS=-pthread
50                 PTHREAD_LIBS=-pthread
51                 check_pthread=no
52         ;;
53         dnl FreeBSD is similar to Digital UNIX:
54         *-*-freebsd*)
55                 if test "$with_kthread" = yes; then
56                         PTHREAD_LIBS=-kthread
57                 else
58                         PTHREAD_LIBS=-pthread
59                 fi
60                 check_pthread=no
61                 PTHREAD_DEFS=-D_THREAD_SAFE
62         ;;
63         *-*-openbsd*)
64                 PTHREAD_LIBS=-pthread
65                 check_pthread=no
66                 PTHREAD_DEFS=-pthread
67                 LINK_SHARED="ld -x -Bshareable"
68         ;;
69         *-*-solaris*)
70                 PTHREAD_DEFS="-D_REENTRANT -D_PTHREADS"
71         ;;
72 esac
73
74 dnl Checks for programs.
75 AC_PROG_CC
76
77 dnl Set up system-dependent compiler flags.
78 if test "$GCC" = yes; then
79         case "$host" in
80                 *-*-bsdi[123]*)
81                         CFLAGS="$CFLAGS -Wall -Wstrict-prototypes"
82                 ;;
83                 mips*-sgi-irix*)
84                         CFLAGS="$CFLAGS -Wall -Wstrict-prototypes"
85                         PICFLAGS=-fPIC
86                 ;;
87                 *-*-solaris*)
88                         CFLAGS="$CFLAGS -Wall -Wno-char-subscripts"
89                         PICFLAGS=-fPIC
90                 ;;
91                 *)
92                         CFLAGS="$CFLAGS -Wall -Wstrict-prototypes"
93                         SERVER_LDFLAGS="$SERVER_LDFLAGS -rdynamic"
94                         PICFLAGS=-fPIC
95                 ;;
96         esac
97 fi
98 AC_PROG_RANLIB
99 AC_PROG_INSTALL
100 AC_PROG_YACC
101 missing_dir=`cd $ac_aux_dir && pwd`
102 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
103
104 dnl Checks for system services.
105 AC_EXEEXT
106
107 dnl Checks for libraries.
108
109 dnl libdl, libgdbm, and libcrypt are only used in the server, so the
110 dnl Makefile only passes $(LIBS) to that target. If other programs start
111 dnl requiring additional libraries, we'll have to use other variables, as is
112 dnl done with curses.
113
114 dnl We want to test for the following in libc before checking for their
115 dnl respective libraries, because some systems (like Irix) have both, and the
116 dnl non-libc versions may be broken.
117 AC_CHECK_FUNCS(crypt dlopen gethostbyname connect)
118
119 if test "$ac_cv_func_gethostbyname" = no; then
120         AC_CHECK_LIB(nsl, gethostbyname, NETLIBS="-lnsl $NETLIBS")
121 fi
122
123 if test "$ac_cv_func_connect" = no; then
124         AC_CHECK_LIB(socket, connect, NETLIBS="-lsocket $NETLIBS",, $NETLIBS)
125 fi
126
127 if test "$ac_cv_func_dlopen" = no; then
128         AC_CHECK_LIB(dl, dlopen, [LIBS="-ldl $LIBS"
129                 test "$with_pam" = yes && chkpwd_LIBS="-ldl $chkpwd_LIBS"])
130 fi
131
132 dnl Determine the system's authentication capabilities, if autologin is
133 dnl requested. We currently support PAM, standard getpwnam(), and getspnam()
134 dnl (Linux shadow passwords)
135 if test "$enable_autologin" != no; then
136         if test "$with_pam" = yes; then
137                 save_LIBS=$LIBS
138                 AC_CHECK_LIB(pam, pam_start, [chkpwd_LIBS="-lpam $chkpwd_LIBS"
139                         LIBS="-lpam $LIBS"])
140                 AC_CHECK_FUNCS(pam_start)
141                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
142         fi
143         if test "$ac_cv_func_pam_start" = no -o "$with_pam" != yes; then
144                 save_LIBS=$LIBS
145                 AC_SEARCH_LIBS(getspnam, shadow, [
146                         if test "$ac_cv_search_getspnam" = -lshadow; then
147                                 chkpwd_LIBS="-lshadow $chkpwd_LIBS"
148                         fi])
149                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
150                 if test "$ac_cv_func_crypt" = no; then
151                         AC_CHECK_LIB(crypt, crypt, [
152                                 chkpwd_LIBS="-lcrypt $chkpwd_LIBS"
153                                 test "$enable_chkpwd" = no && \
154                                         LIBS="-lcrypt $LIBS"])
155                 fi
156         fi
157         if test "$ac_cv_func_crypt" = yes -o "$ac_cv_lib_crypt_crypt" = yes -o "$ac_cv_func_pam_start" = yes; then
158                 AC_DEFINE(ENABLE_AUTOLOGIN)
159                 if test "$enable_chkpwd" != no; then
160                         AC_DEFINE(ENABLE_CHKPWD)
161                         CHKPWD=chkpwd
162                 else
163                         AUTH=auth.ro
164                 fi
165         fi
166 fi
167
168 test -f /usr/local/lib/libgdbm.a && LDFLAGS="$LDFLAGS -L/usr/local/lib"
169 AC_CHECK_LIB(gdbm, gdbm_open, GDBM="$GDBM -lgdbm")
170
171 test -f /usr/local/lib/libresolv.a && LDFLAGS="$LDFLAGS -L/usr/local/lib"
172 AC_CHECK_LIB(resolv, res_query, RESOLV="$RESOLV -lresolv")
173
174 save_LIBS=$LIBS
175 LIBS=$CURSES
176 AC_SEARCH_LIBS(tgetent, [curses termcap])
177 AC_SEARCH_LIBS(initscr, [curses ncurses])
178 CURSES=$LIBS
179 LIBS=$save_LIBS
180
181 dnl Check for libpthread(s) if we're not using Digital UNIX or FreeBSD. (On
182 dnl which the -pthread flag takes care of this.)
183 if test "$check_pthread" != no; then
184         AC_CHECK_LIB(pthread, pthread_create,
185                 PTHREAD_LIBS="-lpthread $PTHREAD_LIBS")
186         AC_CHECK_LIB(pthreads, pthread_create,
187                 PTHREAD_LIBS="-lpthreads $PTHREAD_LIBS")
188 fi
189
190 dnl Checks for header files.
191 AC_HEADER_DIRENT
192 AC_HEADER_STDC
193 AC_HEADER_SYS_WAIT
194 test -f /usr/local/include/gdbm.h && CPPFLAGS="$CPPFLAGS -I/usr/local/include"
195 AC_CHECK_HEADERS(curses.h fcntl.h limits.h termios.h strings.h sys/ioctl.h sys/select.h sys/time.h syslog.h unistd.h gdbm.h utmp.h utmpx.h paths.h)
196
197 dnl some systems require -pthread, -D_REENTRANT, etc to be passed to cc if we
198 dnl include pthread.h:
199 save_CPPFLAGS=$CPPFLAGS
200 CPPFLAGS="$CPPFLAGS $PTHREAD_DEFS"
201 AC_CHECK_HEADERS(pthread.h)
202 CPPFLAGS=$save_CPPFLAGS
203
204 dnl Checks for typedefs, structures, and compiler characteristics.
205 AC_C_CONST
206 AC_TYPE_PID_T
207 AC_TYPE_SIZE_T
208 AC_HEADER_TIME
209 AC_STRUCT_TM
210
211 AC_CACHE_CHECK([for ut_type in struct utmp], ac_cv_struct_ut_type,
212 [AC_TRY_COMPILE([#include <sys/types.h>
213 #include <utmp.h>], [struct utmp ut; ut.ut_type;],
214 ac_cv_struct_ut_type=yes, ac_cv_struct_ut_type=no)])
215 if test $ac_cv_struct_ut_type = yes; then
216         AC_DEFINE(HAVE_UT_TYPE)
217 fi
218
219 AC_CACHE_CHECK([for ut_host in struct utmp], ac_cv_struct_ut_host,
220 [AC_TRY_COMPILE([#include <sys/types.h>
221 #include <utmp.h>], [struct utmp ut; ut.ut_host;],
222 ac_cv_struct_ut_host=yes, ac_cv_struct_ut_host=no)])
223 if test $ac_cv_struct_ut_host = yes; then
224         AC_DEFINE(HAVE_UT_HOST)
225 fi
226
227 dnl Checks for library functions.
228 AC_FUNC_GETPGRP
229 AC_PROG_GCC_TRADITIONAL
230 AC_TYPE_SIGNAL
231 AC_FUNC_VPRINTF
232 AC_CHECK_FUNCS(getspnam getutxline mkdir mkfifo mktime rmdir select socket strerror)
233
234 dnl Now check for pthreads -- set up variables so that the compiler will be run
235 dnl with proper flags for pthread programs
236 save_LDFLAGS=$LDFLAGS
237 LDFLAGS="$LDFLAGS $SERVER_LDFLAGS"
238 save_LIBS=$LIBS
239 LIBS="$PTHREAD_LIBS $LIBS"
240
241 dnl On some platforms, AC_CHECK_FUNC[S] doesn't work for pthreads programs;
242 dnl we need to include pthread.h
243 dnl AC_CHECK_FUNCS(pthread_cancel)
244
245 AC_CACHE_CHECK([for pthread_cancel], ac_cv_func_pthread_cancel,
246 [AC_TRY_LINK([#include <pthread.h>],
247 [       pthread_t thread;
248
249         /* The GNU C library defines this for functions which it implements
250            to always fail with ENOSYS.  Some functions are actually named
251            something starting with __ and the normal name is an alias.  */
252 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
253         choke me
254 #else
255         pthread_cancel(thread);
256 #endif],
257 ac_cv_func_pthread_cancel=yes, ac_cv_func_pthread_cancel=no)])
258 if test "$ac_cv_func_pthread_cancel" = yes; then
259         AC_DEFINE(HAVE_PTHREAD_CANCEL)
260 fi
261
262 dnl AC_CHECK_FUNC(pthread_create, TARGETS="client server utils serv_modules")
263
264 AC_CACHE_CHECK([for pthread_create], ac_cv_func_pthread_create,
265 [AC_TRY_LINK([#include <pthread.h>],
266 [       /* The GNU C library defines this for functions which it implements
267            to always fail with ENOSYS.  Some functions are actually named
268            something starting with __ and the normal name is an alias.  */
269 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
270         choke me
271 #else
272         pthread_create(NULL, NULL, NULL, NULL);
273 #endif],
274 ac_cv_func_pthread_create=yes, ac_cv_func_pthread_create=no)])
275 if test "$ac_cv_func_pthread_create" = yes; then
276         TARGETS="client server utils serv_modules"
277         if test "x$enable_threaded_client" != xno; then
278                 AC_DEFINE(THREADED_CLIENT)
279                 CLIENT_PTLIBS=$PTHREAD_LIBS
280                 CL_LIBOBJS='$(LIBOBJS:.o=.ro)'
281                 CX=.ro
282         fi
283 fi
284
285 if test "x$CX" != x.ro; then
286         CL_LIBOBJS='$(LIBOBJS)'
287         CX=.o
288 fi
289
290 dnl Now restore the old ldflags so we don't pass the wrong stuff to makefile
291 LDFLAGS=$save_LDFLAGS
292 LIBS=$save_LIBS
293
294 AC_REPLACE_FUNCS(snprintf getutline)
295
296 dnl Done! Now write the Makefile and sysdep.h
297 AC_SUBST(AUTH)
298 AC_SUBST(SO)
299 AC_SUBST(CHKPWD)
300 AC_SUBST(CURSES)
301 AC_SUBST(GDBM)
302 AC_SUBST(RESOLV)
303 AC_SUBST(NETLIBS)
304 AC_SUBST(chkpwd_LIBS)
305 AC_SUBST(TARGETS)
306 AC_SUBST(SERVER_LDFLAGS)
307 AC_SUBST(SERV_ICQ)
308 AC_SUBST(PICFLAGS)
309 AC_SUBST(LINK_SHARED)
310 AC_SUBST(PTHREAD_DEFS)
311 AC_SUBST(PTHREAD_LIBS)
312 AC_SUBST(CLIENT_PTLIBS)
313 AC_SUBST(CL_LIBOBJS)
314 AC_SUBST(CX)
315 AC_CONFIG_HEADER(sysdep.h)
316 AC_OUTPUT(Makefile weekly)