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