Update config.guess and config.sub. Fix chdir() and -h in webcit
[citadel.git] / webcit / configure.ac
1 dnl Process this file with autoconf to produce a configure script.
2 dnl $Id$
3 AC_INIT([WebCit],m4_esyscmd_s([grep CLIENT_VERSION webcit.h | sed 's/[^0-9]*//g']),[http://uncensored.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(ssl,
27         [  --with-ssl=PATH         Specify path to OpenSSL installation ],
28         [
29                 if test "x$withval" != "xno" ; then
30                         tryssldir=$withval
31                 fi
32         ]
33 )
34 dnl Set some system-specific variables which are OK to set before compiler
35 dnl checks:
36 PTHREAD_DEFS=-D_REENTRANT
37 case "$host" in
38         dnl Tru64 Unix requires we use -pthread instead of linking the threads
39         dnl libraries directly, and we can't build threaded programs with gcc
40         dnl due to header file problems.
41         alpha*-dec-osf*)
42                 test -z "$CC" && CC=cc
43                 LIBS=-pthread
44         ;;
45         dnl FreeBSD is similar:
46         *-*-freebsd*)
47                 LIBS=-pthread
48                 PTHREAD_DEFS=-D_THREAD_SAFE
49         ;;
50         *-*-solaris*)
51                 PTHREAD_DEFS='-D_REENTRANT -D_PTHREADS'
52         ;;
53         *-*-darwin*)
54                 LIBS=-lintl
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 dnl                     CFLAGS="$CFLAGS -Wall -Wno-char-subscripts --pedantic"
66                         CFLAGS="$CFLAGS -Wall -Wno-char-subscripts"
67                 ;;
68                 *)
69 dnl                     CFLAGS="$CFLAGS -Wall --pedantic"
70                         CFLAGS="$CFLAGS -Wall"
71                 ;;
72         esac
73 fi
74
75 # missing_dir=`cd $ac_aux_dir && pwd`
76 # AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
77
78 dnl Checks for libraries.
79 if test "$LIBS" != -pthread; then
80         AC_CHECK_LIB(pthread, pthread_create)
81         AC_CHECK_LIB(pthreads, pthread_create)
82 fi
83 AC_SEARCH_LIBS(gethostbyname, nsl)
84 AC_SEARCH_LIBS(connect, socket)
85
86 dnl Checks for header files.
87 AC_HEADER_STDC
88 dnl AC_HEADER_SYS_WAIT
89
90 AC_CHECK_FUNCS(crypt gethostbyname connect flock getpwnam_r getpwuid_r getloadavg)
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 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 AC_CHECK_LIB(intl, libintl_bindtextdomain, [LDFLAGS="$LDFLAGS -lintl"])
218
219
220 dnl Checks for the libical iCalendar library.
221 AC_CHECK_HEADER(libical/ical.h,
222         [AC_CHECK_LIB(ical, icaltimezone_set_tzid_prefix,
223                 [
224                         LIBS="-lical $LIBS"
225                 ],
226                 [
227                         AC_MSG_ERROR(libical was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
228                 ]
229         ,
230         )],
231         [
232                 AC_MSG_ERROR(libical/ical.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
233         ]
234 )
235
236 dnl Checks for the discount markdown library.
237 AC_CHECK_LIB(markdown,
238          markdown,
239          [
240          LIBS="$LIBS -lmarkdown"
241          AC_DEFINE(HAVE_MARKDOWN,[],[whether we have markdown message rendering])
242 ])
243
244 dnl Check for libcitadel
245 AC_CHECK_HEADER(libcitadel.h,
246         [AC_CHECK_LIB(citadel, libcitadel_version_string,
247                 [
248                         LIBS="-lcitadel $LIBS"
249                         SETUP_LIBS="-lcitadel $SETUP_LIBS"
250                 ],
251                 [
252                         AC_MSG_ERROR(libcitadel was not found or is not usable.  Please install libcitadel.)
253                 ]
254         ,
255         )],
256         [
257                 AC_MSG_ERROR(libcitadel.h was not found or is not usable.  Please install libcitadel.)
258         ]
259 )
260
261 AC_MSG_CHECKING([whether your system likes memcpy + HKEY]) 
262 AC_TRY_COMPILE([
263 #define _GNU_SOURCE
264 #include <ctype.h>
265 #include <errno.h>
266 #include <string.h>
267 #include <unistd.h>
268 #include <string.h>
269 #include <stdio.h>
270 #include <sys/select.h>
271 #include <fcntl.h>
272 #include <sys/types.h>
273
274 #include "lib/libcitadel.h"
275 ],
276 [
277         char foo[22];
278         memcpy(foo, HKEY("foo"));
279         
280 ],
281                 [
282
283                   AC_MSG_RESULT([yes])
284                 ],
285                 [ 
286                   AC_DEFINE(UNDEF_MEMCPY, [], [whether we need to undefine memcpy])
287                   AC_MSG_RESULT([no])
288                 ]
289 )
290
291 dnl Checks for the Expat XML parser.
292 AC_CHECK_HEADER(expat.h,
293         [AC_CHECK_LIB(expat, XML_ParserCreateNS,
294                 [
295                         LIBS="-lexpat $LIBS"
296                 ],
297                 [
298                         AC_MSG_ERROR(The Expat XML parser was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
299                 ]
300         ,
301         )],
302         [
303                 AC_MSG_ERROR(expat.h was not found and is required.  More info: http://www.citadel.org/doku.php/installation:start)
304         ]
305 )
306
307
308
309 found_ssl=no
310 # The big search for OpenSSL
311 if test "$with_ssl" != "no"; then
312         saved_LIBS="$LIBS"
313         saved_LDFLAGS="$LDFLAGS"
314         saved_CFLAGS="$CFLAGS"
315         if test "x$prefix" != "xNONE"; then
316                 tryssldir="$tryssldir $prefix"
317         fi
318         AC_CACHE_CHECK([for OpenSSL], ac_cv_openssldir, [
319                 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
320                         CFLAGS="$saved_CFLAGS"
321                         LDFLAGS="$saved_LDFLAGS"
322                         LIBS="$saved_LIBS -lssl -lcrypto"
323         
324                         # Skip directories if they don't exist
325                         if test ! -z "$ssldir" -a ! -d "$ssldir" ; then
326                                 continue;
327                         fi
328                         if test ! -z "$ssldir" -a "x$ssldir" != "x/usr"; then
329                                 # Try to use $ssldir/lib if it exists, otherwise
330                                 # $ssldir
331                                 if test -d "$ssldir/lib" ; then
332                                         LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
333                                         if test ! -z "$need_dash_r" ; then
334                                                 LDFLAGS="-R$ssldir/lib $LDFLAGS"
335                                         fi
336                                 else
337                                         LDFLAGS="-L$ssldir $saved_LDFLAGS"
338                                         if test ! -z "$need_dash_r" ; then
339                                                 LDFLAGS="-R$ssldir $LDFLAGS"
340                                         fi
341                                 fi
342                                 # Try to use $ssldir/include if it exists, otherwise
343                                 # $ssldir
344                                 if test -d "$ssldir/include" ; then
345                                         CFLAGS="-I$ssldir/include $saved_CFLAGS"
346                                 else
347                                         CFLAGS="-I$ssldir $saved_CFLAGS"
348                                 fi
349                         fi
350         
351                         # Basic test to check for compatible version and correct linking
352                         # *does not* test for RSA - that comes later.
353                         AC_TRY_RUN(
354                                 [
355         #include <string.h>
356         #include <openssl/rand.h>
357         int main(void)
358         {
359                 char a[2048];
360                 memset(a, 0, sizeof(a));
361                 RAND_add(a, sizeof(a), sizeof(a));
362                 return(RAND_status() <= 0);
363         }
364                                 ],
365                                 [
366                                         found_crypto=1
367                                         break;
368                                 ], []
369                         )
370         
371                         if test ! -z "$found_crypto" ; then
372                                 break;
373                         fi
374                 done
375         
376                 if test -z "$ssldir" ; then
377                         ssldir="(system)"
378                 fi
379         
380                 if test ! -z "$found_crypto" ; then
381                         ac_cv_openssldir=$ssldir
382                 else
383                         ac_cv_openssldir="no"
384                 fi
385         ])
386         LIBS="$saved_LIBS"
387         LDFLAGS="$saved_LDFLAGS"
388         CFLAGS="$saved_CFLAGS"
389         
390         if test "x$ac_cv_openssldir" != "xno" ; then
391                 AC_DEFINE(HAVE_OPENSSL,[],[whethe we have openssl])
392                 found_ssl=yes
393                 LIBS="-lssl -lcrypto $LIBS"
394                 dnl Need to recover ssldir - test above runs in subshell
395                 ssldir=$ac_cv_openssldir
396                 if test ! -z "$ssldir" -a "x$ssldir" != "x/usr" -a "x$ssldir" != "x(system)"; then
397                         # Try to use $ssldir/lib if it exists, otherwise
398                         # $ssldir
399                         if test -d "$ssldir/lib" ; then
400                                 LDFLAGS="-L$ssldir/lib $saved_LDFLAGS"
401                                 if test ! -z "$need_dash_r" ; then
402                                         LDFLAGS="-R$ssldir/lib $LDFLAGS"
403                                 fi
404                         else
405                                 LDFLAGS="-L$ssldir $saved_LDFLAGS"
406                                 if test ! -z "$need_dash_r" ; then
407                                         LDFLAGS="-R$ssldir $LDFLAGS"
408                                 fi
409                         fi
410                         # Try to use $ssldir/include if it exists, otherwise
411                         # $ssldir
412                         if test -d "$ssldir/include" ; then
413                                 CFLAGS="-I$ssldir/include $saved_CFLAGS"
414                         else
415                                 CFLAGS="-I$ssldir $saved_CFLAGS"
416                         fi
417                 fi
418         fi
419 fi
420 dnl Checks for the SSLdir
421 dnl this is a bit different than the rest, 
422 dnl because of the citadel used to have a keys/ subdir.
423 AC_ARG_WITH(ssldir, 
424                     [  --with-ssldir          directory to store the ssl certificates under],
425                         [ if test "x$withval" != "xno" ; then
426                                               
427                                                   ssl_dir="$withval"
428                                                   if test "$found_ssl" = "no"; then
429                                                      echo "Your setup was incomplete; ssldir doesn't make sense without openssl"
430                                                      exit
431                                                   fi
432                           fi
433                         AC_SUBST(MAKE_SSL_DIR)
434                         ]
435 )
436 AC_DEFINE_UNQUOTED(SSL_DIR, "$ssl_dir", [were should we put our keys?])
437
438
439
440
441 AC_CHECK_FUNCS(strftime_l uselocale gettext)
442
443 if test "$ok_nls" != "no"; then
444         AC_CHECK_PROG(ok_xgettext, xgettext, yes, no)
445         ok_nls=$ok_xgettext
446 fi
447
448 if test "$ok_nls" != "no"; then
449         AC_CHECK_PROG(ok_msgmerge, msgmerge, yes, no)
450         ok_nls=$ok_msgmerge
451 fi
452
453 if test "$ok_nls" != "no"; then
454         AC_CHECK_PROG(ok_msgfmt, msgfmt, yes, no)
455         ok_nls=$ok_msgfmt
456 fi
457
458 if test "$ok_nls" != "no"; then
459         AC_MSG_RESULT(WebCit will be built with national language support.)
460         AC_DEFINE(ENABLE_NLS, [], [whether we have NLS support])
461         PROG_SUBDIRS="$PROG_SUBDIRS po/webcit/"
462 else
463         AC_MSG_RESULT(WebCit will be built without national language support.)
464 fi
465
466 AC_SUBST(SETUP_LIBS)
467
468 dnl disable backtrace if we don't want it.
469 AC_ARG_WITH(gprof, 
470                     [  --with-gprof          enable profiling],
471                         [ if test "x$withval" != "xno" ; then
472                              CFLAGS="$CFLAGS  -pg "
473                              LDFLAGS="$LDFLAGS  -pg "
474                           fi
475                         ]
476 )
477
478 dnl disable backtrace if we don't want it.
479 AC_ARG_WITH(backtrace, 
480                     [  --with-backtrace          enable backtrace dumps in the syslog],
481                         [ if test "x$withval" != "xno" ; then
482                              CFLAGS="$CFLAGS  -rdynamic "
483                              LDFLAGS="$LDFLAGS  -rdynamic "
484                              AC_CHECK_FUNCS(backtrace)
485                           fi
486                         ]
487 )
488
489 if test "$prefix" = NONE; then
490         datadir=$ac_default_prefix
491         localedir=$ac_default_prefix
492         wwwdir=$ac_default_prefix
493         rundir=$ac_default_prefix
494         editordir=$ac_default_prefix/tiny_mce
495         markdowneditordir=$ac_default_prefix/epic
496         etcdir=$ac_default_prefix
497 else
498         localedir=$prefix
499         wwwdir=$prefix
500         datadir=$prefix
501         rundir=$prefix
502         editordir=$prefix/tiny_mce
503         markdowneditordir=$prefix/epic
504         etcdir=$prefix
505 fi
506
507 dnl where to put the locale files
508 AC_ARG_WITH(localedir, 
509                     [  --with-localedir          directory to put the locale files to],
510                         [ if test "x$withval" != "xno" ; then
511                             localedir=$withval
512                           fi
513                         ]
514 )
515 AC_DEFINE_UNQUOTED(LOCALEDIR, "$localedir",[where to find our pot files])
516 LOCALEDIR=$localedir
517 AC_SUBST(LOCALEDIR)
518
519 dnl Checks where to put our templates
520 AC_ARG_WITH(wwwdir, 
521                     [  --with-wwwdir             directory to put our templates],
522                         [ if test "x$withval" != "xno" ; then
523                                 wwwdir=$withval
524                           fi
525                         ]
526 )
527 AC_DEFINE_UNQUOTED(WWWDIR, "$wwwdir", [where to find our templates and pics])
528 WWWDIR=$wwwdir
529 AC_SUBST(WWWDIR)
530
531
532 dnl Checks for the run-dir for the sockets
533 AC_ARG_WITH(rundir, 
534                         [  --with-rundir           directory to place runtime files (UDS) to?],
535                         [ if test "x$withval" != "xno" ; then
536                                             AC_DEFINE(HAVE_RUN_DIR, [], [should we put our non volatile files elsewhere?])
537                                                 
538                                                 rundir=$withval
539                                                 AC_SUBST(MAKE_RUN_DIR)
540                           fi
541                         ]
542 )
543 AC_DEFINE_UNQUOTED(RUNDIR, "$rundir", [define, where the config should go in unix style])
544
545 dnl Checks for the Datadir
546 AC_ARG_WITH(datadir, 
547                     [  --with-datadir          directory to store the databases under],
548                         [ if test "x$withval" != "xno" ; then
549                                               datadir=$withval
550                           fi
551                         ]
552 )
553 AC_DEFINE_UNQUOTED(DATADIR, "$datadir",[define, if the user suplied a data-directory to use.])
554
555 dnl Checks where to put our editor
556 AC_ARG_WITH(editordir, 
557                     [  --with-editordir             directory to put our editor],
558                         [ if test "x$withval" != "xno" ; then
559                                 editordir=$withval
560                           fi
561                         ]
562 )
563
564 dnl Checks where to find our configs
565 AC_ARG_WITH(etcdir, 
566                     [  --with-etcdir             directory to read our configs],
567                         [ if test "x$withval" != "xno" ; then
568                                 etcdir=$withval
569                           fi
570                         ]
571 )
572 AC_DEFINE_UNQUOTED(ETCDIR, "$etcdir", [where to find our configs])
573 ETCDIR=$etcdir
574 AC_SUBST(ETCDIR)
575
576 abs_srcdir="`cd $srcdir && pwd`"
577 abs_builddir="`pwd`"
578 if test "$abs_srcdir" != "$abs_builddir"; then
579    CFLAGS="$CFLAGS -I $abs_builddir"
580 fi
581 AC_CONFIG_HEADER(sysdep.h)
582 AC_OUTPUT(Makefile po/webcit/Makefile tests/Makefile)
583
584 if test "$abs_srcdir" != "$abs_builddir"; then
585    ln -s $abs_srcdir/static $abs_builddir
586    ln -s $abs_srcdir/tiny_mce $abs_builddir
587    ln -s $abs_srcdir/epic $abs_builddir
588    ln -s $abs_srcdir/*.h $abs_builddir
589    make mkdir-init
590    
591 else
592 dnl just run it on devel systems and if non vdir build.
593    if test -d .svn; then
594       ./mk_module_init.sh
595    fi
596 fi
597
598 if test -n "$srcdir"; then 
599    export srcdir=.
600 fi
601
602
603 echo ------------------------------------------------------------------------
604 echo 'Character set conversion support:' $ok_iconv
605 echo 'National language support:       ' $ok_nls
606 echo