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