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