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