* if we can't find iconv in the libc, try to find it in a separate library (like...
[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.24], [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                         AC_MSG_RESULT(OK)
109                         LIBS="-lcitadel $LIBS"
110                 ],
111                 [
112                         AC_MSG_ERROR(libcitadel was not found or is not usable.  Please install libcitadel.)
113                 ]
114         ,
115         )],
116         [
117                 AC_MSG_ERROR(libcitadel.h was not found or is not usable.  Please install libcitadel.)
118         ]
119 )
120
121
122 webcit_with_calendar_service=no
123 dnl Checks for the libical calendaring library.
124 if test "x$with_libical" != xno ; then
125         AC_CHECK_HEADERS(ical.h,
126                 [AC_CHECK_LIB(ical, icalcomponent_new,
127                         [ok_libical=yes],,
128         )])
129 fi
130
131 if test "x$ok_libical" = xyes ; then
132
133         AC_TRY_RUN(
134                 [
135 #include <ical.h>
136 main() {
137         int major, minor, v;
138         sscanf(ICAL_VERSION, "%d.%d", &major, &minor);
139         v = 100*major + minor;
140         printf("libical version: %i\n", v);
141         if (v >= 30) {
142                 printf("This version is ok.\n");
143                 return(0);
144         }
145         printf("libical 0.30 or newer required.\n");
146         printf("Citadel will be built without calendar support.\n");
147         return(1);
148 }
149                 ], 
150                 [
151                         LIBS="-lical $LIBS"
152                         AC_DEFINE(HAVE_LIBICAL,[],[whether we have libical available])
153                         webcit_with_calendar_service=yes
154                 ]
155         )
156 fi
157
158 if test "$webcit_with_calendar_service" == "yes"; then
159                         AC_DEFINE(WEBCIT_WITH_CALENDAR_SERVICE,[],[whether we can do with calendar.])
160 fi
161
162 dnl Checks for the zlib compression library.
163 if test "x$with_zlib" != xno ; then
164         AC_CHECK_HEADERS(zlib.h,
165                 [AC_CHECK_LIB(z, zlibVersion,
166                         [ok_zlib=yes],,
167         )])
168 fi
169
170 if test "x$ok_zlib" = xyes ; then
171         LIBS="-lz $LIBS"
172         AC_DEFINE(HAVE_ZLIB,[],[whether we have zlib])
173 fi
174
175
176 # The big search for OpenSSL
177 if test "$with_ssl" != "no"; then
178         saved_LIBS="$LIBS"
179         saved_LDFLAGS="$LDFLAGS"
180         saved_CFLAGS="$CFLAGS"
181         if test "x$prefix" != "xNONE"; then
182                 tryssldir="$tryssldir $prefix"
183         fi
184         AC_CACHE_CHECK([for OpenSSL], ac_cv_openssldir, [
185                 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
186                         CFLAGS="$saved_CFLAGS"
187                         LDFLAGS="$saved_LDFLAGS"
188                         LIBS="$saved_LIBS -lssl -lcrypto"
189         
190                         # Skip directories if they don't exist
191                         if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
192                                 continue;
193                         fi
194                         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
195                                 # Try to use $ssldir/lib if it exists, otherwise
196                                 # $ssldir
197                                 if test -d "$ssldir/lib" ; then
198                                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
199                                         if test ! -z "$need_dash_r" ; then
200                                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
201                                         fi
202                                 else
203                                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
204                                         if test ! -z "$need_dash_r" ; then
205                                                 LDFLAGS="-R$ssldir $LDFLAGS"
206                                         fi
207                                 fi
208                                 # Try to use $ssldir/include if it exists, otherwise
209                                 # $ssldir
210                                 if test -d "$ssldir/include" ; then
211                                         CFLAGS="-I$ssldir/include $saved_CFLAGS"
212                                 else
213                                         CFLAGS="-I$ssldir $saved_CFLAGS"
214                                 fi
215                         fi
216         
217                         # Basic test to check for compatible version and correct linking
218                         # *does not* test for RSA - that comes later.
219                         AC_TRY_RUN(
220                                 [
221         #include <string.h>
222         #include <openssl/rand.h>
223         int main(void)
224         {
225                 char a[2048];
226                 memset(a, 0, sizeof(a));
227                 RAND_add(a, sizeof(a), sizeof(a));
228                 return(RAND_status() <= 0);
229         }
230                                 ],
231                                 [
232                                         found_crypto=1
233                                         break;
234                                 ], []
235                         )
236         
237                         if test ! -z "$found_crypto" ; then
238                                 break;
239                         fi
240                 done
241         
242                 if test -z "$ssldir" ; then
243                         ssldir="(system)"
244                 fi
245         
246                 if test ! -z "$found_crypto" ; then
247                         ac_cv_openssldir=$ssldir
248                 else
249                         ac_cv_openssldir="no"
250                 fi
251         ])
252         LIBS="$saved_LIBS"
253         LDFLAGS="$saved_LDFLAGS"
254         CFLAGS="$saved_CFLAGS"
255         
256         if test "x$ac_cv_openssldir" != "xno" ; then
257                 AC_DEFINE(HAVE_OPENSSL,[],[whethe we have openssl])
258                 LIBS="-lssl -lcrypto $LIBS"
259                 dnl Need to recover ssldir - test above runs in subshell
260                 ssldir=$ac_cv_openssldir
261                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr" -a "x$ssldir" != "x(system)"; then
262                         # Try to use $ssldir/lib if it exists, otherwise
263                         # $ssldir
264                         if test -d "$ssldir/lib" ; then
265                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
266                                 if test ! -z "$need_dash_r" ; then
267                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
268                                 fi
269                         else
270                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
271                                 if test ! -z "$need_dash_r" ; then
272                                         LDFLAGS="-R$ssldir $LDFLAGS"
273                                 fi
274                         fi
275                         # Try to use $ssldir/include if it exists, otherwise
276                         # $ssldir
277                         if test -d "$ssldir/include" ; then
278                                 CFLAGS="-I$ssldir/include $saved_CFLAGS"
279                         else
280                                 CFLAGS="-I$ssldir $saved_CFLAGS"
281                         fi
282                 fi
283         fi
284 fi
285 dnl Checks for the SSLdir
286 dnl this is a bit different than the rest, 
287 dnl because of the citadel used to have a keys/ subdir.
288 AC_ARG_WITH(ssldir, 
289                     [  --with-ssldir          directory to store the ssl certificates under],
290                         [ if test "x$withval" != "xno" ; then
291                                               
292                                                   ssl_dir="$withval"
293                           fi
294                         AC_SUBST(MAKE_SSL_DIR)
295                         ]
296 )
297 AC_DEFINE_UNQUOTED(SSL_DIR, "$ssl_dir", [were should we put our keys?])
298
299 dnl Here is the check for a usable iconv
300
301 AC_ARG_ENABLE(iconv,
302         [  --disable-iconv         do not use iconv charset conversion],
303         ok_iconv=no, ok_iconv=yes)
304
305 if test "$ok_nls" != "no"; then
306         AC_MSG_RESULT(Checking to see if your system supports iconv...)
307         AC_TRY_RUN([
308                 #include <iconv.h>
309                 main() {
310                         iconv_t ic = (iconv_t)(-1) ;
311                         ic = iconv_open("UTF-8", "us-ascii");
312                         iconv_close(ic);
313                         exit(0);
314                 }
315         ],
316                 ok_iconv=yes,
317                 ok_iconv=no
318         )
319 fi
320
321 if test "$ok_iconv" = "no"; then
322         LD_FLAGS_BEFORE=$LDFLAGS
323         LDFLAGS="$LDFLAGS -liconv"
324                 AC_TRY_RUN([
325                         #include <iconv.h>
326                         main() {
327                                iconv_t ic = (iconv_t)(-1) ;
328                                ic = iconv_open("UTF-8", "us-ascii");
329                                iconv_close(ic);
330                                exit(0);
331                         }
332                         ],
333                         ok_iconv=yes,
334                         ok_iconv=no
335                 )
336                 if test "$ok_iconv" != "no"; then
337                    LDFLAGS=$LD_FLAGS_BEFORE
338                 fi
339 fi
340
341 if test "$ok_iconv" != "no"; then
342         AC_MSG_RESULT(WebCit will be built with character set conversion.)
343         AC_DEFINE(HAVE_ICONV,[],[whether we have iconv for charset conversion])
344 else
345         AC_MSG_RESULT(WebCit will be built without character set conversion.)
346 fi
347
348
349
350 dnl Here is the check for libintl etc.
351
352 AC_ARG_ENABLE(nls,
353         [  --disable-nls           do not use Native Language Support],
354         ok_nls=no, ok_nls=yes)
355
356 if test "$ok_nls" != "no"; then
357         AC_MSG_RESULT(Checking for per-thread NLS support...)
358         AC_TRY_RUN([
359                 #define _GNU_SOURCE
360                 #include <libintl.h>
361                 #include <locale.h>
362                 #include <time.h>
363                 main() {
364                         char *foo = NULL;
365                         char baz[32];
366                         struct tm *tm;
367                         uselocale(LC_GLOBAL_LOCALE);
368                         foo = gettext("bar");
369                         if (0) {
370                                 strftime_l(baz, sizeof baz, "%c", tm, LC_GLOBAL_LOCALE);
371                         }
372                         exit(0);
373                 }
374         ],
375                 ok_uselocale=yes,
376                 ok_uselocale=no
377         )
378         ok_nls=$ok_uselocale
379 fi
380
381 if test "$ok_nls" != "no"; then
382         AC_CHECK_PROG(ok_xgettext, xgettext, yes, no)
383         ok_nls=$ok_xgettext
384 fi
385
386 if test "$ok_nls" != "no"; then
387         AC_CHECK_PROG(ok_msgmerge, msgmerge, yes, no)
388         ok_nls=$ok_msgmerge
389 fi
390
391 if test "$ok_nls" != "no"; then
392         AC_CHECK_PROG(ok_msgfmt, msgfmt, yes, no)
393         ok_nls=$ok_msgfmt
394 fi
395
396 if test "$ok_nls" != "no"; then
397         AC_MSG_RESULT(WebCit will be built with national language support.)
398         AC_DEFINE(ENABLE_NLS, [], [whether we have NLS support])
399         PROG_SUBDIRS="$PROG_SUBDIRS po"
400 else
401         AC_MSG_RESULT(WebCit will be built without national language support.)
402 fi
403
404 AC_SUBST(SETUP_LIBS)
405
406 dnl disable backtrace if we don't want it.
407 AC_ARG_WITH(gprof, 
408                     [  --with-gprof          enable profiling],
409                         [ if test "x$withval" != "xno" ; then
410                              CFLAGS="$CFLAGS  -pg "
411                              LDFLAGS="$LDFLAGS  -pg "
412                           fi
413                         ]
414 )
415
416 dnl disable backtrace if we don't want it.
417 AC_ARG_WITH(backtrace, 
418                     [  --with-backtrace          enable backtrace dumps in the syslog],
419                         [ if test "x$withval" != "xno" ; then
420                              CFLAGS="$CFLAGS  -rdynamic "
421                              LDFLAGS="$LDFLAGS  -rdynamic "
422                              AC_CHECK_FUNCS(backtrace)
423                           fi
424                         ]
425 )
426
427 if test "$prefix" = NONE; then
428         datadir=$ac_default_prefix
429         localedir=$ac_default_prefix
430         wwwdir=$ac_default_prefix
431         rundir=$ac_default_prefix
432         editordir=$ac_default_prefix/tiny_mce
433 else
434         localedir=$prefix
435         wwwdir=$prefix
436         datadir=$prefix
437         rundir=$prefix
438         editordir=$prefix/tiny_mce
439 fi
440
441 dnl where to put the locale files
442 AC_ARG_WITH(localedir, 
443                     [  --with-localedir          directory to put the locale files to],
444                         [ if test "x$withval" != "xno" ; then
445                             localedir=$withval
446                           fi
447                         ]
448 )
449 AC_DEFINE_UNQUOTED(LOCALEDIR, "$localedir",[where to find our pot files])
450 LOCALEDIR=$localedir
451 AC_SUBST(LOCALEDIR)
452
453 dnl Checks where to put our templates
454 AC_ARG_WITH(wwwdir, 
455                     [  --with-wwwdir             directory to put our templates],
456                         [ if test "x$withval" != "xno" ; then
457                                 wwwdir=$withval
458                           fi
459                         ]
460 )
461 AC_DEFINE_UNQUOTED(WWWDIR, "$wwwdir", [where to find our templates and pics])
462 WWWDIR=$wwwdir
463 AC_SUBST(WWWDIR)
464
465
466 dnl Checks for the run-dir for the sockets
467 AC_ARG_WITH(rundir, 
468                         [  --with-rundir           directory to place runtime files (UDS) to?],
469                         [ if test "x$withval" != "xno" ; then
470                                             AC_DEFINE(HAVE_RUN_DIR, [], [should we put our non volatile files elsewhere?])
471                                                 
472                                                 rundir=$withval
473                                                 AC_SUBST(MAKE_RUN_DIR)
474                           fi
475                         ]
476 )
477 AC_DEFINE_UNQUOTED(RUNDIR, "$rundir", [define, where the config should go in unix style])
478
479 dnl Checks for the Datadir
480 AC_ARG_WITH(datadir, 
481                     [  --with-datadir          directory to store the databases under],
482                         [ if test "x$withval" != "xno" ; then
483                                               datadir=$withval
484                           fi
485                         ]
486 )
487 AC_DEFINE_UNQUOTED(DATADIR, "$datadir",[define, if the user suplied a data-directory to use.])
488
489 dnl Checks where to put our editor
490 AC_ARG_WITH(editordir, 
491                     [  --with-editordir             directory to put our editor],
492                         [ if test "x$withval" != "xno" ; then
493                                 editordir=$withval
494                           fi
495                         ]
496 )
497 AC_DEFINE_UNQUOTED(EDITORDIR, "$editordir", [where to find our mail editor])
498
499 AC_CONFIG_HEADER(sysdep.h)
500 AC_OUTPUT(Makefile po/Makefile )
501
502 echo ------------------------------------------------------------------------
503 echo 'zlib compression:                ' $ok_zlib
504 echo 'Calendar support:                ' $ok_libical
505 echo 'Character set conversion support:' $ok_iconv
506 echo 'National language support:       ' $ok_nls
507 echo