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