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