9b33da91bdf5d13b154d182351bab81f2b543231
[citadel.git] / webcit / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 dnl $Id$
3 AC_INIT([WebCit], [8.13], [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         *-*-darwin*)
55                 LIBS=-lintl
56 esac
57 AC_SUBST(PTHREAD_DEFS)
58
59 dnl Checks for programs.
60 AC_PROG_CC
61
62 dnl Configure compiler flags for GCC
63 if test "$GCC" = yes; then
64         case "$host" in
65                 *-*-solaris*)
66 dnl                     CFLAGS="$CFLAGS -Wall -Wno-char-subscripts --pedantic"
67                         CFLAGS="$CFLAGS -Wall -Wno-char-subscripts"
68                 ;;
69                 *)
70 dnl                     CFLAGS="$CFLAGS -Wall --pedantic"
71                         CFLAGS="$CFLAGS -Wall"
72                 ;;
73         esac
74 fi
75
76 # missing_dir=`cd $ac_aux_dir && pwd`
77 # AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
78
79 dnl Checks for libraries.
80 if test "$LIBS" != -pthread; then
81         AC_CHECK_LIB(pthread, pthread_create)
82         AC_CHECK_LIB(pthreads, pthread_create)
83 fi
84 AC_SEARCH_LIBS(gethostbyname, nsl)
85 AC_SEARCH_LIBS(connect, socket)
86
87 dnl Checks for header files.
88 AC_HEADER_STDC
89 dnl AC_HEADER_SYS_WAIT
90
91 AC_CACHE_CHECK(
92         [for call semantics from getpwuid_r], 
93         ac_cv_call_getpwuid_r,
94         [AC_TRY_COMPILE([#include <sys/types.h>
95 #include <pwd.h>], 
96                          [
97                                 struct passwd pw, *pwp;
98                                 char pwbuf[64];
99                                 uid_t uid;
100
101                                 getpwuid_r(uid, &pw, pwbuf, sizeof(pwbuf), &pwp);
102                         ],
103                         ac_cv_call_getpwuid_r=yes, 
104                         ac_cv_call_getpwuid_r=no)
105         ])
106
107 if test $ac_cv_call_getpwuid_r = no; then
108         AC_DEFINE(SOLARIS_GETPWUID,[],[do we need to use solaris call syntax?])
109         AC_DEFINE(SOLARIS_LOCALTIME_R,[], [do we need to use soralis call syntax?])
110         AC_DEFINE(F_UID_T, "%ld", [whats the matching format string for uid_t?])
111         AC_DEFINE(F_PID_T, "%ld",  [whats the matching format string for pid_t?])
112         AC_DEFINE(F_XPID_T, "%lx",  [whats the matching format string for xpid_t?])
113 else
114         AC_DEFINE(F_UID_T, "%d",  [whats the matching format string for uid_t?])
115         AC_DEFINE(F_PID_T, "%d",  [whats the matching format string for pid_t?])
116         AC_DEFINE(F_XPID_T, "%x",  [whats the matching format string for xpid_t?])
117 fi
118
119
120
121 dnl Checks for typedefs, structures, and compiler characteristics.
122 AC_C_CONST
123 AC_TYPE_OFF_T
124 AC_TYPE_SIZE_T
125 dnl Check the size of various builtin types; see typesize.h (error)
126 AC_CHECK_SIZEOF(char, 0)
127 AC_CHECK_SIZEOF(short, 0)
128 AC_CHECK_SIZEOF(int, 0)
129 AC_CHECK_SIZEOF(long, 0)
130 AC_CHECK_SIZEOF(long unsigned int, 0)
131 AC_CHECK_SIZEOF(size_t, 0)
132 dnl AC_HEADER_TIME
133
134 dnl Checks for library functions.
135 AC_TYPE_SIGNAL
136 dnl AC_FUNC_VPRINTF
137 AC_REPLACE_FUNCS(snprintf)
138 AC_CHECK_HEADER(CUnit/CUnit.h, [AC_DEFINE(ENABLE_TESTS, [], [whether we should compile the test-suite])])
139
140 AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h iconv.h xlocale.h)
141
142 dnl Checks for the zlib compression library.
143 saved_CFLAGS="$CFLAGS"
144 CFLAGS="$CFLAGS $SERVER_LIBS"
145 AC_CHECK_HEADER(zlib.h,
146         [AC_CHECK_LIB(z, zlibVersion,
147                 [
148                         LIBS="-lz $LIBS $SERVER_LIBS"
149                 ],
150                 [
151                         AC_MSG_ERROR(zlib was not found or is not usable.  Please install zlib.)
152                 ]
153         ,
154         )],
155         [
156                 AC_MSG_ERROR(zlib.h was not found or is not usable.  Please install zlib.)
157         ]
158 )
159 CFLAGS="$saved_CFLAGS"
160
161 dnl Here is the check for a libc integrated iconv
162 AC_ARG_ENABLE(iconv,
163         [  --disable-iconv         do not use iconv charset conversion],
164         ok_iconv=no, ok_iconv=yes)
165
166 AC_MSG_CHECKING(Checking to see if your system supports iconv)
167 AC_TRY_RUN([
168         #include <iconv.h>
169         main() {
170                 iconv_t ic = (iconv_t)(-1) ;
171                 ic = iconv_open("UTF-8", "us-ascii");
172                 iconv_close(ic);
173                 exit(0);
174         }
175  ],
176                 [
177                   ok_iconv=yes
178                   AC_MSG_RESULT([yes])
179                 ],
180                 [ 
181                   ok_iconv=no
182                   AC_MSG_RESULT([no])
183                 ]
184 )
185
186 dnl Check for iconv in external libiconv
187 if test "$ok_iconv" = no; then
188         AC_MSG_CHECKING(Checking for an external libiconv)
189         OLD_LDFLAGS="$LDFLAGS"
190         LDFLAGS="$LDFLAGS -liconv"
191         AC_TRY_RUN([
192                         #include <iconv.h>
193                         main() {
194                                 iconv_t ic = (iconv_t)(-1) ;
195                                 ic = iconv_open("UTF-8", "us-ascii");
196                                 iconv_close(ic);
197                         }
198                 ],
199                         [
200                           ok_iconv=yes
201                           AC_MSG_RESULT([yes])
202                         ],
203                         [ 
204                           ok_iconv=no
205                           LDFLAGS="$OLD_LDFLAGS"
206                           AC_MSG_RESULT([no])
207                         ]
208                 )
209 fi      
210 if test "$ok_iconv" != "no"; then
211         AC_MSG_RESULT(webcit will be built with character set conversion.)
212         AC_DEFINE(HAVE_ICONV,[],[whether we have iconv for charset conversion])
213 else
214         AC_MSG_RESULT(webcit will be built without character set conversion.)
215 fi
216
217
218 AC_CHECK_LIB(intl, libintl_bindtextdomain, [LDFLAGS="$LDFLAGS -lintl"])
219
220
221 dnl Checks for the libical iCalendar library.
222 AC_CHECK_HEADER(libical/ical.h,
223         [AC_CHECK_LIB(ical, icaltimezone_set_tzid_prefix,
224                 [
225                         LIBS="-lical $LIBS"
226                 ],
227                 [
228                         AC_MSG_ERROR(libical was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
229                 ]
230         ,
231         )],
232         [
233                 AC_MSG_ERROR(libical/ical.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
234         ]
235 )
236
237
238 dnl Check for libcitadel
239 AC_CHECK_HEADER(libcitadel.h,
240         [AC_CHECK_LIB(citadel, libcitadel_version_string,
241                 [
242                         LIBS="-lcitadel $LIBS"
243                         SETUP_LIBS="-lcitadel $SETUP_LIBS"
244                 ],
245                 [
246                         AC_MSG_ERROR(libcitadel was not found or is not usable.  Please install libcitadel.)
247                 ]
248         ,
249         )],
250         [
251                 AC_MSG_ERROR(libcitadel.h was not found or is not usable.  Please install libcitadel.)
252         ]
253 )
254
255 AC_MSG_CHECKING([whether your system likes memcpy + HKEY]) 
256 AC_TRY_COMPILE([
257 #define _GNU_SOURCE
258 #include <ctype.h>
259 #include <errno.h>
260 #include <string.h>
261 #include <unistd.h>
262 #include <string.h>
263 #include <stdio.h>
264 #include <sys/select.h>
265 #include <fcntl.h>
266 #include <sys/types.h>
267
268 #include "lib/libcitadel.h"
269 ],
270 [
271         char foo[22];
272         memcpy(foo, HKEY("foo"));
273         
274 ],
275                 [
276
277                   AC_MSG_RESULT([yes])
278                 ],
279                 [ 
280                   AC_DEFINE(UNDEF_MEMCPY, [], [whether we need to undefine memcpy])
281                   AC_MSG_RESULT([no])
282                 ]
283 )
284
285 dnl Checks for the Expat XML parser.
286 AC_CHECK_HEADER(expat.h,
287         [AC_CHECK_LIB(expat, XML_ParserCreateNS,
288                 [
289                         LIBS="-lexpat $LIBS"
290                 ],
291                 [
292                         AC_MSG_ERROR(The Expat XML parser was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
293                 ]
294         ,
295         )],
296         [
297                 AC_MSG_ERROR(expat.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
298         ]
299 )
300
301
302
303 found_ssl=no
304 # The big search for OpenSSL
305 if test "$with_ssl" != "no"; then
306         saved_LIBS="$LIBS"
307         saved_LDFLAGS="$LDFLAGS"
308         saved_CFLAGS="$CFLAGS"
309         if test "x$prefix" != "xNONE"; then
310                 tryssldir="$tryssldir $prefix"
311         fi
312         AC_CACHE_CHECK([for OpenSSL], ac_cv_openssldir, [
313                 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
314                         CFLAGS="$saved_CFLAGS"
315                         LDFLAGS="$saved_LDFLAGS"
316                         LIBS="$saved_LIBS -lssl -lcrypto"
317         
318                         # Skip directories if they don't exist
319                         if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
320                                 continue;
321                         fi
322                         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
323                                 # Try to use $ssldir/lib if it exists, otherwise
324                                 # $ssldir
325                                 if test -d "$ssldir/lib" ; then
326                                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
327                                         if test ! -z "$need_dash_r" ; then
328                                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
329                                         fi
330                                 else
331                                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
332                                         if test ! -z "$need_dash_r" ; then
333                                                 LDFLAGS="-R$ssldir $LDFLAGS"
334                                         fi
335                                 fi
336                                 # Try to use $ssldir/include if it exists, otherwise
337                                 # $ssldir
338                                 if test -d "$ssldir/include" ; then
339                                         CFLAGS="-I$ssldir/include $saved_CFLAGS"
340                                 else
341                                         CFLAGS="-I$ssldir $saved_CFLAGS"
342                                 fi
343                         fi
344         
345                         # Basic test to check for compatible version and correct linking
346                         # *does not* test for RSA - that comes later.
347                         AC_TRY_RUN(
348                                 [
349         #include <string.h>
350         #include <openssl/rand.h>
351         int main(void)
352         {
353                 char a[2048];
354                 memset(a, 0, sizeof(a));
355                 RAND_add(a, sizeof(a), sizeof(a));
356                 return(RAND_status() <= 0);
357         }
358                                 ],
359                                 [
360                                         found_crypto=1
361                                         break;
362                                 ], []
363                         )
364         
365                         if test ! -z "$found_crypto" ; then
366                                 break;
367                         fi
368                 done
369         
370                 if test -z "$ssldir" ; then
371                         ssldir="(system)"
372                 fi
373         
374                 if test ! -z "$found_crypto" ; then
375                         ac_cv_openssldir=$ssldir
376                 else
377                         ac_cv_openssldir="no"
378                 fi
379         ])
380         LIBS="$saved_LIBS"
381         LDFLAGS="$saved_LDFLAGS"
382         CFLAGS="$saved_CFLAGS"
383         
384         if test "x$ac_cv_openssldir" != "xno" ; then
385                 AC_DEFINE(HAVE_OPENSSL,[],[whethe we have openssl])
386                 found_ssl=yes
387                 LIBS="-lssl -lcrypto $LIBS"
388                 dnl Need to recover ssldir - test above runs in subshell
389                 ssldir=$ac_cv_openssldir
390                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr" -a "x$ssldir" != "x(system)"; then
391                         # Try to use $ssldir/lib if it exists, otherwise
392                         # $ssldir
393                         if test -d "$ssldir/lib" ; then
394                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
395                                 if test ! -z "$need_dash_r" ; then
396                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
397                                 fi
398                         else
399                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
400                                 if test ! -z "$need_dash_r" ; then
401                                         LDFLAGS="-R$ssldir $LDFLAGS"
402                                 fi
403                         fi
404                         # Try to use $ssldir/include if it exists, otherwise
405                         # $ssldir
406                         if test -d "$ssldir/include" ; then
407                                 CFLAGS="-I$ssldir/include $saved_CFLAGS"
408                         else
409                                 CFLAGS="-I$ssldir $saved_CFLAGS"
410                         fi
411                 fi
412         fi
413 fi
414 dnl Checks for the SSLdir
415 dnl this is a bit different than the rest, 
416 dnl because of the citadel used to have a keys/ subdir.
417 AC_ARG_WITH(ssldir, 
418                     [  --with-ssldir          directory to store the ssl certificates under],
419                         [ if test "x$withval" != "xno" ; then
420                                               
421                                                   ssl_dir="$withval"
422                                                   if test "$found_ssl" = "no"; then
423                                                      echo "Your setup was incomplete; ssldir doesn't make sense without openssl"
424                                                      exit
425                                                   fi
426                           fi
427                         AC_SUBST(MAKE_SSL_DIR)
428                         ]
429 )
430 AC_DEFINE_UNQUOTED(SSL_DIR, "$ssl_dir", [were should we put our keys?])
431
432
433
434
435 AC_CHECK_FUNCS(strftime_l uselocale gettext)
436
437 if test "$ok_nls" != "no"; then
438         AC_CHECK_PROG(ok_xgettext, xgettext, yes, no)
439         ok_nls=$ok_xgettext
440 fi
441
442 if test "$ok_nls" != "no"; then
443         AC_CHECK_PROG(ok_msgmerge, msgmerge, yes, no)
444         ok_nls=$ok_msgmerge
445 fi
446
447 if test "$ok_nls" != "no"; then
448         AC_CHECK_PROG(ok_msgfmt, msgfmt, yes, no)
449         ok_nls=$ok_msgfmt
450 fi
451
452 if test "$ok_nls" != "no"; then
453         AC_MSG_RESULT(WebCit will be built with national language support.)
454         AC_DEFINE(ENABLE_NLS, [], [whether we have NLS support])
455         PROG_SUBDIRS="$PROG_SUBDIRS po/webcit/"
456 else
457         AC_MSG_RESULT(WebCit will be built without national language support.)
458 fi
459
460 AC_SUBST(SETUP_LIBS)
461
462 dnl disable backtrace if we don't want it.
463 AC_ARG_WITH(gprof, 
464                     [  --with-gprof          enable profiling],
465                         [ if test "x$withval" != "xno" ; then
466                              CFLAGS="$CFLAGS  -pg "
467                              LDFLAGS="$LDFLAGS  -pg "
468                           fi
469                         ]
470 )
471
472 dnl disable backtrace if we don't want it.
473 AC_ARG_WITH(backtrace, 
474                     [  --with-backtrace          enable backtrace dumps in the syslog],
475                         [ if test "x$withval" != "xno" ; then
476                              CFLAGS="$CFLAGS  -rdynamic "
477                              LDFLAGS="$LDFLAGS  -rdynamic "
478                              AC_CHECK_FUNCS(backtrace)
479                           fi
480                         ]
481 )
482
483 if test "$prefix" = NONE; then
484         datadir=$ac_default_prefix
485         localedir=$ac_default_prefix
486         wwwdir=$ac_default_prefix
487         rundir=$ac_default_prefix
488         editordir=$ac_default_prefix/tiny_mce
489 else
490         localedir=$prefix
491         wwwdir=$prefix
492         datadir=$prefix
493         rundir=$prefix
494         editordir=$prefix/tiny_mce
495 fi
496
497 dnl where to put the locale files
498 AC_ARG_WITH(localedir, 
499                     [  --with-localedir          directory to put the locale files to],
500                         [ if test "x$withval" != "xno" ; then
501                             localedir=$withval
502                           fi
503                         ]
504 )
505 AC_DEFINE_UNQUOTED(LOCALEDIR, "$localedir",[where to find our pot files])
506 LOCALEDIR=$localedir
507 AC_SUBST(LOCALEDIR)
508
509 dnl Checks where to put our templates
510 AC_ARG_WITH(wwwdir, 
511                     [  --with-wwwdir             directory to put our templates],
512                         [ if test "x$withval" != "xno" ; then
513                                 wwwdir=$withval
514                           fi
515                         ]
516 )
517 AC_DEFINE_UNQUOTED(WWWDIR, "$wwwdir", [where to find our templates and pics])
518 WWWDIR=$wwwdir
519 AC_SUBST(WWWDIR)
520
521
522 dnl Checks for the run-dir for the sockets
523 AC_ARG_WITH(rundir, 
524                         [  --with-rundir           directory to place runtime files (UDS) to?],
525                         [ if test "x$withval" != "xno" ; then
526                                             AC_DEFINE(HAVE_RUN_DIR, [], [should we put our non volatile files elsewhere?])
527                                                 
528                                                 rundir=$withval
529                                                 AC_SUBST(MAKE_RUN_DIR)
530                           fi
531                         ]
532 )
533 AC_DEFINE_UNQUOTED(RUNDIR, "$rundir", [define, where the config should go in unix style])
534
535 dnl Checks for the Datadir
536 AC_ARG_WITH(datadir, 
537                     [  --with-datadir          directory to store the databases under],
538                         [ if test "x$withval" != "xno" ; then
539                                               datadir=$withval
540                           fi
541                         ]
542 )
543 AC_DEFINE_UNQUOTED(DATADIR, "$datadir",[define, if the user suplied a data-directory to use.])
544
545 dnl Checks where to put our editor
546 AC_ARG_WITH(editordir, 
547                     [  --with-editordir             directory to put our editor],
548                         [ if test "x$withval" != "xno" ; then
549                                 editordir=$withval
550                           fi
551                         ]
552 )
553 AC_DEFINE_UNQUOTED(EDITORDIR, "$editordir", [where to find our mail editor])
554
555 abs_srcdir="`cd $srcdir && pwd`"
556 abs_builddir="`pwd`"
557 if test "$abs_srcdir" != "$abs_builddir"; then
558    CFLAGS="$CFLAGS -I $abs_builddir"
559 fi
560 AC_CONFIG_HEADER(sysdep.h)
561 AC_OUTPUT(Makefile po/webcit/Makefile tests/Makefile)
562
563 if test "$abs_srcdir" != "$abs_builddir"; then
564    ln -s $abs_srcdir/static $abs_builddir
565    ln -s $abs_srcdir/tiny_mce $abs_builddir
566    ln -s $abs_srcdir/*.h $abs_builddir
567    make mkdir-init
568    
569 else
570 dnl just run it on devel systems and if non vdir build.
571    if test -d .svn; then
572       ./mk_module_init.sh
573    fi
574 fi
575
576 if test -n "$srcdir"; then 
577    export srcdir=.
578 fi
579
580
581 echo ------------------------------------------------------------------------
582 echo 'Character set conversion support:' $ok_iconv
583 echo 'National language support:       ' $ok_nls
584 echo