* move to config-header similar to citserver.
[citadel.git] / webcit / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 dnl $Id$
3 AC_INIT(webserver.c)
4
5
6 PACKAGE=webcit
7 VERSION=7.13
8 AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [our package name])
9 AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [our package version])
10 AC_SUBST(PACKAGE)
11 AC_SUBST(VERSION)
12
13 AC_SUBST(PROG_SUBDIRS)
14 AC_DEFINE(PROG_SUBDIRS, [], [Program dirs])
15 AC_CANONICAL_HOST
16 AC_PROG_INSTALL
17 missing_dir=`cd $ac_aux_dir && pwd`
18 AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
19 AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
20
21 dnl Make sure we see all GNU and Solaris extensions.
22 AC_GNU_SOURCE
23
24 AC_CHECK_PROG(SED, sed, sed, no)
25 AC_PREFIX_DEFAULT(/usr/local/webcit)
26 if test "$prefix" = NONE; then
27         AC_DEFINE_UNQUOTED(WEBCITDIR, "$ac_default_prefix", [define this to the Citadel home directory])
28         ssl_dir="$ac_default_prefix/keys"
29 else
30         AC_DEFINE_UNQUOTED(WEBCITDIR, "$prefix", [define this to the Citadel home directory])
31         ssl_dir="$prefix/keys"
32 fi
33
34 AC_ARG_WITH(with_libical, [  --with-libical          use libical calendaring library])
35 AC_ARG_WITH(with_zlib,    [  --with-zlib             use zlib compression if present])
36 AC_ARG_WITH(ssl,
37         [  --with-ssl=PATH         Specify path to OpenSSL installation ],
38         [
39                 if test "x$withval" != "xno" ; then
40                         tryssldir=$withval
41                 fi
42         ]
43 )
44 dnl Set some system-specific variables which are OK to set before compiler
45 dnl checks:
46 PTHREAD_DEFS=-D_REENTRANT
47 case "$host" in
48         dnl Tru64 Unix requires we use -pthread instead of linking the threads
49         dnl libraries directly, and we can't build threaded programs with gcc
50         dnl due to header file problems.
51         alpha*-dec-osf*)
52                 test -z "$CC" && CC=cc
53                 LIBS=-pthread
54         ;;
55         dnl FreeBSD is similar:
56         *-*-freebsd*)
57                 LIBS=-pthread
58                 PTHREAD_DEFS=-D_THREAD_SAFE
59         ;;
60         *-*-solaris*)
61                 PTHREAD_DEFS='-D_REENTRANT -D_PTHREADS'
62         ;;
63 esac
64 AC_SUBST(PTHREAD_DEFS)
65
66 dnl Checks for programs.
67 AC_PROG_CC
68
69 dnl Configure compiler flags for GCC
70 if test "$GCC" = yes; then
71         case "$host" in
72                 *-*-solaris*)
73                         CFLAGS="$CFLAGS -Wall -Wno-char-subscripts"
74                 ;;
75                 *)
76                         CFLAGS="$CFLAGS -Wall"
77                 ;;
78         esac
79 fi
80
81 # missing_dir=`cd $ac_aux_dir && pwd`
82 # AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
83
84 dnl Checks for libraries.
85 if test "$LIBS" != -pthread; then
86         AC_CHECK_LIB(pthread, pthread_create)
87         AC_CHECK_LIB(pthreads, pthread_create)
88 fi
89 AC_SEARCH_LIBS(gethostbyname, nsl)
90 AC_SEARCH_LIBS(connect, socket)
91
92 dnl Checks for header files.
93 AC_HEADER_STDC
94 dnl AC_HEADER_SYS_WAIT
95 AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h)
96
97
98
99
100 dnl Checks for typedefs, structures, and compiler characteristics.
101 AC_C_CONST
102 AC_TYPE_OFF_T
103 AC_TYPE_SIZE_T
104 dnl AC_HEADER_TIME
105
106 dnl Checks for library functions.
107 AC_TYPE_SIGNAL
108 dnl AC_FUNC_VPRINTF
109 AC_REPLACE_FUNCS(snprintf)
110
111 dnl Checks for the libical calendaring library.
112 if test "x$with_libical" != xno ; then
113         AC_CHECK_HEADERS(ical.h,
114                 [AC_CHECK_LIB(ical, icalcomponent_new,
115                         [ok_libical=yes],,
116         )])
117 fi
118
119 if test "x$ok_libical" = xyes ; then
120
121         AC_TRY_RUN(
122                 [
123 #include <ical.h>
124 main() {
125         int major, minor, v;
126         sscanf(ICAL_VERSION, "%d.%d", &major, &minor);
127         v = 100*major + minor;
128         printf("libical version: %i\n", v);
129         if (v >= 24) {
130                 printf("This version is ok.\n");
131                 return(0);
132         }
133         printf("libical 0.24 or newer required.\n");
134         printf("Citadel will be built without calendar support.\n");
135         return(1);
136 }
137                 ], 
138                 [
139                         LIBS="-lical $LIBS"
140                         AC_DEFINE(HAVE_LIBICAL,[],[whether we have libical available])
141                 ]
142         )
143 fi
144
145
146
147 dnl Checks for the zlib compression library.
148 if test "x$with_zlib" != xno ; then
149         AC_CHECK_HEADERS(zlib.h,
150                 [AC_CHECK_LIB(z, zlibVersion,
151                         [ok_zlib=yes],,
152         )])
153 fi
154
155 if test "x$ok_zlib" = xyes ; then
156         LIBS="-lz $LIBS"
157         AC_DEFINE(HAVE_ZLIB,[],[whether we have zlib])
158 fi
159
160
161 # The big search for OpenSSL
162 if test "$with_ssl" != "no"; then
163         saved_LIBS="$LIBS"
164         saved_LDFLAGS="$LDFLAGS"
165         saved_CFLAGS="$CFLAGS"
166         if test "x$prefix" != "xNONE"; then
167                 tryssldir="$tryssldir $prefix"
168         fi
169         AC_CACHE_CHECK([for OpenSSL], ac_cv_openssldir, [
170                 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
171                         CFLAGS="$saved_CFLAGS"
172                         LDFLAGS="$saved_LDFLAGS"
173                         LIBS="$saved_LIBS -lssl -lcrypto"
174         
175                         # Skip directories if they don't exist
176                         if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
177                                 continue;
178                         fi
179                         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
180                                 # Try to use $ssldir/lib if it exists, otherwise
181                                 # $ssldir
182                                 if test -d "$ssldir/lib" ; then
183                                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
184                                         if test ! -z "$need_dash_r" ; then
185                                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
186                                         fi
187                                 else
188                                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
189                                         if test ! -z "$need_dash_r" ; then
190                                                 LDFLAGS="-R$ssldir $LDFLAGS"
191                                         fi
192                                 fi
193                                 # Try to use $ssldir/include if it exists, otherwise
194                                 # $ssldir
195                                 if test -d "$ssldir/include" ; then
196                                         CFLAGS="-I$ssldir/include $saved_CFLAGS"
197                                 else
198                                         CFLAGS="-I$ssldir $saved_CFLAGS"
199                                 fi
200                         fi
201         
202                         # Basic test to check for compatible version and correct linking
203                         # *does not* test for RSA - that comes later.
204                         AC_TRY_RUN(
205                                 [
206         #include <string.h>
207         #include <openssl/rand.h>
208         int main(void)
209         {
210                 char a[2048];
211                 memset(a, 0, sizeof(a));
212                 RAND_add(a, sizeof(a), sizeof(a));
213                 return(RAND_status() <= 0);
214         }
215                                 ],
216                                 [
217                                         found_crypto=1
218                                         break;
219                                 ], []
220                         )
221         
222                         if test ! -z "$found_crypto" ; then
223                                 break;
224                         fi
225                 done
226         
227                 if test -z "$ssldir" ; then
228                         ssldir="(system)"
229                 fi
230         
231                 if test ! -z "$found_crypto" ; then
232                         ac_cv_openssldir=$ssldir
233                 else
234                         ac_cv_openssldir="no"
235                 fi
236         ])
237         LIBS="$saved_LIBS"
238         LDFLAGS="$saved_LDFLAGS"
239         CFLAGS="$saved_CFLAGS"
240         
241         if test "x$ac_cv_openssldir" != "xno" ; then
242                 AC_DEFINE(HAVE_OPENSSL,[],[whethe we have openssl])
243                 LIBS="-lssl -lcrypto $LIBS"
244                 dnl Need to recover ssldir - test above runs in subshell
245                 ssldir=$ac_cv_openssldir
246                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr" -a "x$ssldir" != "x(system)"; then
247                         # Try to use $ssldir/lib if it exists, otherwise
248                         # $ssldir
249                         if test -d "$ssldir/lib" ; then
250                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
251                                 if test ! -z "$need_dash_r" ; then
252                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
253                                 fi
254                         else
255                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
256                                 if test ! -z "$need_dash_r" ; then
257                                         LDFLAGS="-R$ssldir $LDFLAGS"
258                                 fi
259                         fi
260                         # Try to use $ssldir/include if it exists, otherwise
261                         # $ssldir
262                         if test -d "$ssldir/include" ; then
263                                 CFLAGS="-I$ssldir/include $saved_CFLAGS"
264                         else
265                                 CFLAGS="-I$ssldir $saved_CFLAGS"
266                         fi
267                 fi
268         fi
269 fi
270 dnl Checks for the SSLdir
271 dnl this is a bit different than the rest, 
272 dnl because of the citadel used to have a keys/ subdir.
273 AC_ARG_WITH(ssldir, 
274                     [  --with-ssldir          directory to store the ssl certificates under],
275                         [ if test "x$withval" != "xno" ; then
276                                               
277                                                   ssl_dir="$withval"
278                           fi
279                         AC_SUBST(MAKE_SSL_DIR)
280                         ]
281 )
282 AC_DEFINE_UNQUOTED(SSL_DIR, "$ssl_dir", [were should we put our keys?])
283
284 dnl Here is the check for a usable iconv
285
286 AC_ARG_ENABLE(iconv,
287         [  --disable-iconv         do not use iconv charset conversion],
288         ok_iconv=no, ok_iconv=yes)
289
290 if test "$ok_nls" != "no"; then
291         AC_MSG_RESULT(Checking to see if your system supports iconv...)
292         AC_TRY_RUN([
293                 #include <iconv.h>
294                 main() {
295                         iconv_t ic = (iconv_t)(-1) ;
296                         ic = iconv_open("UTF-8", "us-ascii");
297                         iconv_close(ic);
298                         exit(0);
299                 }
300         ],
301                 ok_iconv=yes,
302                 ok_iconv=no
303         )
304 fi
305
306 if test "$ok_iconv" != "no"; then
307         AC_MSG_RESULT(WebCit will be built with character set conversion.)
308         AC_DEFINE(HAVE_ICONV,[],[whether we have iconv for charset conversion])
309 else
310         AC_MSG_RESULT(WebCit will be built without character set conversion.)
311 fi
312
313
314
315 dnl Here is the check for libintl etc.
316
317 AC_ARG_ENABLE(nls,
318         [  --disable-nls           do not use Native Language Support],
319         ok_nls=no, ok_nls=yes)
320
321 if test "$ok_nls" != "no"; then
322         AC_MSG_RESULT(Checking for per-thread NLS support...)
323         AC_TRY_RUN([
324                 #define _GNU_SOURCE
325                 #include <libintl.h>
326                 #include <locale.h>
327                 #include <time.h>
328                 main() {
329                         char *foo = NULL;
330                         char baz[32];
331                         struct tm *tm;
332                         uselocale(LC_GLOBAL_LOCALE);
333                         foo = gettext("bar");
334                         if (0) {
335                                 strftime_l(baz, sizeof baz, "%c", tm, LC_GLOBAL_LOCALE);
336                         }
337                         exit(0);
338                 }
339         ],
340                 ok_uselocale=yes,
341                 ok_uselocale=no
342         )
343         ok_nls=$ok_uselocale
344 fi
345
346 if test "$ok_nls" != "no"; then
347         AC_CHECK_PROG(ok_xgettext, xgettext, yes, no)
348         ok_nls=$ok_xgettext
349 fi
350
351 if test "$ok_nls" != "no"; then
352         AC_CHECK_PROG(ok_msgmerge, msgmerge, yes, no)
353         ok_nls=$ok_msgmerge
354 fi
355
356 if test "$ok_nls" != "no"; then
357         AC_CHECK_PROG(ok_msgfmt, msgfmt, yes, no)
358         ok_nls=$ok_msgfmt
359 fi
360
361 if test "$ok_nls" != "no"; then
362         AC_MSG_RESULT(WebCit will be built with national language support.)
363         AC_DEFINE(ENABLE_NLS, [], [whether we have NLS support])
364         PROG_SUBDIRS="$PROG_SUBDIRS po"
365 else
366         AC_MSG_RESULT(WebCit will be built without national language support.)
367 fi
368
369 AC_SUBST(SETUP_LIBS)
370
371 dnl disable backtrace if we don't want it.
372 AC_ARG_WITH(gprof, 
373                     [  --with-gprof          enable profiling],
374                         [ if test "x$withval" != "xno" ; then
375                              CFLAGS="$CFLAGS  -pg "
376                              LDFLAGS="$LDFLAGS  -pg "
377                           fi
378                         ]
379 )
380
381 dnl disable backtrace if we don't want it.
382 AC_ARG_WITH(backtrace, 
383                     [  --with-backtrace          enable backtrace dumps in the syslog],
384                         [ if test "x$withval" != "xno" ; then
385                              CFLAGS="$CFLAGS  -rdynamic "
386                              LDFLAGS="$LDFLAGS  -rdynamic "
387                              AC_CHECK_FUNCS(backtrace)
388                           fi
389                         ]
390 )
391
392 if test "$prefix" = NONE; then
393         datadir=$ac_default_prefix
394         localedir=$ac_default_prefix
395         wwwdir=$ac_default_prefix
396         rundir=$ac_default_prefix
397         editordir=$ac_default_prefix/tiny_mce
398 else
399         localedir=$prefix
400         wwwdir=$prefix
401         datadir=$prefix
402         rundir=$prefix
403         editordir=$prefix/tiny_mce
404 fi
405
406 dnl where to put the locale files
407 AC_ARG_WITH(localedir, 
408                     [  --with-localedir          directory to put the locale files to],
409                         [ if test "x$withval" != "xno" ; then
410                             localedir=$withval
411                           fi
412                         ]
413 )
414 AC_DEFINE_UNQUOTED(LOCALEDIR, "$localedir",[where to find our pot files])
415
416 dnl Checks where to put our templates
417 AC_ARG_WITH(wwwdir, 
418                     [  --with-wwwdir             directory to put our templates],
419                         [ if test "x$withval" != "xno" ; then
420                                 wwwdir=$withval
421                           fi
422                         ]
423 )
424 AC_DEFINE_UNQUOTED(WWWDIR, "$wwwdir", [where to find our templates and pics])
425
426
427
428 dnl Checks for the run-dir for the sockets
429 AC_ARG_WITH(rundir, 
430                         [  --with-rundir           directory to place runtime files (UDS) to?],
431                         [ if test "x$withval" != "xno" ; then
432                                             AC_DEFINE(HAVE_RUN_DIR, [], [should we put our non volatile files elsewhere?])
433                                                 
434                                                 rundir=$withval
435                                                 AC_SUBST(MAKE_RUN_DIR)
436                           fi
437                         ]
438 )
439 AC_DEFINE_UNQUOTED(RUNDIR, "$rundir", [define, where the config should go in unix style])
440
441 dnl Checks for the Datadir
442 AC_ARG_WITH(datadir, 
443                     [  --with-datadir          directory to store the databases under],
444                         [ if test "x$withval" != "xno" ; then
445                                               datadir=$withval
446                           fi
447                         ]
448 )
449 AC_DEFINE_UNQUOTED(DATADIR, "$datadir",[define, if the user suplied a data-directory to use.])
450
451 dnl Checks where to put our editor
452 AC_ARG_WITH(editordir, 
453                     [  --with-editordir             directory to put our editor],
454                         [ if test "x$withval" != "xno" ; then
455                                 editordir=$withval
456                           fi
457                         ]
458 )
459 AC_DEFINE_UNQUOTED(EDITORDIR, "$editordir", [where to find our mail editor])
460
461 AC_CONFIG_HEADER(sysdep.h)
462 AC_OUTPUT(Makefile po/Makefile )
463
464 echo ------------------------------------------------------------------------
465 echo 'zlib compression:                ' $ok_zlib
466 echo 'Calendar support:                ' $ok_libical
467 echo 'Character set conversion support:' $ok_iconv
468 echo 'National language support:       ' $ok_nls
469 echo