We now look for libical/ical.h instead of ical.h, because
[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], [7.37], [http://www.citadel.org/])
5 AC_REVISION([$Revision: 5108 $])
6 AC_CONFIG_SRCDIR([citserver.c])
7 AC_PREFIX_DEFAULT(/usr/local/citadel)
8 if test "$prefix" = NONE; then
9         AC_DEFINE_UNQUOTED(CTDLDIR, "$ac_default_prefix", [define this to the Citadel home directory])
10         ssl_dir="$ac_default_prefix/keys"
11 else
12         AC_DEFINE_UNQUOTED(CTDLDIR, "$prefix", [define this to the Citadel home directory])
13         ssl_dir="$prefix/keys"
14 fi
15
16 dnl Make sure we see all GNU and Solaris extensions.
17 AC_GNU_SOURCE
18
19
20 dnl Checks for the Datadir
21 AC_ARG_WITH(datadir, 
22                     [  --with-datadir          directory to store the databases under],
23                         [ if test "x$withval" != "xno" ; then
24                                               AC_DEFINE(HAVE_DATA_DIR,[],[use alternate database location?])
25                                               AC_DEFINE_UNQUOTED(DATA_DIR, "$withval",[define, if the user suplied a data-directory to use.])
26                                               MAKE_DATA_DIR=$withval
27                                               AC_SUBST(MAKE_DATA_DIR)
28                           fi
29                         ]
30 )
31
32 dnl Checks for the Datadir
33 AC_ARG_WITH(staticdatadir, 
34                     [  --with-staticdatadir    directory to store citadels system messages under],
35                         [ if test "x$withval" != "xno" ; then
36                                                   AC_DEFINE(HAVE_STATICDATA_DIR, [], [should we activate an alternate static text location?])
37                                                   AC_DEFINE_UNQUOTED(STATICDATA_DIR, "$withval", [where do we put our static text data?])
38                                                   MAKE_STATICDATA_DIR=$withval
39                                                   AC_SUBST(MAKE_STATICDATA_DIR)
40                           fi
41                         ]
42 )
43
44
45 dnl Checks for the SSLdir
46 dnl this is a bit different than the rest, 
47 dnl because of the citadel used to have a keys/ subdir.
48 AC_ARG_WITH(ssldir, 
49                     [  --with-ssldir           directory to store the ssl certificates under],
50                         [ if test "x$withval" != "xno" ; then
51                                               
52                                                   ssl_dir="$withval"
53                           fi
54                         AC_SUBST(MAKE_SSL_DIR)
55                         ]
56 )
57 AC_DEFINE_UNQUOTED(SSL_DIR, "$ssl_dir", [were should we put our keys?])
58
59
60 dnl Checks for the spooldir
61 AC_ARG_WITH(spooldir, 
62                         [  --with-spooldir         directory to keep queues under],
63                         [ if test "x$withval" != "xno" ; then
64                                                 AC_DEFINE(HAVE_SPOOL_DIR, [], [enable alternate spool dir?])
65                                                 AC_DEFINE_UNQUOTED(SPOOL_DIR,"$withval", [where do we place our spool dirs?])
66                                                 MAKE_SPOOL_DIR=$withval
67                                                 AC_SUBST(MAKE_SPOOL_DIR)
68                            fi
69                         ]
70 )
71
72
73 dnl Checks for the Configdir
74 AC_ARG_WITH(sysconfdir, 
75                         [  --with-sysconfdir       directory to store the configs under],
76                         [ if test "x$withval" != "xno" ; then
77                                             AC_DEFINE(HAVE_ETC_DIR, [], [should we search our system config in an alternate place?])
78                                                 AC_DEFINE_UNQUOTED(ETC_DIR, "$withval", [where to search our config files])
79                                                 MAKE_ETC_DIR=$withval
80                                                 AC_SUBST(MAKE_ETC_DIR)
81                           fi
82                         ]
83 )
84
85 dnl Checks for where to put our utilities
86 AC_ARG_WITH(utility-bindir, 
87                         [  --with-utility-bindir   directory where to find helper binaries],
88                         [ if test "x$withval" != "xno" ; then
89                                             AC_DEFINE(HAVE_UTILBIN_DIR,[],[should we put our helper binaries to another location?])
90                                                 AC_DEFINE_UNQUOTED(UTILBIN_DIR, "$withval", [were to put our helper programs])
91                                                 MAKE_UTILBIN_DIR=$withval
92                                                 AC_SUBST(MAKE_UTILBIN_DIR)
93                           fi
94                         ]
95 )
96
97
98 dnl Checks for the run-dir for the sockets
99 AC_ARG_WITH(rundir, 
100                         [  --with-rundir           directory to place runtime files (UDS) to?],
101                         [ if test "x$withval" != "xno" ; then
102                                             AC_DEFINE(HAVE_RUN_DIR, [], [should we put our non volatile files elsewhere?])
103                                                 AC_DEFINE_UNQUOTED(RUN_DIR, "$withval", [define, where the config should go in unix style])
104                                                 MAKE_RUN_DIR=$withval
105                                                 AC_SUBST(MAKE_RUN_DIR)
106                           fi
107                         ]
108 )
109
110
111 dnl Checks for the Pseudo Random Generator sockets TODO: this keeps being default.
112 AC_DEFINE_UNQUOTED(EGD_POOL, "/var/run/egd-pool", [place to keep our pseudo random generator file])
113 AC_ARG_WITH(egdpool, 
114                         [  --with-egdpool          the socket from Pseudo Random Generator, defaults to /var/run/egd-pool],
115                         [ if test "x$withval" != "xno" ; then
116                                                 AC_DEFINE_UNQUOTED(EGD_POOL, "$withval", [the socket from Pseudo Random Generator])
117                           fi
118                         ]
119 )
120
121
122 AC_ARG_WITH(docdir,
123                         [  --with-docdir           where to install the documentation. default: /usr/local/citadel/],
124                         [ if test "x$withval" != "xno" ; then
125                                         MAKE_DOC_DIR=$withval
126                                         AC_SUBST(MAKE_DOC_DIR)
127                           fi
128                         ]
129 )
130
131
132 dnl Here is the check for a libc integrated iconv
133 AC_ARG_ENABLE(iconv,
134         [  --disable-iconv         do not use iconv charset conversion],
135         ok_iconv=no, ok_iconv=yes)
136
137 AC_MSG_CHECKING(Checking to see if your system supports iconv)
138 AC_TRY_RUN([
139         #include <iconv.h>
140         main() {
141                 iconv_t ic = (iconv_t)(-1) ;
142                 ic = iconv_open("UTF-8", "us-ascii");
143                 iconv_close(ic);
144                 exit(0);
145         }
146  ],
147                 [
148                   ok_iconv=yes
149                   AC_MSG_RESULT([yes])
150                 ],
151                 [ 
152                   ok_iconv=no
153                   AC_MSG_RESULT([no])
154                 ]
155 )
156
157 dnl Check for iconv in external libiconv
158 if test "$ok_iconv" = no; then
159         AC_MSG_CHECKING(Checking for an external libiconv)
160         OLD_LDFLAGS="$LDFLAGS"
161         LDFLAGS="$LDFLAGS -liconv"
162         AC_TRY_RUN([
163                         #include <iconv.h>
164                         main() {
165                                 iconv_t ic = (iconv_t)(-1) ;
166                                 ic = iconv_open("UTF-8", "us-ascii");
167                                 iconv_close(ic);
168                         }
169                 ],
170                         [
171                           ok_iconv=yes
172                           AC_MSG_RESULT([yes])
173                         ],
174                         [ 
175                           ok_iconv=no
176                           LDFLAGS="$OLD_LDFLAGS"
177                           AC_MSG_RESULT([no])
178                         ]
179                 )
180 fi      
181 if test "$ok_iconv" != "no"; then
182         AC_MSG_RESULT(WebCit will be built with character set conversion.)
183         AC_DEFINE(HAVE_ICONV,[],[whether we have iconv for charset conversion])
184 else
185         AC_MSG_RESULT(WebCit will be built without character set conversion.)
186 fi
187
188 AC_CHECK_LIB(intl, libintl_bindtextdomain, [LDFLAGS="$LDFLAGS -lintl"])
189
190
191
192 AC_ARG_ENABLE(threaded-client, [  --disable-threaded-client
193                           disable multithreaded client])
194
195 AC_ARG_ENABLE(pie, [  --enable-pie            build position-independent executables])
196
197 AC_ARG_WITH(pam, [  --with-pam              use PAM if present (see PAM.txt before you try this)])
198 AC_ARG_WITH(kthread, [  --with-kthread          use kernel threads (on FreeBSD) (not recommended yet)])
199 AC_ARG_WITH(db, [  --with-db@<:@=DIR@:>@         use Berkeley DB 3.x @<:@DIR=/usr/local/BerkeleyDB.3.@<:@123@:>@@:>@])
200 AC_ARG_WITH(ssl,
201         [  --with-ssl=PATH         Specify path to OpenSSL installation ],
202         [
203                 if test "x$withval" != "xno" ; then
204                         tryssldir=$withval
205                 fi
206         ]
207 )
208 AC_ARG_WITH(ncurses, [  --without-ncurses       don't use ncurses])
209
210 AC_ARG_WITH(with_zlib, [  --with-zlib             use zlib compression if present])
211 AC_ARG_WITH(with_ldap, [  --with-ldap             use OpenLDAP client library])
212 AC_ARG_WITH(with_libdspam, [  --with-libdspam         use libdspam mail spam scanning library])
213
214 if test "x$with_db" != xno -a "x$with_db" != xyes -a "$with_db"; then
215         db_dir="$with_db"
216         with_db=yes
217 else
218         test -f /usr/local/lib/libdb.a -o -f /usr/local/lib/libdb.so \
219           -o -f /usr/local/lib/libdb4.a -o -f /usr/local/lib/libdb4.so \
220           && db_dir=/usr/local
221
222         test -d /usr/local/BerkeleyDB.4.1 && db_dir=/usr/local/BerkeleyDB.4.1
223         test -d /usr/local/BerkeleyDB.4.2 && db_dir=/usr/local/BerkeleyDB.4.2
224         test -d /usr/local/BerkeleyDB.4.3 && db_dir=/usr/local/BerkeleyDB.4.3
225         test -d /usr/local/BerkeleyDB.4.4 && db_dir=/usr/local/BerkeleyDB.4.4
226         test -d /usr/local/BerkeleyDB.4.5 && db_dir=/usr/local/BerkeleyDB.4.5
227 fi
228
229 dnl By default, we only build the client (citadel and whobbs) unless we can
230 dnl figure out how to build with POSIX threads.
231 TARGETS=client
232
233 AC_CANONICAL_HOST
234 PTHREAD_DEFS=-D_REENTRANT
235 AC_MSG_CHECKING([how to compile with POSIX threads])
236 case "$host" in
237         dnl BSDI 3.0 wants relocatable object modules instead of shared libs
238         dnl for dlopen(), and has a wrapper script to link with shared libs.
239         dnl Also has stupid non-reentrant gethostbyaddr() and friends.
240         *-*-bsdi[123]*)
241                 test -z "$CC" -a -x /usr/bin/shlicc2 && CC=shlicc2
242                 AC_DEFINE(HAVE_NONREENTRANT_NETDB,[], [define this if the OS has broken non-reentrant gethostby{name,addr}() ])
243                 AC_MSG_RESULT([Old BSDI])
244         ;;
245         *-*-bsdi*)
246                 AC_DEFINE(HAVE_NONREENTRANT_NETDB, [], [define this if the OS has broken non-reentrant gethostby{name,addr}() ])
247                 AC_MSG_RESULT([BSD/OS])
248         ;;
249         dnl Curses support on Mac OS X is kind of screwed at the moment.
250         dnl TCP buffering isn't ideal under OS X. This define should also be
251         dnl checked in other cases of OS X-Linux differences.
252         *-*-darwin*)
253                 AC_DEFINE(DISABLE_CURSES,[],[define this to disable use of curses])
254                 AC_DEFINE(HAVE_DARWIN, [], [define if using OS X/Darwin])
255                 AC_MSG_RESULT([Mac OS X])
256         ;;
257         dnl Digital Unix has an odd way to build for pthreads, and we can't
258         dnl build pthreads programs with gcc due to header problems.
259         alpha*-dec-osf*)
260                 test -z "$CC" && CC=cc
261                 LIBS="-lpthread -lexc $LIBS"
262                 check_pthread=no
263                 AC_MSG_RESULT([Tru64 or Digital UNIX])
264         ;;
265         dnl FreeBSD is similar to Digital UNIX with DEC C, which has a -pthread flag:
266         *-*-freebsd*)
267                 if test "$with_kthread" = yes; then
268                         LIBS="-kthread $LIBS"
269                 else
270                         LIBS="-pthread $LIBS"
271                 fi
272                 check_pthread=no
273                 PTHREAD_DEFS=-D_THREAD_SAFE
274                 AC_MSG_RESULT([FreeBSD])
275         ;;
276         *-*-openbsd*)
277                 LIBS="-pthread $LIBS"
278                 check_pthread=no
279                 PTHREAD_DEFS=-pthread
280                 AC_MSG_RESULT([OpenBSD])
281         ;;
282         *-*-linux*)
283                 PTHREAD_DEFS="-D_REENTRANT -pthread"
284                 AC_MSG_RESULT([Linux])
285         ;;
286         *-*-solaris*)
287                 PTHREAD_DEFS="-D_REENTRANT -D_PTHREADS"
288                 AC_MSG_RESULT([Solaris])
289         ;;
290         *-*-cygwin*)
291                 SERVER_LDFLAGS="-Wl,-subsystem,windows"
292                 AC_MSG_RESULT([Cygwin])
293         ;;
294         *)
295                 AC_MSG_RESULT([default])
296         ;;
297 esac
298 dnl DEFS="$DEFS $PTHREAD_DEFS"
299
300
301 dnl Checks for programs.
302 AC_PROG_CC
303
304
305
306 dnl Set up system-dependent compiler flags.
307 if test "$GCC" = yes; then
308         if test "$CC" = icc; then
309                 CFLAGS="$CFLAGS -w1"
310         else
311                 case "$host" in
312                         *-*-solaris*|alpha*-dec-osf*)
313                                 CFLAGS="$CFLAGS -Wall -Wcast-qual -Wcast-align -Wno-char-subscripts $PTHREAD_DEFS"
314                         ;;
315                         *)
316                         CFLAGS="$CFLAGS -Wall -Wcast-qual -Wcast-align -Wstrict-prototypes $PTHREAD_DEFS"
317                         ;;
318                 esac
319         fi
320 fi
321
322 if test "x$enable_pie" = xyes; then
323         save_CFLAGS="$CFLAGS"
324         save_LDFLAGS="$LDFLAGS"
325         CFLAGS="$CFLAGS -fpie"
326         LDFLAGS="$LDFLAGS -pie -fpie"
327         AC_CACHE_CHECK([whether compiler accepts -pie -fpie], ac_cv_pie_fpie,
328         [AC_TRY_LINK([], [],
329         ac_cv_pie_fpie=yes, ac_cv_pie_fpie=no)])
330         if test $ac_cv_pie_fpie = no; then
331                 CFLAGS="$save_CFLAGS"
332                 LDFLAGS="$save_LDFLAGS"
333         fi
334 fi
335
336 AC_MSG_CHECKING([how to create dependancy checks])
337                  if test -n "`$CC -V 2>&1 |grep Sun`"; then 
338                         DEPEND_FLAG=-xM;
339                  else 
340                         DEPEND_FLAG=-M
341                  fi
342 AC_SUBST(DEPEND_FLAG)
343
344
345 AC_PROG_INSTALL
346 AC_PROG_YACC
347 missing_dir=`cd $ac_aux_dir && pwd`
348 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
349 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
350
351 dnl Checks for system services.
352
353 dnl Check the size of various builtin types; see typesize.h (error)
354 AC_CHECK_SIZEOF(char, 0)
355 AC_CHECK_SIZEOF(short, 0)
356 AC_CHECK_SIZEOF(int, 0)
357 AC_CHECK_SIZEOF(long, 0)
358 AC_CHECK_SIZEOF(size_t, 0)
359 dnl AC_CHECK_SIZEOF(long long, 0)
360
361 dnl Checks for libraries.
362
363 dnl We want to test for the following in libc before checking for their
364 dnl respective libraries, because some systems (like Irix) have both, and the
365 dnl non-libc versions may be broken.
366 AC_CHECK_FUNCS(crypt gethostbyname connect flock getpwnam_r getpwuid_r)
367
368
369 dnl disable backtrace if we don't want it.
370 AC_ARG_WITH(backtrace, 
371                     [  --with-backtrace        enable backtrace dumps in the syslog],
372                         [ if test "x$withval" != "xno" ; then
373                              CFLAGS="$CFLAGS  -rdynamic "
374                              LDFLAGS="$LDFLAGS  -rdynamic "
375                              SERVER_LDFLAGS="$SERVER_LDFLAGS  -rdynamic "
376                              AC_CHECK_FUNCS(backtrace)
377                           fi
378                         ]
379 )
380
381 dnl disable backtrace if we don't want it.
382 AC_ARG_WITH(gprof, 
383                     [  --with-gprof            enable profiling],
384                         [ if test "x$withval" != "xno" ; then
385                              CFLAGS="$CFLAGS  -pg "
386                              LDFLAGS="$LDFLAGS  -pg "
387                              SERVER_LDFLAGS="$SERVER_LDFLAGS  -pg "
388                           fi
389                         ]
390 )
391
392 dnl disable thread table reporting
393 AC_ARG_WITH(threadlog,
394                 [  --with-threadlog        enable logging of thread table],
395                         [ if test "x$withval" != "xno" ; then
396                                 AC_DEFINE(WITH_THREADLOG, [], [Define if you want logging of the thread tables.])
397                           fi
398                         ]
399 )
400
401
402 if test "$ac_cv_func_gethostbyname" = no; then
403         AC_CHECK_LIB(nsl, gethostbyname)
404 fi
405
406 if test "$ac_cv_func_connect" = no; then
407         AC_CHECK_LIB(socket, connect)
408 fi
409
410 dnl Check for Solaris realtime support
411 AC_CHECK_LIB(rt, sched_yield)
412
413 dnl Determine the system's authentication capabilities.
414 dnl We currently support PAM, standard getpwnam(), and getspnam()
415 dnl (Linux shadow passwords)
416
417         if test "$with_pam" = yes; then
418                 save_LIBS=$LIBS
419                 AC_CHECK_LIB(pam, pam_start, [chkpwd_LIBS="-lpam $chkpwd_LIBS"
420                         LIBS="-lpam $LIBS"])
421                 AC_CHECK_FUNCS(pam_start)
422                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
423         fi
424         if test "$ac_cv_func_pam_start" = no -o "$with_pam" != yes; then
425                 save_LIBS=$LIBS
426                 AC_SEARCH_LIBS(getspnam, shadow, [
427                         if test "$ac_cv_search_getspnam" = -lshadow; then
428                                 chkpwd_LIBS="-lshadow $chkpwd_LIBS"
429                         fi])
430                 test "$enable_chkpwd" != no && LIBS=$save_LIBS
431                 if test "$ac_cv_func_crypt" = no; then
432                         AC_CHECK_LIB(crypt, crypt, [
433                                 chkpwd_LIBS="-lcrypt $chkpwd_LIBS"
434                                 test "$enable_chkpwd" = no && \
435                                         LIBS="-lcrypt $LIBS"])
436                 fi
437         fi
438
439 if test "x$with_ncurses" != "xno"; then
440         AC_SEARCH_LIBS(tgetent, [ncurses curses termcap])
441         AC_SEARCH_LIBS(scrollok, [ncurses curses])
442         AC_SEARCH_LIBS(initscr, [ncurses curses])
443 else
444         AC_SEARCH_LIBS(tgetent, [curses termcap])
445         AC_SEARCH_LIBS(initscr, [curses])
446 fi
447 AC_CHECK_FUNCS(vw_printw wcolor_set resizeterm wresize)
448
449 dnl Check for libpthread(s) if we're not using Digital UNIX or FreeBSD. (On
450 dnl which the -pthread flag takes care of this.)
451 if test "$check_pthread" != no; then
452         AC_CHECK_LIB(pthread, pthread_create)
453         AC_CHECK_LIB(pthreads, pthread_create)
454 fi
455
456 test -d /usr/kerberos/include && CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
457
458
459 dnl Check for libcitadel
460 AC_CHECK_HEADER(libcitadel.h,
461         [AC_CHECK_LIB(citadel, libcitadel_version_string,
462                 [
463                         LIBS="-lcitadel $LIBS"
464                 ],
465                 [
466                         AC_MSG_ERROR(libcitadel was not found or is not usable.  Please install libcitadel.)
467                 ]
468         ,
469         )],
470         [
471                 AC_MSG_ERROR(libcitadel.h was not found or is not usable.  Please install libcitadel.)
472         ]
473 )
474
475
476
477
478 # The big search for OpenSSL
479 if test "$with_ssl" != "no"; then
480         saved_LIBS="$LIBS"
481         saved_LDFLAGS="$LDFLAGS"
482         saved_CFLAGS="$CFLAGS"
483         if test "x$prefix" != "xNONE"; then
484                 tryssldir="$tryssldir $prefix"
485         fi
486         AC_CACHE_CHECK([for OpenSSL], ac_cv_openssldir, [
487                 for ssldir in $tryssldir "" /usr /usr/local/openssl /usr/lib/openssl /usr/local/ssl /usr/lib/ssl /usr/local /usr/pkg /opt /opt/openssl ; do
488                         CFLAGS="$saved_CFLAGS"
489                         LDFLAGS="$saved_LDFLAGS"
490                         LIBS="$saved_LIBS -lssl -lcrypto"
491         
492                         # Skip directories if they don't exist
493                         if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
494                                 continue;
495                         fi
496                         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
497                                 # Try to use $ssldir/lib if it exists, otherwise
498                                 # $ssldir
499                                 if test -d "$ssldir/lib" ; then
500                                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
501                                         if test ! -z "$need_dash_r" ; then
502                                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
503                                         fi
504                                 else
505                                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
506                                         if test ! -z "$need_dash_r" ; then
507                                                 LDFLAGS="-R$ssldir $LDFLAGS"
508                                         fi
509                                 fi
510                                 # Try to use $ssldir/include if it exists, otherwise
511                                 # $ssldir
512                                 if test -d "$ssldir/include" ; then
513                                         CFLAGS="-I$ssldir/include $saved_CFLAGS"
514                                 else
515                                         CFLAGS="-I$ssldir $saved_CFLAGS"
516                                 fi
517                         fi
518         
519                         # Basic test to check for compatible version and correct linking
520                         # *does not* test for RSA - that comes later.
521                         AC_TRY_RUN(
522                                 [
523         #include <string.h>
524         #include <openssl/rand.h>
525         int main(void)
526         {
527                 char a[2048];
528                 memset(a, 0, sizeof(a));
529                 RAND_add(a, sizeof(a), sizeof(a));
530                 return(RAND_status() <= 0);
531         }
532                                 ],
533                                 [
534                                         found_crypto=1
535                                         break;
536                                 ], []
537                         )
538         
539                         if test ! -z "$found_crypto" ; then
540                                 break;
541                         fi
542                 done
543         
544                 if test -z "$ssldir" ; then
545                         ssldir="(system)"
546                 fi
547         
548                 if test ! -z "$found_crypto" ; then
549                         ac_cv_openssldir=$ssldir
550                 else
551                         ac_cv_openssldir="no"
552                 fi
553         ])
554         LIBS="$saved_LIBS"
555         LDFLAGS="$saved_LDFLAGS"
556         CFLAGS="$saved_CFLAGS"
557         
558         if test "x$ac_cv_openssldir" != "xno" ; then
559                 AC_DEFINE(HAVE_OPENSSL, [], [Define if you have OpenSSL.])
560                 LIBS="-lssl -lcrypto $LIBS"
561                 dnl Need to recover ssldir - test above runs in subshell
562                 ssldir=$ac_cv_openssldir
563                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr" -a "x$ssldir" != "x(system)"; then
564                         # Try to use $ssldir/lib if it exists, otherwise
565                         # $ssldir
566                         if test -d "$ssldir/lib" ; then
567                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
568                                 if test ! -z "$need_dash_r" ; then
569                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
570                                 fi
571                         else
572                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
573                                 if test ! -z "$need_dash_r" ; then
574                                         LDFLAGS="-R$ssldir $LDFLAGS"
575                                 fi
576                         fi
577                         # Try to use $ssldir/include if it exists, otherwise
578                         # $ssldir
579                         if test -d "$ssldir/include" ; then
580                                 CFLAGS="-I$ssldir/include $saved_CFLAGS"
581                         else
582                                 CFLAGS="-I$ssldir $saved_CFLAGS"
583                         fi
584                 fi
585         fi
586 fi
587
588 if test "x$with_db" != xno; then
589         test "$db_dir" && LDFLAGS="$LDFLAGS -L$db_dir/lib"
590
591         dblib=""
592
593         if test -d "$db_dir/include/db4"; then
594                 CPPFLAGS="$CPPFLAGS -I$db_dir/include/db4"
595                 dblib="db4"
596         elif test "$db_dir"; then
597                 CPPFLAGS="$CPPFLAGS -I$db_dir/include"
598         elif test -d /usr/include/db4; then
599                 CPPFLAGS="$CPPFLAGS -I/usr/include/db4"
600                 dblib="db4"
601         fi
602
603
604         AC_CHECK_DB([db db-4.1 db-4 db4],
605                     [
606                      DATABASE=database.c
607                     ],
608                     AC_MSG_ERROR([[Can not locate a suitable Berkeley DB
609                                   library.  Use --with-db=PATH to specify
610                                   the path]]))
611
612 fi
613
614 dnl Checks for the zlib compression library.
615 if test "x$with_zlib" != xno ; then
616         AC_CHECK_HEADERS(zlib.h,
617                 [AC_CHECK_LIB(z, zlibVersion,
618                         [ok_zlib=yes],,
619         )])
620 fi
621
622 if test "x$ok_zlib" = xyes ; then
623         SERVER_LIBS="-lz $SERVER_LIBS"
624         AC_DEFINE(HAVE_ZLIB, [], [define this if you have zlib compression available])
625 fi
626
627
628
629
630 dnl Checks for the OpenLDAP client library.
631 if test "x$with_ldap" != xno ; then
632         AC_CHECK_HEADERS(ldap.h,
633                 [AC_CHECK_LIB(ldap, ldap_init,
634                         [ok_ldap=yes],,
635         )])
636 fi
637
638 if test "x$ok_ldap" = xyes ; then
639         SERVER_LIBS="-lldap $SERVER_LIBS"
640         AC_DEFINE(HAVE_LDAP, [], [define this if you have OpenLDAP client available])
641 fi
642
643
644
645
646
647 dnl Checks for the libdspam mail spam scanning library.
648 if test "x$with_libdspam" != xno ; then
649         AC_CHECK_HEADERS(dspam/libdspam.h,
650                 [AC_CHECK_LIB(dspam, dspam_init,
651                         [ok_libdspam=yes],,
652         )])
653 fi
654
655 if test "x$ok_libdspam" = xyes ; then
656         SERVER_LIBS="-ldspam $SERVER_LIBS"
657         AC_DEFINE(HAVE_LIBDSPAM, [], [define this if you have the libdspam mail spam scanning library available])
658 fi
659
660
661
662 dnl Checks for the Expat XML parser.
663 AC_CHECK_HEADER(expat.h,
664         [AC_CHECK_LIB(expat, XML_ParserCreateNS,
665                 [
666                         SERVER_LIBS="-lexpat $SERVER_LIBS"
667                 ],
668                 [
669                         AC_MSG_ERROR(The Expat XML parser was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
670                 ]
671         ,
672         )],
673         [
674                 AC_MSG_ERROR(expat.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
675         ]
676 )
677
678
679
680
681
682
683
684 dnl Checks for libcurl.
685 AC_CHECK_HEADER(curl/curl.h,
686         [AC_CHECK_LIB(curl, curl_version,
687                 [
688                         SERVER_LIBS="-lcurl $SERVER_LIBS"
689                 ],
690                 [
691                         AC_MSG_ERROR(libcurl was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
692                 ]
693         ,
694         )],
695         [
696                 AC_MSG_ERROR(curl/curl.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
697         ]
698 )
699
700
701
702
703
704
705
706 dnl Checks for the libical iCalendar library.
707 AC_CHECK_HEADER(libical/ical.h,
708         [AC_CHECK_LIB(ical, icalcomponent_new,
709                 [
710                         SERVER_LIBS="-lical $SERVER_LIBS"
711                 ],
712                 [
713                         AC_MSG_ERROR(libical was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
714                 ]
715         ,
716         )],
717         [
718                 AC_MSG_ERROR(libical/ical.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
719         ]
720 )
721
722
723 dnl Checks for the libsieve mailbox sorting library.
724 AC_CHECK_HEADER(sieve2.h,
725         [AC_CHECK_LIB(sieve, sieve2_license,
726                 [
727                         SERVER_LIBS="-lsieve $SERVER_LIBS"
728                 ],
729                 [
730                         AC_MSG_ERROR(libsieve was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
731                 ]
732         ,
733         )],
734         [
735                 AC_MSG_ERROR(sieve2.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
736         ]
737 )
738
739
740
741
742 dnl Checks for header files.
743 AC_HEADER_DIRENT
744 AC_HEADER_STDC
745 AC_HEADER_SYS_WAIT
746
747 dnl
748 dnl TODO: for the DB header checks, we should check whether the headers
749 dnl define db_env_create, somehow
750 dnl
751 AC_CHECK_HEADERS(curses.h dl.h fcntl.h limits.h malloc.h termios.h sys/ioctl.h sys/select.h sys/stat.h sys/time.h sys/prctl.h syslog.h unistd.h utmp.h utmpx.h paths.h db.h db4/db.h pthread.h netinet/in.h arpa/nameser.h arpa/nameser_compat.h)
752
753 dnl
754 dnl need to check if this is actually compilable, sometimes there are
755 dnl conflicts with the system's headers (eg solaris xpg4 style headers)
756 dnl
757 if test "x$with_ncurses" != xno; then
758         AC_CHECK_HEADERS(ncurses.h,,,[ ])
759 fi
760
761 AC_CHECK_HEADER(resolv.h,AC_DEFINE(HAVE_RESOLV_H, [], [define this if you have the resolv.h header file.]),,
762 [#ifdef HAVE_SYS_TYPES_H
763 #include <sys/types.h>
764 #endif
765 #ifdef HAVE_NETINET_IN_H
766 #include <netinet/in.h>
767 #endif
768 #ifdef HAVE_ARPA_NAMESER_H
769 #include <arpa/nameser.h>
770 #endif])
771
772
773 dnl Checks for typedefs, structures, and compiler characteristics.
774 AC_C_CONST
775 AC_TYPE_PID_T
776 AC_TYPE_SIZE_T
777 AC_HEADER_TIME
778
779 dnl defined in acinclude.m4:
780 CIT_STRUCT_TM
781
782 AC_CACHE_CHECK([for ut_type in struct utmp], ac_cv_struct_ut_type,
783 [AC_TRY_COMPILE([#include <sys/types.h>
784 #include <utmp.h>], [struct utmp ut; ut.ut_type;],
785 ac_cv_struct_ut_type=yes, ac_cv_struct_ut_type=no)])
786 if test $ac_cv_struct_ut_type = yes; then
787         AC_DEFINE(HAVE_UT_TYPE, [], [define this if struct utmp has an ut_type member])
788 fi
789
790 AC_CACHE_CHECK(
791         [for call semantics from getpwuid_r], 
792         ac_cv_call_getpwuid_r,
793         [AC_TRY_COMPILE([#include <sys/types.h>
794 #include <pwd.h>], 
795                          [
796                                 struct passwd pw, *pwp;
797                                 char pwbuf[64];
798                                 uid_t uid;
799
800                                 getpwuid_r(uid, &pw, pwbuf, sizeof(pwbuf), &pwp);
801                         ],
802                         ac_cv_call_getpwuid_r=yes, 
803                         ac_cv_call_getpwuid_r=no)
804         ])
805
806 if test $ac_cv_call_getpwuid_r = no; then
807         AC_DEFINE(SOLARIS_GETPWUID,[],[do we need to use solaris call syntax?])
808         AC_DEFINE(F_UID_T, "%ld", [whats the matching format string for uid_t?])
809         AC_DEFINE(F_PID_T, "%ld",  [whats the matching format string for pid_t?])
810         AC_DEFINE(F_XPID_T, "%lx",  [whats the matching format string for xpid_t?])
811 else
812         AC_DEFINE(F_UID_T, "%d",  [whats the matching format string for uid_t?])
813         AC_DEFINE(F_PID_T, "%d",  [whats the matching format string for pid_t?])
814         AC_DEFINE(F_XPID_T, "%x",  [whats the matching format string for xpid_t?])
815 fi
816
817
818 dnl Our own happy little check for the resolver library.
819
820 case "`uname -a`" in 
821  OpenBSD*)
822         echo "we don't need to check for resolv on openbsd"  
823         ;;
824  FreeBSD*)
825         echo "we don't need to check for resolv on freeBSD"  
826         ;;
827  *)
828         test -f /usr/local/lib/libresolv.a && LDFLAGS="$LDFLAGS -L/usr/local/lib"
829         AC_CHECK_LIB(resolv, res_query,
830                 RESOLV="$RESOLV -lresolv",
831                 [dnl Have to include resolv.h as res_query is sometimes defined as a macro
832                         AC_MSG_CHECKING([for res_query in -lresolv (with resolv.h if present)])
833                         saved_libs="$LIBS"
834                         LIBS="-lresolv $LIBS"
835                         AC_TRY_LINK([
836                                 #ifdef HAVE_RESOLV_H
837                                 #include <resolv.h>
838                                 #endif],
839                                 [res_query(0,0,0,0,0)],
840                                 [AC_MSG_RESULT(yes)
841                                                 have_res_query=yes],
842                                 [AC_MSG_RESULT(no)
843                                         AC_MSG_ERROR(libresolv was not found.  Citadel requires the resolver library.)
844                                 ])
845          ]
846         )
847         ;;
848 esac
849
850
851
852 AC_CACHE_CHECK([for ut_host in struct utmp], ac_cv_struct_ut_host,
853 [AC_TRY_COMPILE([#include <sys/types.h>
854 #include <utmp.h>], [struct utmp ut; ut.ut_host;],
855 ac_cv_struct_ut_host=yes, ac_cv_struct_ut_host=no)])
856 if test $ac_cv_struct_ut_host = yes; then
857         AC_DEFINE(HAVE_UT_HOST, [], [define this if struct utmp has an ut_host member])
858 fi
859
860 dnl Checks for library functions.
861 AC_FUNC_GETPGRP
862 AC_PROG_GCC_TRADITIONAL
863 AC_TYPE_SIGNAL
864 AC_FUNC_VPRINTF
865 AC_CHECK_FUNCS(getspnam getutxline mkdir mkfifo mktime rmdir select socket strerror strcasecmp strncasecmp)
866
867 dnl Now check for pthreads
868
869 dnl On some platforms, AC_CHECK_FUNC[S] doesn't work for pthreads programs;
870 dnl we need to include pthread.h
871
872 AC_CACHE_CHECK([for pthread_cancel], ac_cv_func_pthread_cancel,
873 [AC_TRY_LINK([#include <pthread.h>],
874 [       pthread_t thread;
875
876         /* The GNU C library defines this for functions which it implements
877            to always fail with ENOSYS.  Some functions are actually named
878            something starting with __ and the normal name is an alias.  */
879 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
880         choke me
881 #else
882         pthread_cancel(thread);
883 #endif],
884 ac_cv_func_pthread_cancel=yes, ac_cv_func_pthread_cancel=no)])
885 if test "$ac_cv_func_pthread_cancel" = yes; then
886         AC_DEFINE(HAVE_PTHREAD_CANCEL, [], [define this if you have the pthread_cancel() function])
887 fi
888
889 AC_CACHE_CHECK([for pthread_create], ac_cv_func_pthread_create,
890 [AC_TRY_LINK([#include <pthread.h>],
891 [       /* The GNU C library defines this for functions which it implements
892            to always fail with ENOSYS.  Some functions are actually named
893            something starting with __ and the normal name is an alias.  */
894 #if defined (__stub_pthread_cancel) || defined (__stub___pthread_cancel)
895         choke me
896 #else
897         pthread_create(NULL, NULL, NULL, NULL);
898 #endif],
899 ac_cv_func_pthread_create=yes, ac_cv_func_pthread_create=no)])
900 if test "$ac_cv_func_pthread_create" = yes; then
901         test "$DATABASE" && TARGETS="client server utils"
902         if test "x$enable_threaded_client" != xno; then
903                 AC_DEFINE(THREADED_CLIENT, [], [define this if you want to enable the multithreaded client])
904         fi
905 fi
906
907 AC_REPLACE_FUNCS(snprintf getutline)
908
909 AC_CACHE_CHECK([the weather], ac_cv_weather, [
910         sleep 1
911         echo $ECHO_N "opening your window... $ECHO_C" >&6
912         sleep 2
913         month=`date | cut -f 2 -d ' '`
914         case $month in
915         Dec | Jan | Feb)
916                 ac_cv_weather="it's cold!"
917                 ;;
918         Mar | Apr)
919                 ac_cv_weather="it's wet!"
920                 ;;
921         Jul | Aug)
922                 ac_cv_weather="it's hot!"
923                 ;;
924         Oct | Nov)
925                 ac_cv_weather="it's cool"
926                 ;;
927         May | Jun | Sep | *)
928                 ac_cv_weather="it's fine"
929                 ;;
930         esac
931         ])
932
933
934
935
936 AC_CACHE_CHECK([under the bed], ac_cv_under_the_bed, [
937         number=`date | cut -c 19`
938         case $number in
939         7)
940                 ac_cv_under_the_bed="lunatics and monsters found"
941                 ;;
942         *)
943                 ac_cv_under_the_bed="dust bunnies found"
944                 ;;
945         esac
946         ])
947
948 dnl Done! Now write the Makefile and sysdep.h
949 AC_SUBST(AUTH)
950 AC_SUBST(RESOLV)
951 AC_SUBST(chkpwd_LIBS)
952 AC_SUBST(TARGETS)
953 AC_SUBST(DATABASE)
954 AC_SUBST(SERVER_LDFLAGS)
955 AC_SUBST(SERVER_LIBS)
956 AC_SUBST(SETUP_LIBS)
957 AC_CONFIG_HEADER(sysdep.h)
958 ./mk_module_init.sh
959 AC_CONFIG_FILES([Makefile])
960 AC_OUTPUT(database_cleanup.sh)
961
962
963 if test -z "$DATABASE"; then
964         AC_MSG_WARN([No database driver was found. Please install Berkeley DB.])
965 fi
966
967 echo ------------------------------------------------------------------------
968 echo 'zlib compression:                ' $ok_zlib
969 echo 'LDAP support:                    ' $ok_ldap
970 echo 'Character set conversion support:' $ok_iconv
971 echo 'DSpam Scanning support:          ' $ok_libdspam
972 echo 
973 echo 'Note: if you are not using Linux, make sure you are using GNU make'
974 echo '(gmake) to compile Citadel.'
975 echo