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