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