1dnl Process this file with autoconf to produce a configure script.
2
3dnl
4dnl Copyright (c) 1994-2008 Carnegie Mellon University.  All rights reserved.
5dnl
6dnl Redistribution and use in source and binary forms, with or without
7dnl modification, are permitted provided that the following conditions
8dnl are met:
9dnl
10dnl 1. Redistributions of source code must retain the above copyright
11dnl    notice, this list of conditions and the following disclaimer.
12dnl
13dnl 2. Redistributions in binary form must reproduce the above copyright
14dnl    notice, this list of conditions and the following disclaimer in
15dnl    the documentation and/or other materials provided with the
16dnl    distribution.
17dnl
18dnl 3. The name "Carnegie Mellon University" must not be used to
19dnl    endorse or promote products derived from this software without
20dnl    prior written permission. For permission or any legal
21dnl    details, please contact
22dnl      Carnegie Mellon University
23dnl      Center for Technology Transfer and Enterprise Creation
24dnl      4615 Forbes Avenue
25dnl      Suite 302
26dnl      Pittsburgh, PA  15213
27dnl      (412) 268-7393, fax: (412) 268-7395
28dnl      innovation@andrew.cmu.edu
29dnl
30dnl 4. Redistributions of any form whatsoever must retain the following
31dnl    acknowledgment:
32dnl    "This product includes software developed by Computing Services
33dnl     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34dnl
35dnl CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
36dnl THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37dnl AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
38dnl FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
39dnl WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
40dnl AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
41dnl OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42dnl
43dnl configure.ac for the Cyrus imapd
44dnl
45
46
47AC_INIT([cyrus-imapd],
48        m4_esyscmd(printf '%s' $(tools/git-version.sh)),
49        [https://github.com/cyrusimap/cyrus-imapd/issues],
50        ,
51        [https://www.cyrusimap.org])
52AC_PREREQ([2.63])
53AC_CONFIG_SRCDIR([imap/imapd.c])
54AC_CONFIG_HEADERS(config.h)
55AC_CONFIG_MACRO_DIR([cmulocal])
56AC_CANONICAL_SYSTEM
57
58dnl carve the version string (defined in AC_INIT above) into useful chunks
59dnl e.g. for version 3.0.0-beta:
60dnl   CYRUS_IMAPD_SERIES   => 3.0
61dnl   CYRUS_IMAPD_REVISION => 0
62dnl   CYRUS_IMAPD_PATCH    => beta2
63CYRUS_IMAPD_SERIES=`echo AC_PACKAGE_VERSION | cut -d- -f1 | cut -d. -f1-2`
64CYRUS_IMAPD_REVISION=`echo AC_PACKAGE_VERSION | cut -d- -f1 | cut -d. -f3`
65CYRUS_IMAPD_PATCH=`echo AC_PACKAGE_VERSION | cut -d- -f2-`
66AC_SUBST([CYRUS_IMAPD_SERIES])
67AC_SUBST([CYRUS_IMAPD_REVISION])
68AC_SUBST([CYRUS_IMAPD_PATCH])
69
70dnl in case the first use of PKG_CHECK_MODULES is inside a conditional
71PKG_PROG_PKG_CONFIG
72
73AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability foreign dist-bzip2
74                  no-installinfo subdir-objects silent-rules tar-ustar])
75AC_CONFIG_LIBOBJ_DIR([lib])
76
77dnl Useful hook for distributions
78AC_ARG_WITH(extraident,
79        [AS_HELP_STRING([--with-extraident=STRING],[use STRING as extra version information])],
80        [AC_DEFINE_UNQUOTED(EXTRA_IDENT,"$withval", [Extra version information for imap/version.h])])
81
82AM_MAINTAINER_MODE
83
84dnl Coverage (disabled by default)
85GCOV_CFLAGS=
86GCOV_CXXFLAGS=
87GCOV_LDFLAGS=
88GCOV_LIBS=
89
90AC_ARG_ENABLE(coverage,
91    AS_HELP_STRING([--enable-coverage],[enable C test coverage])
92)
93
94AS_IF([test "x$enable_coverage" = "xyes"], [
95    GCOV_CFLAGS="--coverage"
96    GCOV_CXXFLAGS="--coverage"
97    GCOV_LDFLAGS="--coverage"
98    GCOV_LIBS="-lgcov"
99])
100AM_CONDITIONAL([HAVE_COVERAGE], [test "x$enable_coverage" = "xyes"])
101
102AC_SUBST(GCOV_CFLAGS)
103AC_SUBST(GCOV_CXXFLAGS)
104AC_SUBST(GCOV_LDFLAGS)
105AC_SUBST(GCOV_LIBS)
106
107AC_ARG_WITH(login,,AC_MSG_ERROR([--with-login is no longer supported.
108Configure SASL appropriately instead.]))
109
110AC_ARG_WITH(cyrus-user,
111        [AS_HELP_STRING([--with-cyrus-user=USERID], [use USERID cyrus userid])],
112        cyrus_user="$withval",cyrus_user="cyrus")
113AC_SUBST(cyrus_user)
114AC_DEFINE_UNQUOTED(CYRUS_USER, "$cyrus_user",[What user will we run as?])
115
116dnl allow users to override $sysconfdir, but retain old default (/etc)
117dnl if not specified
118if test $sysconfdir = '${prefix}/etc'; then
119  sysconfdir="/etc"
120fi
121
122dnl for some reason AC_PROG_CXX can succeed even though c++ compiler is missing
123dnl if it is invoked after AC_PROG_CC, so instead invoke it first
124dnl ref: https://lists.gnu.org/archive/html/bug-autoconf/2010-05/msg00001.html
125AC_PROG_CXX
126AC_PROG_CC
127AM_PROG_CC_C_O
128AC_PROG_LN_S
129AC_PROG_MAKE_SET
130AC_PROG_INSTALL
131AC_USE_SYSTEM_EXTENSIONS
132AC_ISC_POSIX
133AC_PROG_AWK
134AC_SYS_LONG_FILE_NAMES
135if test $ac_cv_sys_long_file_names = no; then
136        AC_MSG_ERROR(The Cyrus IMAPD requires support for long file names)
137fi
138AC_C_INLINE
139
140gl_VISIBILITY
141AH_BOTTOM([#if HAVE_VISIBILITY
142#define EXPORTED __attribute__((__visibility__("default")))
143#define HIDDEN   __attribute__((__visibility__("hidden")))
144#else
145#define EXPORTED
146#define HIDDEN
147#endif])
148
149AH_BOTTOM([#if defined __GNUC__ &&  __GNUC__ > 6
150    #define GCC_FALLTHROUGH __attribute__((fallthrough));
151#else
152    #define GCC_FALLTHROUGH /* fall through */
153#endif
154])
155
156LT_PREREQ([2.2.6])
157LT_INIT([disable-static])
158AC_SUBST([LIBTOOL_DEPS])
159
160dnl Check the size of various types
161AC_CHECK_SIZEOF(int)
162AC_CHECK_SIZEOF(long)
163AC_CHECK_SIZEOF(size_t)
164AC_CHECK_SIZEOF(off_t)
165AC_CHECK_SIZEOF(time_t)
166
167dnl Check that `long long int' is available
168AC_CHECK_SIZEOF(long long int)
169AC_CHECK_SIZEOF(unsigned long long int)
170if test "$ac_cv_sizeof_long_long_int" -eq 8 -a \
171        "$ac_cv_sizeof_unsigned_long_long_int" -eq 8; then
172  AC_C_BIGENDIAN
173else
174  AC_MSG_ERROR(The Cyrus IMAPD requires support for long long int)
175fi
176
177dnl check for -R, etc. switch
178CMU_GUESS_RUNPATH_SWITCH
179
180AC_CHECK_HEADERS(unistd.h sys/select.h sys/param.h stdarg.h)
181AC_REPLACE_FUNCS(memmove strcasecmp ftruncate strerror posix_fadvise strsep memmem)
182AC_CHECK_FUNCS(strlcat strlcpy strnchr getgrouplist fmemopen pselect getline)
183AC_HEADER_DIRENT
184
185dnl check whether to use getpassphrase or getpass
186AC_CHECK_HEADERS(stdlib.h)
187AC_CHECK_FUNCS(getpassphrase)
188
189dnl do this before Berkeley DB/IPv6 detection
190CMU_SOCKETS
191LIBS="$LIBS ${LIB_SOCKET}"
192
193dnl check for IPv6 functions (fall back to sasl's if we don't have them)
194cyrus_cv_getaddrinfo=yes
195IPv6_CHECK_FUNC(getaddrinfo, [IPv6_CHECK_FUNC(gai_strerror,
196        AC_DEFINE(HAVE_GETADDRINFO,[],[Do we have a getaddrinfo?]),
197        cyrus_cv_getaddrinfo=no)], cyrus_cv_getaddrinfo=no)
198
199cyrus_cv_getnameinfo=yes
200IPv6_CHECK_FUNC(getnameinfo,
201        AC_DEFINE(HAVE_GETNAMEINFO,[],[Do we have a getnameinfo?]),
202        cyrus_cv_getnameinfo=no)
203
204AM_CONDITIONAL([IPV6_noGETADDRINFO], [test $cyrus_cv_getaddrinfo = no])
205AM_CONDITIONAL([IPV6_noGETNAMEINFO], [test $cyrus_cv_getnameinfo = no])
206IPv6_CHECK_SS_FAMILY()
207IPv6_CHECK_SA_LEN()
208
209dnl this is to check for time things
210AC_CHECK_HEADERS(sys/time.h)
211AC_HEADER_TIME
212AC_STRUCT_TM
213AC_STRUCT_TIMEZONE
214AC_CHECK_FUNCS(timegm)
215
216AC_SUBST(CPPFLAGS)
217AC_SUBST(LOCALDEFS)
218AC_FUNC_VPRINTF
219
220dnl function for doing each of the database backends
221dnl parameters: backend name, variable to set, withval
222
223dnl SQL DB Detection
224
225HAVE_CYRUSDB_SQL=0
226
227dnl MySQL Detection
228
229dnl legacy options --with-mysql-libdir and --with-mysql-incdir
230CYRUS_MYSQL_OPTS
231if test "$with_mysql_lib" != none ; then
232    AC_MSG_NOTICE([Legacy option --with-mysql-libdir=DIR detected.]
233                  [You may wish to change to --with-mysql which works now.])
234    withval="$with_mysql_lib/.."
235else
236    withval="no"
237fi
238
239AC_MSG_CHECKING([whether to use MySQL])
240AC_ARG_WITH(mysql,
241        [AS_HELP_STRING([--with-mysql=DIR], [use MySQL (in DIR) [no]])])
242with_mysql=$withval
243
244case "$with_mysql" in
245  no)
246        # Explicitly disable MySQL
247        ;;
248  yes)
249        # Find mysql_config in $PATH
250        AC_PATH_PROG(mysql_config, mysql_config, [])
251        AS_IF([test -z "$mysql_config"],
252            AC_MSG_ERROR([The mysql_config program was not found]))
253        ;;
254  *)
255        # Find mysql_config in the specified directory
256        mysql_config="$with_mysql/bin/mysql_config"
257        if test ! -x "$mysql_config" ; then
258            AC_MSG_ERROR([The mysql_config program was not found]
259                         [in $with_mysql/bin, disabling MySQL support])
260            with_mysql="no"
261        fi
262        ;;
263esac
264
265if test "$with_mysql" != "no"; then
266    MYSQL_LIBADD=`$mysql_config --libs`
267    MYSQL_INCADD=`$mysql_config --cflags`
268    HAVE_CYRUSDB_SQL=1
269    LIBS="${LIBS} ${MYSQL_LIBADD}"
270    CPPFLAGS="${MYSQL_INCADD} ${CPPFLAGS}"
271    AC_DEFINE(HAVE_MYSQL,[],[Build in MySQL support?])
272    AC_SUBST(MYSQL_LIBADD)
273fi
274AC_MSG_RESULT($with_mysql)
275
276dnl End MySQL Detection
277
278
279dnl PgSQL Detection
280AC_ARG_WITH(pgsql,
281        [AS_HELP_STRING([--with-pgsql=DIR], [use PostgreSQL (in DIR) [no]])],
282        with_pgsql=$withval, with_pgsql="no")
283
284case "$with_pgsql" in
285  no)
286        use_pgsql="no"
287        ;;
288  yes)
289        use_pgsql="yes"
290        with_pgsql_lib=none
291        with_pgsql_inc=none
292        ;;
293  *)
294        use_pgsql="yes"
295        with_pgsql_lib="$with_pgsql/lib"
296        with_pgsql_inc="$with_pgsql/include"
297        ;;
298esac
299
300if test "$use_pgsql" != "no"; then
301  CYRUS_PGSQL_CHK()
302
303  if test "$pgsqllib" = "no"; then
304    AC_MSG_ERROR([PgSQL was not found.  You may need to supply the
305    --with-pgsql-libdir or --with-pgsql-incdir configure options.])
306  else
307    HAVE_CYRUSDB_SQL=1
308  fi
309
310  if test "$with_pgsql_lib" != "none"; then
311    CMU_ADD_LIBPATH($with_pgsql_lib)
312  fi
313
314  LIBS="${LIBS} ${PGSQL_LIBADD}"
315  CPPFLAGS="${PGSQL_INCADD} ${CPPFLAGS}"
316
317  AC_DEFINE(HAVE_PGSQL,[],[Build in PgSQL support?])
318  AC_SUBST(PGSQL_LIBADD)
319fi
320
321dnl End PgSQL Detection
322
323
324dnl SQLite Detection
325dnl XXX this is a bit gross... the same option for specifying WHERE sqlite is
326dnl (--with-sqlite) is also the option for enabling it as a cyrusdb backend,
327dnl which means if your sqlite is in a non-default location and you need httpd
328dnl or object storage etc, you're suddenly also supporting it as a cyrusdb
329dnl backend, possibly unexpectedly.
330AC_ARG_WITH(sqlite,
331        [AS_HELP_STRING([--with-sqlite=DIR], [use SQLite (in DIR) [no]])],
332        with_sqlite=$withval, with_sqlite=check)
333
334case "$with_sqlite" in
335  no)
336        use_sqlite="no"
337        ;;
338  yes)
339        use_sqlite="yes"
340        with_sqlite_lib=none
341        with_sqlite_inc=none
342        ;;
343  check)
344        use_sqlite="check"
345        with_sqlite_lib=none
346        with_sqlite_inc=none
347        ;;
348  *)
349        use_sqlite="yes"
350        with_sqlite_lib="$with_sqlite/lib"
351        with_sqlite_inc="$with_sqlite/include"
352        ;;
353esac
354
355if test "$use_sqlite" != "no"; then
356  CYRUS_SQLITE_CHK()
357
358  if test "$use_sqlite" = "yes"; then
359    dnl sqlite specifically requested: not found is a failure
360    if test "$sqlitelib" = "no"; then
361        AC_MSG_ERROR([Sqlite was not found.  You may need to supply the
362        --with-sqlite-libdir or --with-sqlite-incdir configure options.])
363    else
364        HAVE_CYRUSDB_SQL=1
365        HAVE_SQLITE=1
366    fi
367  else
368    dnl sqlite not specifically requested: not found isn't a failure (yet)
369    use_sqlite="no"
370    if test "$sqlitelib" = "no"; then
371        AC_MSG_NOTICE([sqlite was not found, will try to build without it])
372    else
373        HAVE_SQLITE=1
374    fi
375  fi
376
377  dnl other modules might yet need to link against sqlite.
378  dnl we will update LIBS/CPPFLAGS etc later, once their checks have run.
379  dnl for now:
380  dnl   * $use_sqlite = "yes" if we definitely need it
381  dnl   * $HAVE_SQLITE = 1 if we have it available
382fi
383
384dnl End SQLite Detection
385
386if test "x$HAVE_CYRUSDB_SQL" = x1; then
387    AC_DEFINE([USE_CYRUSDB_SQL],[],[Build in cyrusdb_sql support?])
388fi
389AM_CONDITIONAL([USE_CYRUSDB_SQL], [test $HAVE_CYRUSDB_SQL = 1])
390dnl End SQL DB Detection
391
392dnl LMDB configuration
393AC_ARG_WITH(lmdb,
394        [AS_HELP_STRING([--with-lmdb], [use LMDB backend [no]])],
395        with_lmdb="$withval", with_lmdb="no")
396if test "$with_lmdb" = "yes"; then
397  AC_CHECK_LIB(lmdb,mdb_env_create,
398      use_lmdb="yes"
399      LMDB_LIB="-llmdb"
400      AC_DEFINE([HAVE_LMDB],[],[Build in cyrusdb_lmdb support?]),
401      AC_MSG_ERROR([The LMDB library is required for Cyrus DB LMDB support.]))
402else
403    use_lmdb="no"
404fi
405AM_CONDITIONAL([USE_CYRUSDB_LMDB], [test "x$use_lmdb" = "xyes"])
406
407dnl
408dnl Object Store support
409dnl
410
411dnl Caringo object store backend
412AC_MSG_CHECKING([whether to use Caringo])
413AC_ARG_WITH(caringo,
414        [AS_HELP_STRING([--with-caringo], [use Caringo ("yes" or "no")])],,with_caringo="no")
415case "$with_caringo" in
416  yes)
417	LDFLAGS="$LDFLAGS -lCastorSDK"
418  ;;
419esac
420AC_MSG_RESULT([$with_caringo])
421
422dnl OpenIO object store backend
423dnl deps: metautils gridclient oiosds curl
424AC_MSG_CHECKING([whether to use OpenIO])
425AC_ARG_WITH(openio,
426        [AS_HELP_STRING([--with-openio=yes|no], [use OpenIO ("yes" or "no")])],
427        with_openio=$withval, with_openio="no")
428
429case "$with_openio" in
430  no)
431	use_openio="no"
432	;;
433  yes)
434	use_openio="yes"
435	with_openio_lib=none
436	with_openio_inc=none
437	AC_DEFINE([WITH_OPENIO],[1],[Enable support for OpenIO object storage.])
438	;;
439  *)
440	use_openio="yes"
441	with_openio_lib="$with_openio/lib64"
442	with_openio_inc="$with_openio/include"
443	AC_DEFINE([WITH_OPENIO],[1],[Enable support for OpenIO object storage.])
444	;;
445esac
446
447AC_ARG_WITH(openio-libdir,
448        [AS_HELP_STRING([--with-openio-libdir=DIR], [OpenIO lib files are in DIR])],
449        with_openio_lib=$withval,
450        [ test "${with_openio_lib+set}" = set || with_openio_lib=none])
451AC_ARG_WITH(openio-incdir,
452        [AS_HELP_STRING([--with-openio-incdir=DIR], [OpenIO include files are in DIR])],
453        with_openio_inc=$withval,
454        [ test "${with_openio_inc+set}" = set || with_openio_inc=none ])
455
456if test "$use_openio" = "yes"; then
457	if test ! -d "$with_openio_lib"; then
458		AC_MSG_ERROR([OpenIO library directory '$with_openio_lib' does not exist.])
459	fi
460	if test ! -d "$with_openio_inc"; then
461		AC_MSG_ERROR([OpenIO include directory '$with_openio_inc' does not exist.])
462	fi
463
464	LDFLAGS="$LDFLAGS -L$with_openio_lib"
465	CFLAGS="$CFLAGS -I$with_openio_inc"
466	openio_headers="oio_sds.h core/oiourl.h"
467	for h in $openio_headers; do
468		AC_CHECK_HEADER($h,[],[
469			AC_MSG_ERROR([Header $h is missing.])
470		])
471	done
472	AC_CHECK_LIB([oiosds],[oio_error_free],[],[AC_MSG_ERROR([Library oiosds not found.])])
473	AC_CHECK_LIB([oiocore],[oio_url_empty],[],[AC_MSG_ERROR([Library oiocore not found.])])
474	AC_CHECK_LIB([curl],[curl_version],[],[AC_MSG_ERROR([Library curl not found.])])
475	AC_CHECK_LIB([json-c],[json_tokener_parse_ex],[],[AC_MSG_ERROR([Library json-c not found.])])
476
477	LDFLAGS="$LDFLAGS -L$with_openio_lib -loiosds -loiocore -lcurl -ljson-c"
478fi
479AC_MSG_RESULT([$use_openio])
480
481dnl enable object store
482AC_MSG_CHECKING([whether to enable object store])
483AC_ARG_ENABLE(objectstore,
484    [AS_HELP_STRING([--enable-objectstore],
485        [enable IMAP objectstore support. Use --with-caringo or --with-openio to choose a backend])],
486    [],
487    [enable_objectstore=no])
488
489with_objectstore_dummy=no
490if test "x$enable_objectstore" != xno ; then
491    dnl we need sqlite for the objectstore database
492    if test "x$HAVE_SQLITE" != x1; then
493        AC_MSG_ERROR([Need sqlite3 for objectstore])
494    else
495        use_sqlite="yes"
496    fi
497
498    dnl arbitrarily prioritise OpenIO over Caringo if both are requested
499    AS_IF(
500        [test "x$with_openio" != xno -a "x$with_caringo" != xno],
501            [AC_MSG_WARN([both --with-openio and --with-caringo requested: using OpenIO])
502             enable_objectstore="openio"
503             with_caringo = "no"],
504        [test "x$with_openio" != xno],
505            [enable_objectstore="openio"],
506        [test "x$with_caringo" != xno],
507            [enable_objectstore="caringo"],
508        [enable_objectstore="dummy"
509         with_objectstore_dummy="yes"])
510    AC_DEFINE([ENABLE_OBJECTSTORE],[],[Build with Object Store support])
511fi
512AC_MSG_RESULT([$enable_objectstore])
513AM_CONDITIONAL([OBJECTSTORE], [test "x$enable_objectstore" != xno])
514AM_CONDITIONAL([WITH_CARINGO], [test "x$with_caringo" != xno])
515AM_CONDITIONAL([WITH_OPENIO], [test "x$use_openio" != xno])
516AM_CONDITIONAL([WITH_OBJSTR_DUMMY], [test "x$with_objectstore_dummy" != xno])
517
518
519dnl
520dnl Search engines - SQUAT
521dnl
522
523AC_ARG_ENABLE(squat,
524    [AS_HELP_STRING([--disable-squat], [disable Squat support])],,[enable_squat="yes";])
525
526if test "$enable_squat" != "no"; then
527    AC_DEFINE(USE_SQUAT,[],[Build in Squat support?])
528fi
529
530AM_CONDITIONAL([USE_SQUAT], [test "${enable_squat}" != "no"])
531
532dnl
533dnl Search engines - Sphinx
534dnl
535
536AC_ARG_ENABLE(sphinx,
537        [AS_HELP_STRING([--enable-sphinx], [enable Sphinx support])],,
538        [enable_sphinx=no])
539if test "x$enable_sphinx" != xno ; then
540    AC_DEFINE(USE_SPHINX,[],[Build in Sphinx support?])
541fi
542AM_CONDITIONAL([USE_SPHINX], [test "${enable_sphinx}" != "no"])
543
544dnl Note that Sphinx' searchd uses the MySQL protocol
545dnl so we need to link with the MySQL client libraries.
546if test "$enable_sphinx" = yes -a "$with_mysql" = no ; then
547    AC_MSG_ERROR([Sphinx requires MySQL but you have not used --with-mysql; disabling Sphinx])
548    enable_sphinx=no
549fi
550
551dnl
552dnl Search engines - Xapian
553dnl
554
555xapian_flavor=none
556AC_ARG_ENABLE(xapian,
557        [AS_HELP_STRING([--enable-xapian], [enable Xapian support])],,
558        [enable_xapian=no])
559if test "x$enable_xapian" != xno ; then
560    AC_ARG_VAR(RM_BIN, [Location of rm])
561    AC_PATH_PROG(RM_BIN, [rm], [])
562    AS_IF([test -z "$RM_BIN"],[
563        AC_MSG_ERROR([Can't find the 'rm' binary])
564    ])
565    AC_DEFINE_UNQUOTED([RM_BIN], ["$RM_BIN"], [Path to 'rm' binary])
566
567    AC_ARG_VAR(RSYNC_BIN, [Location of rsync])
568    AC_PATH_PROG(RSYNC_BIN, [rsync], [])
569    AS_IF([test -z "$RSYNC_BIN"],[
570        AC_MSG_ERROR([Can't find the 'rsync' binary])
571    ])
572    AC_DEFINE_UNQUOTED([RSYNC_BIN], ["$RSYNC_BIN"], [Path to 'rsync' binary])
573
574    AC_ARG_VAR(XAPIAN_CONFIG, [Location of xapian-config])
575    AC_PATH_PROGS(XAPIAN_CONFIG, [xapian-config-1.5 xapian-config], [])
576    if test -z "$XAPIAN_CONFIG"; then
577        AC_MSG_ERROR([Can't find Xapian library])
578    else
579        AC_MSG_CHECKING([$XAPIAN_CONFIG works])
580        dnl check for --ltlibs but not --libs as xapian-config --libs will
581        dnl fail if xapian isn't installed...
582
583        dnl run with exec to avoid leaking output on "real" bourne shells
584        if (exec >&5 2>&5 ; $XAPIAN_CONFIG --ltlibs --cxxflags; exit $?) then
585            AC_MSG_RESULT(yes)
586        else
587            AC_MSG_ERROR([\`$XAPIAN_CONFIG --ltlibs --cxxflags' doesn't work, aborting])
588        fi
589
590        dnl Xapian requires CXX11
591        AX_CXX_COMPILE_STDCXX_11([noext], [mandatory])
592
593        dnl If AC_PROG_LIBTOOL (or the deprecated older version AM_PROG_LIBTOOL)
594        dnl has already been expanded, enable libtool support now, otherwise add
595        dnl hooks to the end of AC_PROG_LIBTOOL and AM_PROG_LIBTOOL to enable it
596        dnl if either is expanded later.
597        XAPIAN_VERSION="`$XAPIAN_CONFIG --version|sed 's/.* //'`"
598        XAPIAN_CXXFLAGS="`$XAPIAN_CONFIG --cxxflags`"
599        AC_PROVIDE_IFELSE([AC_PROG_LIBTOOL],
600            [XAPIAN_LIBS="`$XAPIAN_CONFIG --ltlibs`"],
601            [AC_PROVIDE_IFELSE([AM_PROG_LIBTOOL],
602                [XAPIAN_LIBS="`$XAPIAN_CONFIG --ltlibs`"],
603                dnl Pass magic option so xapian-config knows we called it (so it
604                dnl can choose a more appropriate error message if asked to link
605                dnl with an uninstalled libxapian). Also pass ac_top_srcdir
606                dnl so the error message can correctly say "configure.ac" or
607                dnl "configure.in" according to which is in use.
608                [XAPIAN_LIBS="`ac_top_srcdir=\"$ac_top_srcdir\" $XAPIAN_CONFIG --from-xo-lib-xapian --libs`"
609                define([AC_PROG_LIBTOOL], defn([AC_PROG_LIBTOOL])
610                       [XAPIAN_LIBS="`$XAPIAN_CONFIG --ltlibs`"])
611                define([AM_PROG_LIBTOOL], defn([AM_PROG_LIBTOOL])
612                       [XAPIAN_LIBS="`$XAPIAN_CONFIG --ltlibs`"])])])
613        AC_DEFINE(USE_XAPIAN,[],[Build in Xapian support?])
614
615        dnl check if Xapian supports Cyruslibs extensions
616        AC_LANG_PUSH([C++])
617        ORIG_LDFLAGS=$LDFLAGS
618        ORIG_CXXFLAGS=$CXXFLAGS
619        LDFLAGS="$LDFLAGS $XAPIAN_LIBS"
620        CXXFLAGS="$CXXFLAGS $XAPIAN_CXXFLAGS"
621        AC_MSG_CHECKING([for Xapian cyruslibs extensions])
622        AC_LINK_IFELSE(
623            [AC_LANG_PROGRAM(
624                [[#include <xapian.h>]],
625                [[unsigned cjk_flags = Xapian::TermGenerator::FLAG_CJK_WORDS | Xapian::QueryParser::FLAG_CJK_WORDS; unsigned snippet_flags = Xapian::MSet::SNIPPET_START_AT_NONSPACE; (void) cjk_flags; (void) snippet_flags]])],
626            [xapian_cyrusexts="yes"],
627            [xapian_cyrusexts="no"])
628        AC_MSG_RESULT($xapian_cyrusexts)
629        if test $xapian_cyrusexts = yes; then
630            AC_DEFINE([USE_XAPIAN_CYRUS_EXTENSIONS], [], [Use Xapian cyruslibs extensions?])
631            xapian_flavor=cyruslibs
632        else
633            AC_MSG_NOTICE([Your Xapian does not support the Cyrus extensions for Xapian. Consider installing cyruslibs Xapian])
634            xapian_flavor=vanilla
635        fi
636        LDFLAGS=$ORIG_LDFLAGS
637        CXXFLAGS=$ORIG_CXXFLAGS
638        AC_LANG_POP([C++])
639    fi
640    AC_SUBST(XAPIAN_CXXFLAGS)
641    AC_SUBST(XAPIAN_LIBS)
642    AC_SUBST(XAPIAN_VERSION)
643fi
644AM_CONDITIONAL([USE_XAPIAN], [test "${enable_xapian}" != "no"])
645AC_DEFINE_UNQUOTED([XAPIAN_FLAVOR], ["$xapian_flavor"], [Which Xapian are we running on?])
646
647
648AM_CONDITIONAL([SQUATTER],
649    [test "${enable_squat}" != "no" -o "${enable_sphinx}" != "no" -o "${enable_xapian}" != "no" ])
650
651AC_ARG_ENABLE(sieve,
652        [AS_HELP_STRING([--disable-sieve], [disable Sieve support])],,[enable_sieve="yes";])
653AC_ARG_ENABLE(pcre,
654        [AS_HELP_STRING([--disable-pcre], [disable PCRE library])],[cyrus_cv_pcre_utf8="no"])
655
656if test "$enable_sieve" != "no"; then
657        AC_DEFINE(USE_SIEVE,[],[Build in Sieve support?])
658
659        dnl Sieve configure stuff
660        AC_PROG_YACC
661        AM_PROG_LEX
662
663        if test -z "$ac_cv_prog_YACC"; then
664            AC_MSG_ERROR([Sieve requires bison/byacc/yacc, but none is installed])
665        fi
666
667        if test -z "$ac_cv_prog_LEX"; then
668            AC_MSG_ERROR([Sieve requires flex/lex, but none is installed])
669        fi
670fi
671
672AM_CONDITIONAL([SIEVE], [test "${enable_sieve}" != "no"])
673
674if test "$enable_pcre" != "no"; then
675        AC_CHECK_HEADER(pcreposix.h)
676        if test "$ac_cv_header_pcreposix_h" = "yes"; then
677            AC_MSG_CHECKING(for utf8 enabled pcre)
678            AC_CACHE_VAL(cyrus_cv_pcre_utf8, AC_TRY_CPP([#include <pcreposix.h>
679#ifndef REG_UTF8
680#include </nonexistent>
681#endif],cyrus_cv_pcre_utf8=yes,cyrus_cv_pcre_utf8=no))
682            AC_MSG_RESULT($cyrus_cv_pcre_utf8)
683        else
684            cyrus_cv_pcre_utf8="no"
685        fi
686fi
687
688if test "$cyrus_cv_pcre_utf8" = "yes"; then
689        LIBS="$LIBS -lpcre -lpcreposix";
690        AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?])
691        AC_DEFINE(HAVE_PCREPOSIX_H, [], [Do we have usable pcre library?])
692else
693        AC_CHECK_HEADERS(rxposix.h)
694        if test "$ac_cv_header_rxposix_h" = "yes"; then
695            LIBS="$LIBS -lrx"
696            AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?])
697        else
698            AC_SEARCH_LIBS(regcomp, regex,
699                           AC_DEFINE(ENABLE_REGEX, [], [Do we have a regex library?]), [])
700        fi
701fi
702
703dnl look for an option to disable sign-comparison warnings (needed for
704dnl flex-generated sieve sources when building with -Werror)
705saved_CFLAGS="$CFLAGS"
706NOWARN_SIGN_COMPARE="-Wno-sign-compare"
707CFLAGS="$NOWARN_SIGN_COMPARE"
708AC_MSG_CHECKING([whether the C compiler supports -Wno-sign-compare])
709AC_COMPILE_IFELSE(
710    [AC_LANG_PROGRAM([], [])],
711    [AC_MSG_RESULT([yes])],
712    [NOWARN_SIGN_COMPARE=]
713    [AC_MSG_RESULT([no])]
714)
715CFLAGS="$saved_CFLAGS"
716AC_SUBST([NOWARN_SIGN_COMPARE])
717
718dnl for et routines
719AC_FUNC_CHECK(strerror,AC_DEFINE(HAS_STRERROR,[],[Do we have strerror()?]),
720              AC_DEFINE(NEED_SYS_ERRLIST,[],[Do we have a sys_errlist?]))
721
722dnl for master fd limits
723AC_CHECK_HEADERS(sys/resource.h)
724AC_CHECK_FUNCS(setrlimit)
725AC_CHECK_FUNCS(getrlimit)
726
727dnl for detaching terminal
728AC_CHECK_FUNCS(daemon setsid)
729
730dnl for turning off sockets
731AC_CHECK_FUNCS(shutdown)
732
733AC_EGREP_HEADER(socklen_t, sys/socket.h, AC_DEFINE(HAVE_SOCKLEN_T,[],[Do we have a socklen_t?]))
734AC_EGREP_HEADER(sockaddr_storage, sys/socket.h,
735                AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE,[],[Do we have a sockaddr_storage?]))
736AC_EGREP_HEADER(rlim_t, sys/resource.h, AC_DEFINE(HAVE_RLIM_T,[],[Do we have an rlim_t?]))
737
738dnl Bunch of setproctitle stuff
739spt_type=""
740AC_CHECK_FUNC(setproctitle,spt_type=SPT_BUILTIN)
741if test "$spt_type" = ""; then
742        dnl BSD/OS and FreeBSD put it in -lutil
743        AC_CHECK_LIB(util,setproctitle,spt_type=SPT_BUILTIN
744                        LIBS="${LIBS} -lutil")
745fi
746if test "$spt_type" = ""; then
747        AC_CHECK_HEADER(sys/pstat.h,spt_type=SPT_PSTAT)
748fi
749if test "$spt_type" = ""; then
750        AC_CHECK_HEADER(sys/sysnews.h,spt_type=SPT_SYSMIPS)
751fi
752if test "$spt_type" = ""; then
753        AC_MSG_CHECKING(for PS_STRINGS)
754        AC_CACHE_VAL(cyrus_cv_sys_psstrings, AC_COMPILE_IFELSE([AC_LANG_SOURCE([
755#include <machine/vmparam.h>
756#include <sys/exec.h>
757void *p = PS_STRINGS;
758])],cyrus_cv_sys_psstrings=yes,cyrus_cv_sys_psstrings=no))
759         if test $cyrus_cv_sys_psstrings = yes; then
760                 spt_type=SPT_PSSTRINGS
761         fi
762         AC_MSG_RESULT($cyrus_cv_sys_psstrings)
763fi
764if test "$spt_type" = ""; then
765        AC_MSG_CHECKING(for SCO)
766        AC_CACHE_VAL(cyrus_cv_sys_sco, AC_TRY_CPP([
767#ifndef _SCO_unix_
768#include </nonexistent>
769#endif],cyrus_cv_sys_sco=yes,cyrus_cv_sys_sco=no))
770        if test $cyrus_cv_sys_sco = yes; then
771                spt_type=SPT_SCO
772        fi
773        AC_MSG_RESULT($cyrus_cv_sys_sco)
774fi
775if test "$spt_type" = ""; then
776        AC_MSG_CHECKING(for setproctitle usability)
777        AC_CACHE_VAL(cyrus_cv_sys_setproctitle, AC_TRY_CPP([
778#if defined(DGUX) || defined(_SEQUENT_) || defined(apollo)
779#include </nonexistent>
780#endif],cyrus_cv_sys_setproctitle=yes,cyrus_cv_sys_setproctitle=no))
781        if test $cyrus_cv_sys_setproctitle = no; then
782                spt_type=SPT_NONE
783        fi
784        AC_MSG_RESULT($cyrus_cv_sys_setproctitle)
785fi
786if test "$spt_type" != ""; then
787        AC_DEFINE_UNQUOTED(SPT_TYPE,$spt_type,[Do we already have setproctitle?])
788fi
789
790AC_MSG_CHECKING(nonblocking method)
791AC_CACHE_VAL(cyrus_cv_sys_nonblock,AC_TRY_LINK([#include <sys/types.h>
792#include <sys/file.h>
793#include <fcntl.h>
794#ifndef FNDELAY
795#define FNDELAY         O_NDELAY
796#endif],[fcntl(0, F_GETFL, 0)&FNDELAY],
797cyrus_cv_sys_nonblock=fcntl,cyrus_cv_sys_nonblock=ioctl))
798AM_CONDITIONAL([NONBLOCK_FCNTL], [test "$cyrus_cv_sys_nonblock" = "fcntl"])
799AC_MSG_RESULT($cyrus_cv_sys_nonblock)
800
801AC_MSG_CHECKING(timezone GMT offset method)
802AC_CACHE_VAL(cyrus_cv_struct_sys_gmtoff,AC_TRY_COMPILE([
803#include <time.h>],[struct tm tm;
804tm.tm_gmtoff = 0;
805],cyrus_cv_struct_sys_gmtoff=tm,cyrus_cv_struct_sys_gmtoff=gmtime))
806AM_CONDITIONAL([GMTOFF_TM], [test "$cyrus_cv_struct_sys_gmtoff" = "tm"])
807AC_MSG_RESULT($cyrus_cv_struct_sys_gmtoff)
808AC_MSG_CHECKING(for shared mmap)
809AC_CACHE_VAL(cyrus_cv_func_mmap_shared,AC_TRY_RUN([
810#include <fcntl.h>
811#include <string.h>
812#include <sys/mman.h>
813#include <sys/types.h>
814#include <unistd.h>
815int main() {
816    char *base;
817    int mmapflags = MAP_SHARED;
818    int fd = open("conftestmmap", O_RDWR|O_CREAT|O_TRUNC, 0666);
819    if (fd == -1) return 1;
820    if (write(fd, "test", 4) != 4) return 1;
821    fsync(fd);
822#ifdef MAP_FILE
823    mmapflags |= MAP_FILE;
824#endif
825#ifdef MAP_VARIABLE
826    mmapflags |= MAP_VARIABLE;
827#endif
828    base = mmap((caddr_t)0, 100, PROT_READ, mmapflags, fd, 0L);
829    if (base == (caddr_t)-1) return 1;
830    if (memcmp(base, "test", 4) != 0) return 1;
831    if (write(fd, "test", 4) != 4) return 1;
832    fsync(fd);
833    if (memcmp(base+4, "test", 4) != 0) return 1;
834    return 0;
835}
836],cyrus_cv_func_mmap_shared=yes,cyrus_cv_func_mmap_shared=no,
837cyrus_cv_func_mmap_shared=no))
838AC_MSG_RESULT($cyrus_cv_func_mmap_shared)
839if test $cyrus_cv_func_mmap_shared = yes; then
840        found_map="shared"
841else
842AC_MSG_CHECKING(for stupid shared mmap)
843AC_CACHE_VAL(cyrus_cv_func_mmap_stupidshared,AC_TRY_RUN([
844#include <fcntl.h>
845#include <string.h>
846#include <sys/mman.h>
847#include <sys/types.h>
848#include <unistd.h>
849int main() {
850    char *base;
851    int fd = open("conftestmmap", O_RDWR|O_CREAT|O_TRUNC, 0666);
852    int mmapflags = MAP_SHARED;
853    if (fd == -1) return 1;
854    if (write(fd, "test", 4) != 4) return 1;
855    fsync(fd);
856#ifdef MAP_FILE
857    mmapflags |= MAP_FILE;
858#endif
859#ifdef MAP_VARIABLE
860    mmapflags |= MAP_VARIABLE;
861#endif
862    base = mmap((caddr_t)0, 4, PROT_READ, mmapflags, fd, 0L);
863    if (base == (caddr_t)-1) return 1;
864    if (memcmp(base, "test", 4) != 0) return 1;
865    lseek(fd, 0L, 0);
866    if (write(fd, "xyzz", 4) != 4) return 1;
867    fsync(fd);
868    if (memcmp(base, "xyzz", 4) != 0) return 1;
869    return 0;
870}
871],cyrus_cv_func_mmap_stupidshared=yes,cyrus_cv_func_mmap_stupidshared=no,
872cyrus_cv_func_mmap_stupidshared=no))
873AC_MSG_RESULT($cyrus_cv_func_mmap_stupidshared)
874if test $cyrus_cv_func_mmap_stupidshared = yes; then
875        found_map="stupidshared"
876else
877        AC_MSG_WARN([*** This system does not have a working mmap()])
878        AC_MSG_WARN(*** Expect a considerable performance penalty)
879        found_map=nommap
880fi
881fi
882
883AC_ARG_WITH(mmap,
884        [AS_HELP_STRING([--with-mmap=TYPE], [force shared/stupidshared/nommap - JUST FOR TESTING])],
885        WITH_MAP="$withval",WITH_MAP="$found_map")
886AM_CONDITIONAL([MAP_SHARED], [test "$WITH_MAP" = "shared"])
887AM_CONDITIONAL([MAP_STUPIDSHARED], [test "$WITH_MAP" = "stupidshared"])
888
889AC_ARG_WITH(lock,
890  [AS_HELP_STRING([--with-lock=METHOD], [force use of METHOD for locking (flock or fcntl)])],
891  WITH_LOCK="$withval", [
892  AC_CHECK_FUNC(fcntl,WITH_LOCK="fcntl",[
893                AC_CHECK_FUNC(flock,WITH_LOCK="flock",[
894                                AC_MSG_ERROR(unable to detect locking method)
895                              ])
896                ])
897  ])
898AM_CONDITIONAL([LOCK_FCNTL], [test $WITH_LOCK = "fcntl"])
899
900dnl check for fdatasync (used by cyrusdb_skiplist)
901AC_SEARCH_LIBS([fdatasync], [rt], [
902    AC_DEFINE(HAVE_FDATASYNC,[],[Do we have fdatasync()?])
903], [])
904
905dnl check for clock_gettime
906AC_SEARCH_LIBS([clock_gettime], [rt], [], [
907    AC_MSG_ERROR([unable to find the clock_gettime() function])
908])
909
910dnl check for libuuid (used when generating mailbox uniqueids)
911LIB_UUID=
912AC_CHECK_LIB(uuid, uuid_generate,[
913    LIB_UUID="-luuid"
914    AC_DEFINE(HAVE_LIBUUID,[],[Do we have the uuid library])
915])
916
917dnl for AFS.
918cant_find_sigvec=no
919AC_CACHE_VAL(cyrus_cv_sigveclib,[
920 dnl bsd classic flavor
921 AC_CHECK_FUNC(sigvec, [
922        cyrus_cv_sigveclib=""
923  ], [
924  dnl hp flavor
925  AC_CHECK_LIB(BSD, sigvec, cyrus_cv_sigveclib="-lBSD", [
926    dnl not hp flavor
927    SAVE_LDFLAGS="$LDFLAGS"
928    dnl solaris flavor
929    LDFLAGS="-L/usr/ucblib -R/usr/ucblib $LDFLAGS"
930    AC_CHECK_LIB(ucb, sigvec, [
931      dnl more solaris flavor
932      cyrus_cv_sigveclib="-lc -L/usr/ucblib -R/usr/ucblib -lucb"],
933      [ cant_find_sigvec=yes ])
934    LDFLAGS="$SAVE_LDFLAGS"])
935  ])
936])
937AC_SUBST(cyrus_cv_sigveclib)
938
939# ok, we still look for this stuff because of checking groups, but
940# all authentication goes through SASL
941AC_ARG_ENABLE([afs],
942        [AS_HELP_STRING([--enable-afs], [Enable AFS with ptloader])])
943
944AC_ARG_WITH(afs-libdir,
945        [AS_HELP_STRING([--with-afs-libdir=DIR], [use AFS libraries from DIR [/usr/lib]])],
946        afs_libdir="${withval}", afs_libdir="/usr/lib")
947
948AC_ARG_WITH(afs-incdir,
949        [AS_HELP_STRING([--with-afs-incdir=DIR], [use AFS headers from DIR [/usr/include]])],
950        afs_incdir="${withval}", afs_incdir="/usr/include")
951
952AC_ARG_WITH(ldap,
953        [AS_HELP_STRING([--with-ldap=DIR], [use LDAP (in DIR) (experimental) [/usr/local]])],
954        with_ldap="${withval}", with_ldap="no")
955
956dnl select mode of afspts
957AC_ARG_ENABLE(krb5afspts,
958        [AS_HELP_STRING([--enable-krb5afspts], [compile afskrb PTS module with krb5 support])])
959
960if test "x$enable_afs" = "xyes"; then
961# krb5afspts is only valid if AFS is enabled, so check inside here.
962    AS_IF([test "x$enable_krb5afspts" = "xyes"], [SASL_SET_GSSAPI_LIBS
963      AC_DEFINE(AFSPTS_USE_KRB5,[],[Should the AFS PTS plugin use krb5?])
964    ])
965
966    SAVE_CFLAGS="$CFLAGS"
967    CFLAGS="${CFLAGS} -I${with_afs_incdir}"
968    AFS_LIBS="${with_afs_libdir}/afs/libkauth.a ${with_afs_libdir}/afs/libprot.a  ${with_afs_libdir}/afs/libauth.a ${with_afs_libdir}/afs/libsys.a ${with_afs_libdir}/librxkad.a ${with_afs_libdir}/librx.a ${with_afs_libdir}/afs/libsys.a ${with_afs_libdir}/libubik.a ${with_afs_libdir}/afs/util.a ${with_afs_libdir}/afs/libafscom_err.a -lresolv"
969    if test -f ${with_afs_libdir}/afs/liblwp.a; then
970      AFS_LIBS="$AFS_LIBS ${with_afs_libdir}/afs/liblwp.a"
971    elif test -f ${with_afs_libdir}/liblwp.a; then
972      AFS_LIBS="$AFS_LIBS ${with_afs_libdir}/liblwp.a"
973    fi
974    if test -f ${with_afs_libdir}/afs/libaudit.a; then
975      AFS_LIBS="$AFS_LIBS ${with_afs_libdir}/afs/libaudit.a"
976    fi
977    if test -f /usr/ucblib/libucb.a; then
978      CMU_ADD_LIBPATH_TO(/usr/ucblib, AFS_LDFLAGS)
979      AFS_LIBS="$AFS_LIBS -lc -lucb"
980    fi
981    if test -f ${with_afs_libdir}/afs/libdes.a; then
982      AFS_LIBS="$AFS_LIBS ${with_afs_libdir}/afs/libdes.a"
983    else
984      AFS_LIBS="$AFS_LIBS -ldes"
985    fi
986
987    AC_CACHE_VAL(cyrus_cv_afs_sigvec,[
988        SAVE_LIBS="$LIBS"
989        LIBS="${with_afs_libdir}/liblwp.a"
990        AC_MSG_CHECKING(if AFS libraries need sigvec)
991        dnl Does AFS need sigvec?  We have to link against lwp and see
992        dnl if IOMGR_Initialize wants it
993        AC_TRY_LINK([IOMGR_Initialize();],
994                [IOMGR_Initialize()],
995                [
996                        dnl it linked; don't need it
997                        AC_MSG_RESULT(no)
998                        cyrus_cv_afs_sigvec="no"
999                ], [
1000                        dnl didn't link; pick up sigvec
1001                        AC_MSG_RESULT(yes)
1002                        cyrus_cv_afs_sigvec="yes"
1003                ])
1004        ])
1005    if test "$cyrus_cv_afs_sigvec" = yes; then
1006      if test "$cant_find_sigvec" = yes; then
1007        AC_MSG_WARN([Can not find a sigvec for AFS libraries which seem to need one.])
1008      else
1009        AFS_LIBS="${AFS_LIBS} $cyrus_cv_sigveclib"
1010        AC_DEFINE(HAVE_AFSKRB,[],[Should we build afskrb pts module?])
1011      fi
1012    else
1013      AFS_LIBS="${AFS_LIBS}"
1014      AC_DEFINE(HAVE_AFSKRB,[],[Should we build afskrb pts module?])
1015    fi
1016    LIBS="$SAVE_LIBS"
1017    CFLAGS="$SAVE_CFLAGS"
1018    AC_SUBST(AFS_LDFLAGS)
1019    AC_SUBST(AFS_LIBS)
1020fi
1021AM_CONDITIONAL([USE_AFSKRB], [grep HAVE_AFSKRB confdefs.h >/dev/null])
1022
1023have_ldap=no
1024LDAP_CPPFLAGS=
1025LDAP_LDFLAGS=
1026LDAP_LIBS=
1027
1028case "x$with_ldap" in
1029xno)
1030    # default args or --without-ldap
1031    # do not try to enable
1032    ;;
1033xyes)
1034    # --with-ldap
1035    # try to enable, search in default system directories
1036    ldap_cppflags=
1037    ldap_ldflags=
1038    ;;
1039*)
1040    # --with-ldap=DIR
1041    # try to enable, search in given install directory
1042    if test "x$with_ldap" != "x" -a -d "$with_ldap"; then
1043        ldap_cppflags="-I${with_ldap}/include"
1044        ldap_ldflags="-L${with_ldap}/lib"
1045        with_ldap=yes
1046    else
1047        AC_WARN([Disabling LDAP - no include files found])
1048        with_ldap=no
1049    fi
1050esac
1051
1052if test $with_ldap = yes; then
1053    save_CPPFLAGS="$CPPFLAGS"
1054    save_LDFLAGS="$LDFLAGS"
1055    CPPFLAGS="$CPPFLAGS $ldap_cppflags"
1056    LDFLAGS="$LDFLAGS $ldap_ldflags"
1057
1058    AC_CHECK_LIB(ldap, ldap_initialize, [
1059        AC_DEFINE(HAVE_LDAP,[],[Should we build the LDAP pts module?])
1060        LDAP_CPPFLAGS="$ldap_cppflags"
1061        LDAP_LDFLAGS="$ldap_ldflags"
1062        LDAP_LIBS="-lldap -llber"
1063        have_ldap=yes
1064    ],,-llber)
1065
1066    CPPFLAGS="$save_CPPFLAGS"
1067    LDFLAGS="$save_LDFLAGS"
1068fi
1069AC_SUBST(LDAP_CPPFLAGS)
1070AC_SUBST(LDAP_LDFLAGS)
1071AC_SUBST(LDAP_LIBS)
1072AM_CONDITIONAL([HAVE_LDAP], [test "$have_ldap" = "yes"])
1073
1074AM_CONDITIONAL([PTCLIENT], [test "x$enable_afs" = "xyes" -o "$have_ldap" = "yes"])
1075
1076AC_ARG_WITH([clamav],
1077	AS_HELP_STRING([--without-clamav], [ignore presence of ClamAV and disable it]))
1078AS_IF([test "x$with_clamav" != "xno"],
1079	[ PKG_CHECK_MODULES([CLAMAV], [libclamav],
1080		[ AC_DEFINE(HAVE_CLAMAV, [], [Do we have ClamAV?])
1081		  with_clamav=yes ],
1082		with_clamav=no)])
1083
1084AC_ARG_ENABLE(server,
1085        [AS_HELP_STRING([--disable-server], [disable compiling servers])])
1086AM_CONDITIONAL([SERVER], [test "$enable_server" != "no"])
1087# We always output a server makefile (just because we can)
1088
1089dnl this is the new simple check for kerberos; since the person had to
1090dnl compile SASL, we might as well use the same checks.
1091AC_ARG_WITH(krb,
1092        [AS_HELP_STRING([--with-krb=DIR], [use Kerberos from DIR])],
1093        with_krb="$withval", with_krb="no")
1094
1095AC_ARG_WITH(krbimpl,
1096        [AS_HELP_STRING([--with-krbimpl=kth|mit], [assume Kerberos 4 from KTH or MIT])],
1097        with_krbimpl="$withval", with_krbimpl="kth")
1098
1099AC_ARG_ENABLE(statickrb,
1100        [AS_HELP_STRING([--enable-statickrb], [link Kerberos statically])],
1101        with_statickrb="yes", with_statickrb="no")
1102
1103dnl In order to compile kerberos4, we need libkrb and libdes.
1104
1105dnl we might need -lresolv for kerberos
1106AC_CHECK_LIB(resolv,res_search)
1107
1108if test "$with_statickrb" = "yes" -a ! -d "$with_krb"; then
1109      AC_MSG_ERROR([--enable-statickrb specified but --with-krb did not specify a valid directory])
1110fi
1111
1112if test "$with_krb" != "no"; then
1113dnl Do we need DES for kerberos?
1114AC_ARG_WITH(krbdes,
1115        [AS_HELP_STRING([--with-krbdes], [use Kerberos DES implementation [yes]])],
1116        with_krbdes="$withval", with_krbdes="yes")
1117if test "$with_krbdes" = "yes"; then
1118  AC_CHECK_LIB(des,des_ecb_encrypt,
1119      if test "$with_statickrb" = "yes"; then
1120          KRB_LIBS="$with_krb/lib/libdes.a"
1121      else
1122          KRB_LIBS="-ldes"
1123      fi,
1124  AC_MSG_ERROR([The Kerberos DES library is required for Kerberos support.]))
1125fi
1126fi
1127
1128dnl if we were ambitious, we'd look more aggressively for the
1129dnl krb4 install
1130if test -d ${with_krb}; then
1131   AC_CACHE_CHECK(for Kerberos includes, cyrus_cv_krbinclude, [
1132     for krbhloc in include/kerberosIV include
1133     do
1134       if test -f ${with_krb}/${krbhloc}/krb.h ; then
1135         cyrus_cv_krbinclude=${with_krb}/${krbhloc}
1136         break
1137       fi
1138     done
1139     ])
1140
1141   if test -n "${cyrus_cv_krbinclude}"; then
1142     CPPFLAGS="$CPPFLAGS -I${cyrus_cv_krbinclude}"
1143   fi
1144   CMU_ADD_LIBPATH(${with_krb}/lib)
1145fi
1146
1147if test "$with_krbimpl" != "kth"; then
1148  KRBLIB="krb4"
1149else
1150  KRBLIB="krb"
1151fi
1152
1153if test "$with_des" != no; then
1154  AC_CHECK_HEADER(krb.h,
1155    AC_CHECK_LIB(${KRBLIB}, krb_mk_priv,
1156      if test "$with_statickrb" = "yes"; then
1157          KRB_LIBS="$KRB_LIBS $with_krb/lib/lib${KRBLIB}.a"
1158      else
1159          KRB_LIBS="$KRB_LIBS -l${KRBLIB}"
1160      fi,
1161                 AC_WARN(No Kerberos V4 found); krb4=no,
1162           $KRB_LIBS),
1163    krb4=no)
1164else
1165  AC_WARN(No DES library found for Kerberos V4 support)
1166  krb4=no
1167fi
1168
1169if test "${krb4}" != no; then
1170  AC_DEFINE(HAVE_KRB,[],[Support for Kerberos?])
1171fi
1172
1173LIBS="$KRB_LIBS $LIBS"
1174
1175SASL_SET_GSSAPI_LIBS
1176
1177dnl
1178dnl Test for OpenSSL
1179dnl
1180AC_ARG_WITH(openssl,
1181        [AS_HELP_STRING([--with-openssl=DIR], [use OpenSSL from DIR])],
1182        with_ssl="${withval}")
1183
1184SSL_CPPFLAGS=
1185SSL_LIBS=
1186
1187case "x$with_ssl" in
1188xno)
1189    # --without-openssl
1190    # do not try to enable
1191    ;;
1192x|xyes)
1193    # default args or --with-openssl
1194    #
1195    # Try pkg-config - OpenSSL >= 0.9.6 has openssl.pc
1196    PKG_CHECK_MODULES(OPENSSL, openssl, [with_ssl=yes])
1197    ssl_cppflags="$OPENSSL_CFLAGS"
1198    ssl_ldflags="$OPENSSL_LIBS"
1199    #
1200    # If pkg-config doesn't work, search in default system directories
1201    ;;
1202*)
1203    # --with-openssl=DIR
1204    # try to enable, search in given install directory
1205    if test -d "$with_ssl"; then
1206        ssl_cppflags="-I${with_ssl}/include"
1207        ssl_ldflags=
1208        if test -d "${with_ssl}/lib64"; then
1209            CMU_ADD_LIBPATH_TO(${with_ssl}/lib64, ssl_ldflags)
1210        else
1211            CMU_ADD_LIBPATH_TO(${with_ssl}/lib, ssl_ldflags)
1212        fi
1213        with_ssl=yes
1214    else
1215        AC_WARN([Disabling OpenSSL - no include files found])
1216        with_ssl=no
1217    fi
1218esac
1219
1220if test "$with_ssl" != "no"; then
1221    save_CPPFLAGS="$CPPFLAGS"
1222    save_LDFLAGS="$LDFLAGS"
1223    CPPFLAGS="$CPPFLAGS $ssl_cppflags"
1224    LDFLAGS="$LDFLAGS $ssl_ldflags"
1225
1226    AC_CHECK_HEADER(openssl/evp.h, [
1227        with_ssl=yes
1228    ],[
1229        with_ssl=no
1230    ])
1231
1232    dnl if openssl has been compiled with the rsaref2 libraries,
1233    dnl we need to include the rsaref libraries in the crypto check
1234    ssl_libs=
1235    AC_CHECK_LIB(rsaref, RSAPublicEncrypt,[
1236       ssl_libs="-lRSAglue -lrsaref"
1237    ],[
1238       # whatever, we do not care
1239       :
1240    ])
1241    AC_CHECK_LIB(crypto, BIO_accept,[
1242        ssl_libs="-lcrypto $ssl_libs"
1243    ],[
1244        with_ssl=no
1245    ], $ssl_libs)
1246    AC_CHECK_LIB(ssl, SSL_CTX_new, [
1247        ssl_libs="-lssl $ssl_libs"
1248    ],[
1249        with_ssl=no
1250    ], $ssl_libs)
1251
1252    if test "$with_ssl" = "no"; then
1253        AC_WARN([Disabling SSL - no library files found])
1254    fi
1255    CPPFLAGS="$save_CPPFLAGS"
1256    LDFLAGS="$save_LDFLAGS"
1257fi
1258
1259AC_MSG_CHECKING(for ssl)
1260AC_MSG_RESULT($with_ssl)
1261
1262if test "$with_ssl" != "no"; then
1263    SSL_CPPFLAGS="$ssl_cppflags"
1264    SSL_LIBS="$ssl_ldflags $ssl_libs"
1265    AC_DEFINE(HAVE_SSL,[],[Build with SSL support?])
1266    if test "${krb4}" != no; then
1267       AC_DEFINE(OPENSSL_ENABLE_OLD_DES_SUPPORT,[],[Configure OpenSSL to provide legacy des apis])
1268       AC_DEFINE(OPENSSL_DES_LIBDES_COMPATIBILITY,[],[Configure OpenSSL to provide krb4-compatible legacy des apis])
1269    fi
1270fi
1271AM_CONDITIONAL([HAVE_SSL], [test "$with_ssl" != "no"])
1272AC_SUBST(SSL_CPPFLAGS)
1273AC_SUBST(SSL_LIBS)
1274
1275dnl
1276dnl Allow for setting EGD socket file on systems without /dev/*random.
1277dnl
1278AC_ARG_WITH(egd-socket,
1279      [AC_HELP_STRING([--with-egd-socket=FILE], [Entropy Gathering Daemon socket pathname for systems without /dev/urandom])],
1280              [ EGD_SOCKET="$withval" ]
1281      )
1282if test -n "$EGD_SOCKET" ; then
1283      AC_DEFINE_UNQUOTED(EGD_SOCKET, "$EGD_SOCKET", [Alternative to /dev/urandom?])
1284fi
1285
1286dnl
1287dnl Test for zlib
1288dnl
1289AC_ARG_WITH(zlib, [AS_HELP_STRING([--with-zlib=DIR],[use zlib from DIR])],
1290    with_zlib=$withval, with_zlib="yes")
1291
1292save_CPPFLAGS=$CPPFLAGS
1293save_LDFLAGS=$LDFLAGS
1294
1295if test -d $with_zlib; then
1296    CPPFLAGS="${CPPFLAGS} -I${with_lib}/include"
1297    CMU_ADD_LIBPATH(${with_zlib}/$CMU_LIB_SUBDIR)
1298fi
1299
1300ZLIB=""
1301case "$with_zlib" in
1302    no)
1303      with_zlib="no";;
1304    *)
1305    AC_CHECK_HEADER(zlib.h, [
1306        AC_CHECK_LIB(z, deflate,
1307                LIBS="${LIBS} -lz"; with_zlib="yes",
1308                with_zlib="no",)],
1309        with_zlib=no)
1310    ;;
1311esac
1312
1313if test "$with_zlib" != "no"; then
1314    AC_DEFINE(HAVE_ZLIB,[],[Do we have zlib?])
1315    ZLIB="-lz"
1316    HAVE_ZLIB=1
1317else
1318    CPPFLAGS=$save_CPPFLAGS
1319    LDFLAGS=$save_LDFLAGS
1320    HAVE_ZLIB=0
1321fi
1322
1323AC_MSG_CHECKING(for zlib)
1324AC_MSG_RESULT($with_zlib)
1325AC_SUBST(ZLIB)
1326
1327dnl
1328dnl Test for Zephyr
1329dnl
1330AC_ARG_WITH(zephyr,
1331        [AS_HELP_STRING([--with-zephyr=DIR], [enable Zephyr notification (installed on DIR)])],
1332        with_zephyr="${withval}")
1333if test -z "$with_zephyr"; then
1334     if test -f /usr/local/lib/libzephyr.a; then
1335        with_zephyr="/usr/local"
1336     elif test -f /usr/lib/libzephyr.a; then
1337        with_zephyr="/usr"
1338     fi
1339fi
1340ZEPHYR_LIBS=""
1341case "$with_zephyr" in
1342        no) true;;
1343        ""|yes) AC_CHECK_LIB(zephyr,ZInitialize,ZEPHYR_LIBS="-lzephyr",
1344                with_zephyr="no",);;
1345       *) ZEPHYR_LIBS="-lzephyr";;
1346esac
1347AC_SUBST(ZEPHYR_LIBS)
1348if test "$with_zephyr" != "no"; then
1349        AC_DEFINE(HAVE_ZEPHYR,[],[Build with Zephyr support?])
1350fi
1351AM_CONDITIONAL([ZEPHYR], [test "$with_zephyr" != "no"])
1352
1353
1354dnl
1355dnl Test for libcap (POSIX.1e - security API) on Linux systems
1356dnl
1357AC_ARG_WITH([libcap],
1358        AS_HELP_STRING([--with-libcap], [Enable libcap system capabilities handling (Linux systems only)]),
1359        with_libcap="${withval}")
1360
1361have_libcap=no
1362case $host_os in
1363linux*)
1364        if test "x$with_libcap" = "xyes"; then
1365                AC_CHECK_LIB([cap], [cap_get_proc], have_libcap=yes, have_libcap=no)
1366                AC_CHECK_HEADERS([sys/capability.h sys/prctl.h], , have_libcap=no)
1367                if test "$have_libcap" = "yes"; then
1368                        AC_DEFINE(HAVE_LIBCAP, [], [Do we have libcap system capabilities handling (Linux systems only)?])
1369                        LIBS="$LIBS -lcap"
1370                fi
1371        fi
1372        ;;
1373*)
1374        ;;
1375esac
1376
1377AC_MSG_CHECKING(for libcap)
1378AC_MSG_RESULT($have_libcap)
1379
1380dnl
1381dnl Check for jansson library, needed for JSON support
1382dnl
1383PKG_CHECK_MODULES([JANSSON], [jansson >= 2.3])
1384dnl call AC_SUBST macro to support pkg-config version older than 0.24
1385AC_SUBST([JANSSON_LIBS])
1386AC_SUBST([JANSSON_CFLAGS])
1387
1388dnl
1389dnl Test for mailbox event notification
1390dnl enable requires the installation of jansson library
1391dnl
1392AC_ARG_ENABLE(event-notification,
1393        [AS_HELP_STRING([--disable-event-notification], [disable compiling of mailbox event notification (that needs jansson library)])],,
1394        [enable_event_notification="yes";])
1395
1396if test "$enable_event_notification" != "no"; then
1397    AC_DEFINE(ENABLE_MBOXEVENT,[],[Build with support of mailbox event notification])
1398fi
1399
1400dnl
1401dnl Set pidfile location
1402dnl
1403AC_ARG_WITH(pidfile,
1404        [AS_HELP_STRING([--with-pidfile=DIR], [pidfile in DIR [/var/run/cyrus-master.pid]])],
1405        [MASTERPIDFILE="$withval"],
1406        [MASTERPIDFILE="/var/run/cyrus-master.pid"])
1407MASTERPIDFILE="\"$MASTERPIDFILE\""
1408AC_DEFINE_UNQUOTED(MASTER_PIDFILE, $MASTERPIDFILE,[Name of the pidfile for master])
1409
1410dnl
1411dnl see if we're compiling with autocreate support
1412dnl
1413AC_ARG_ENABLE(autocreate,
1414        [AS_HELP_STRING([--enable-autocreate], [enable autocreate support])],,[enable_autocreate="no";])
1415AM_CONDITIONAL([AUTOCREATE], [test "$enable_autocreate" != "no"])
1416if test "x$enable_autocreate" = "xyes"; then
1417        AC_DEFINE(USE_AUTOCREATE,[],[Build with autocreate functionality])
1418fi
1419dnl
1420dnl see if we're compiling with IMAP idled support
1421dnl
1422AC_ARG_ENABLE(idled,
1423        [AS_HELP_STRING([--enable-idled], [enable IMAP idled support])],,[enable_idled="no";])
1424AM_CONDITIONAL([IDLED], [test "$enable_idled" != "no"])
1425if test "x$enable_idled" = "xyes"; then
1426        AC_DEFINE(USE_IDLED,[],[Build with idled functionality])
1427fi
1428dnl
1429dnl see if we're compiling with NNTP support
1430dnl
1431AC_ARG_ENABLE(nntp,
1432        [AS_HELP_STRING([--enable-nntp], [enable NNTP support])],,[enable_nntp="no";])
1433AM_CONDITIONAL([NNTPD], [test "$enable_nntp" != "no"])
1434if test "x$enable_nntp" = "xyes"; then
1435        AC_DEFINE(USE_NNTPD,[],[Build with nntpd functionality])
1436fi
1437
1438dnl
1439dnl see if we're compiling the Murder support programs
1440dnl
1441AC_ARG_ENABLE(murder,
1442        [AS_HELP_STRING([--enable-murder], [enable IMAP Murder support])],, [enable_murder="no";])
1443AM_CONDITIONAL([MURDER], [test "$enable_murder" != "no"])
1444if test "$enable_murder" != no; then
1445        # for master/slave auto-selection
1446        AC_CHECK_HEADERS(sys/sockio.h)
1447fi
1448if test "x$enable_murder" = "xyes"; then
1449        AC_DEFINE(USE_MURDER,[],[Build with Murder functionality])
1450fi
1451
1452dnl
1453dnl see if we're compiling with HTTP support
1454dnl
1455AC_ARG_ENABLE(http,
1456        [AS_HELP_STRING([--enable-http], [enable HTTP support])],, [enable_http="no";])
1457AM_CONDITIONAL([HTTPD], [test "$enable_http" != "no"])
1458
1459HTTP_CPPFLAGS=
1460HTTP_LIBS=
1461with_xml2=no
1462with_ical=no
1463with_icu4c=no
1464with_shapelib=no
1465with_brotli=no
1466if test "$enable_http" != no; then
1467dnl
1468dnl make sure all the modules we need are present
1469dnl
1470        if test "x$HAVE_SQLITE" != x1; then
1471            AC_MSG_ERROR([Need sqlite3 for http])
1472        else
1473            use_sqlite="yes"
1474            AC_DEFINE(WITH_DAV,[],[Build *DAV support into httpd?])
1475        fi
1476
1477        PKG_CHECK_MODULES([XML2], [libxml-2.0], [
1478                LIBS="$LIBS ${XML2_LIBS}"
1479                with_xml2=yes
1480                ],
1481                AC_MSG_ERROR([Need libxml-2.0 for http]))
1482
1483        AC_CHECK_LIB(xml2, xmlFirstElementChild, [
1484                AC_DEFINE(HAVE_XML_FIRSTCHILD,[],
1485                        [Do we have support for xmlFirstElementChild()?])
1486
1487                AC_CHECK_LIB(xml2, xmlBufferDetach,
1488                        AC_DEFINE(HAVE_XML_BUFFERDETACH,[],
1489                                [Do we have support for xmlBufferDetach()?]))
1490                ])
1491
1492        PKG_CHECK_MODULES([ICAL], [libical], [
1493                AC_DEFINE(HAVE_ICAL,[],[Build CalDAV support into httpd?])
1494                LIBS="$LIBS ${ICAL_LIBS}"
1495                with_ical=yes
1496                ],
1497                AC_MSG_ERROR([Need libical for http]))
1498
1499        AC_CHECK_DECLS([icalproperty_get_parent,
1500                        icalrecur_freq_to_string, icalrecur_weekday_to_string],
1501                [], [], [[#include <libical/ical.h>]])
1502
1503        AC_CHECK_MEMBER(icaltimetype.is_utc,
1504                AC_DEFINE(ICALTIME_HAS_IS_UTC,[],
1505                        [Does icaltimetype have is_utc field?]),
1506                        [], [#include <libical/ical.h>])
1507
1508        AC_CHECK_LIB(ical, icalproperty_new_acknowledged,
1509                AC_DEFINE(HAVE_VALARM_EXT_PROPS,[],
1510                        [Do we have built-in support for VALARM extensions props?]))
1511
1512        AC_CHECK_LIB(ical, icalparameter_new_iana, [
1513                AC_DEFINE(HAVE_IANA_PARAMS,[],
1514                        [Do we have support for IANA params?])
1515
1516                AC_CHECK_LIB(ical, icalparameter_new_schedulestatus,
1517                        AC_DEFINE(HAVE_SCHEDULING_PARAMS,[],
1518                                [Do we have built-in support for scheduling params?]))
1519
1520                AC_CHECK_LIB(ical, icalparameter_new_managedid,
1521                        AC_DEFINE(HAVE_MANAGED_ATTACH_PARAMS,[],
1522                                [Do we have built-in support for managed attachment params?]))
1523
1524                AC_CHECK_LIB(ical, icalproperty_new_tzuntil,
1525                        AC_DEFINE(HAVE_TZDIST_PROPS,[],
1526                                [Do we have built-in support for TZdist props?]))
1527                ],
1528                AC_MSG_NOTICE([Your version of libical can not support scheduling or managed attachments.  Consider upgrading to libical >= 0.48]))
1529
1530        AC_CHECK_LIB(ical, icaltimezone_set_builtin_tzdata,
1531                AC_DEFINE(HAVE_TZ_BY_REF,[],
1532                        [Build timezones by reference support into httpd?]),
1533                AC_MSG_NOTICE([Your version of libical can not support timezones by reference.  Consider upgrading to libical >= 1.0.1]))
1534
1535        AC_CHECK_LIB(ical, icalcomponent_new_vavailability,
1536                AC_DEFINE(HAVE_VAVAILABILITY,[],
1537                        [Build VAVAILABILITY support into httpd?]),
1538                AC_MSG_NOTICE([Your version of libical can not support availability.  Consider upgrading to libical >= 1.0.1]))
1539
1540        AC_CHECK_LIB(ical, icalcomponent_new_vvoter,
1541                AC_DEFINE(HAVE_VPOLL,[], [Build VPOLL support into httpd?]),
1542                AC_MSG_NOTICE([Your version of libical can not support consensus scheduling.  Consider upgrading to libical >= 2.0]))
1543
1544        AC_CHECK_LIB(ical, icalrecurrencetype_rscale_is_supported, [
1545                PKG_CHECK_MODULES([ICU4C], [icu-i18n], [
1546                        AC_DEFINE(HAVE_RSCALE,[], [Build RSCALE support into httpd?])
1547                        LIBS="$LIBS ${ICU4C_LIBS}"
1548                        with_icu4c=yes
1549                        ],
1550                        AC_MSG_ERROR([Need ICU4C for RSCALE support in httpd]))
1551                ],
1552                AC_MSG_NOTICE([Your version of libical can not support non-gregorian recurrences.  Consider upgrading to libical >= 2.0]))
1553
1554        AC_CHECK_LIB(ical, icalcomponent_new_vpatch,
1555                AC_DEFINE(HAVE_VPATCH,[],
1556                        [Build VPATCH support into httpd?]),
1557                AC_MSG_NOTICE([Your version of libical can not support patching iCalendar objects.  Consider upgrading to libical >= 2.1]))
1558
1559        AC_CHECK_LIB(ical, icalrecur_iterator_set_start,
1560                AC_DEFINE(HAVE_RECUR_ITERATOR_START,[],
1561                        [Do we have support for setting start point of recurrences?]))
1562
1563dnl  Don't bother checking for DKIM until iSchedule gains traction
1564dnl        PKG_CHECK_MODULES([DKIM], [opendkim >= 2.7.0],
1565dnl                AC_EGREP_HEADER(DKIM_CANON_ISCHEDULE, dkim.h,
1566dnl                        AC_DEFINE(WITH_DKIM,[],
1567dnl                                [Build DKIM support into iSchedule?]),
1568dnl                        AC_MSG_WARN([Your version of OpenDKIM can not support iSchedule.  Consider patching OpenDKIM with contrib/dkim_canon_ischedule.patch])),
1569dnl                AC_MSG_WARN([Your version of OpenDKIM can not support iSchedule.  Consider upgrading to OpenDKIM >= 2.7.0]))
1570        AC_ARG_WITH(nghttp2, [AS_HELP_STRING([--without-nghttp2], [disable HTTP/2 support (check)])],,[with_nghttp2="check"])
1571        if test "x$with_nghttp2" = "xyes" -o "x$with_nghttp2" = "xcheck"; then
1572                PKG_CHECK_MODULES([NGHTTP2], [libnghttp2 >= 1.5], [
1573                    with_nghttp2=yes
1574                    AC_DEFINE(HAVE_NGHTTP2,[],
1575                            [Build HTTP/2 support into httpd?])
1576                ], [
1577                    if test "x$with_nghttp2" = "xyes"; then
1578                        AC_MSG_ERROR([HTTP/2 explicitly requested, but libnghttp2 was not found])
1579                    fi
1580                    with_nghttp2=no
1581                    AC_MSG_NOTICE([httpd will not have support for HTTP/2.  Consider installing libnghttp2 >= 1.5])
1582                ])
1583        fi
1584
1585        PKG_CHECK_MODULES([BROTLI], [libbrotlienc], [
1586                AC_DEFINE(HAVE_BROTLI,[],
1587                        [Build Brotli compression support into httpd?])
1588                with_brotli=yes
1589                ],
1590                AC_MSG_NOTICE([httpd will not have support for Brotli compression.  Consider installing libbrotli]))
1591
1592        dnl httpd needs libmath in a few places
1593        dnl XXX really should check for this properly but AC_SEARCH_LIBS/AC_CHECK_LIB
1594        dnl XXX break under -Werror(!)
1595        LIB_MATH="-lm"
1596
1597        PKG_CHECK_MODULES([SHAPELIB], [shapelib >= 1.3.0],[
1598                AC_DEFINE(HAVE_SHAPELIB,[],
1599                        [Build geographic support into tzdist?])
1600                AC_DEFINE(SHAPELIB_VERSION, ["1.3.0"], [ShapeLib Version])
1601                with_shapelib=yes
1602                ],
1603                AC_MSG_NOTICE([tzdist will not have geolocation support.  Consider installing shapelib]))
1604
1605        HTTP_CPPFLAGS="${XML2_CFLAGS} ${SQLITE3_CFLAGS} ${ICAL_CFLAGS} ${JANSSON_CFLAGS} ${NGHTTP2_CFLAGS} ${BROTLI_CFLAGS} ${SHAPELIB_CFLAGS}"
1606        HTTP_LIBS="${XML2_LIBS} ${SQLITE3_LIBS} ${ICAL_LIBS} ${JANSSON_LIBS} ${NGHTTP2_LIBS} ${BROTLI_LIBS} ${SHAPELIB_LIBS} ${LIB_MATH}"
1607fi
1608AC_SUBST(HTTP_CPPFLAGS)
1609AC_SUBST(HTTP_LIBS)
1610if test "x$enable_http" = "xyes"; then
1611        AC_DEFINE(USE_HTTPD,[],[Build with HTTP functionality])
1612fi
1613
1614dnl
1615dnl see if we're compiling with calendar alarm support
1616dnl
1617AC_ARG_ENABLE(calalarmd,
1618        [AS_HELP_STRING([--enable-calalarmd], [enable CalDAV alarm support])],,[enable_calalarmd="no";])
1619if test "x$enable_calalarmd" = "xyes"; then
1620    if test "x$enable_http" = "xyes"; then
1621	AC_DEFINE(USE_CALALARMD,[],[Build with calendar alarm functionality])
1622    else
1623	AC_MSG_ERROR([--enable-calalarmd requires --enable-http])
1624    fi
1625fi
1626AM_CONDITIONAL([CALALARMD], [test "$enable_calalarmd" != "no"])
1627
1628dnl
1629dnl see if we're compiling replication support programs
1630dnl
1631AC_ARG_ENABLE(replication,
1632        [AS_HELP_STRING([--enable-replication], [enable replication support (experimental)])],,[enable_replication="no";])
1633AM_CONDITIONAL([REPLICATION], [test "$enable_replication" != no])
1634if test "x$enable_replication" = "xyes"; then
1635        AC_DEFINE(USE_REPLICATION,[],[Build with replication functionality])
1636fi
1637
1638dnl
1639dnl see if we're compiling backup support programs
1640dnl
1641AC_ARG_ENABLE(backup,
1642        [AS_HELP_STRING([--enable-backup], [enable backup support (experimental)])],,[enable_backup="no";])
1643AM_CONDITIONAL([BACKUP], [test "$enable_backup" != no])
1644
1645if test "x$enable_backup" != xno; then
1646    if test "x$HAVE_SQLITE" != x1; then
1647        AC_MSG_ERROR([Need sqlite3 for backups])
1648    else
1649        use_sqlite="yes"
1650    fi
1651    if test "x$HAVE_ZLIB" != x1; then
1652        AC_MSG_ERROR([Need zlib for backups])
1653    fi
1654
1655    AC_DEFINE([ENABLE_BACKUP],[],[Build with backup support])
1656fi
1657
1658dnl
1659dnl Try and find a system version of com_err.
1660dnl If we see something that looks a little wacky, ignore it (there are many
1661dnl deficient installs of com_err, unfortunately, which leave out compile_et)
1662dnl There is also a broken re-implementation of compile_et, apparently derived
1663dnl from the Kerberos project, being shipped in /usr/bin on MacOS X, see Bug #3711.
1664dnl
1665AC_ARG_WITH(com_err,
1666        [AS_HELP_STRING([--with-com_err=DIR], [use com_err from path -- includes in DIR/include, libs in DIR/lib, and compile_et in DIR/bin])])
1667if test -z "$with_com_err"; then
1668        # no value supplied
1669        AC_CHECK_LIB(com_err, com_err, [
1670                # com_err is already in library path
1671                # guess we're okay
1672                # can use system com_err
1673                with_com_err=""
1674                AC_CHECK_HEADER(et/com_err.h,
1675                  [AC_DEFINE(HAVE_ET_COM_ERR_H,[],[We need et/com_err.h])],
1676                  [AC_CHECK_HEADER(com_err.h,[],[AC_MSG_ERROR([cannot locate com_err.h])])])
1677                AC_PATH_PROG(COMPILE_ET, compile_et, [no compile et])
1678        ], [
1679        if test -f /usr/local/include/com_err.h -o -f /usr/local/include/et/com_err.h; then
1680                with_com_err="/usr/local"
1681                AC_PATH_PROG(COMPILE_ET, /usr/local/bin/compile_et, [no compile et])
1682        elif test -f /usr/include/com_err.h -o -f /usr/include/et/com_err.h; then
1683                with_com_err="/usr"
1684                AC_PATH_PROG(COMPILE_ET, /usr/bin/compile_et, [no compile et])
1685        else
1686                # use ours
1687                with_com_err=yes
1688        fi
1689        ])
1690
1691        if test "${with_com_err}" = "no"; then
1692          AC_MSG_WARN([com_err is required; included version will be used.])
1693          with_com_err="yes"
1694        fi
1695        if test "${COMPILE_ET}" = "no compile et" -o "${COMPILE_ET}" = ""; then
1696          AC_MSG_NOTICE([Parts of com_err distribution were found, but not compile_et.])
1697          AC_MSG_NOTICE([Will build com_err from included sources.])
1698          with_com_err="yes" # build it ourselves
1699        fi
1700fi
1701
1702dnl Set up $COMPILE_ET first, we need to test it
1703case "$with_com_err" in
1704    # built-in et
1705    yes) # use the com_err we're gonna build
1706        COMPILE_ET="\${abs_top_builddir}/com_err/et/compile_et"
1707        ;;
1708    "") # no problem, we already have it in the paths
1709        # we do nothing to pick it up
1710        ;;
1711    *)  # use whatever they told us, or whatever we found
1712        COMPILE_ET="${with_com_err}/bin/compile_et"
1713        ;;
1714esac
1715
1716if test "$with_com_err" != yes ; then
1717    dnl Test that the specified compile_et produces correct output
1718    dnl See bug #3711 for why this is necessary
1719    TEST1=".cyrus-configure-test-$$"
1720    /bin/rm -f $TEST1.et $TEST1.h $TEST1.c
1721    echo "error_table imap" >> $TEST1.et
1722    echo "ec IMAP_TESTING," >> $TEST1.et
1723    echo "   \"Testing\"" >> $TEST1.et
1724    echo "end" >> $TEST1.et
1725    "${COMPILE_ET}" $TEST1.et > /dev/null
1726    compile_et_ok=no
1727    if test -f $TEST1.h ; then
1728        dnl Broken compile_et produces (2390157824L)
1729        if test `awk '/IMAP_TESTING/{print $3}' $TEST1.h 2>/dev/null` = "(-1904809472L)" ; then
1730            dnl We need a version that exposes et_[foo]_error_table
1731            if grep -q '^extern const struct error_table et_imap_error_table;' $TEST1.h; then
1732                compile_et_ok=yes
1733            fi
1734        fi
1735    fi
1736    /bin/rm -f $TEST1.et $TEST1.h $TEST1.c
1737    if test "$compile_et_ok" = no ; then
1738        # revert to the built-in compile_et
1739        AC_MSG_WARN([It seems $COMPILE_ET is buggy, building our own])
1740        with_com_err=yes
1741        COMPILE_ET="\${abs_top_builddir}/com_err/et/compile_et"
1742    fi
1743fi
1744
1745case "$with_com_err" in
1746  # built-in et
1747  yes) # use the com_err we're gonna build
1748          COM_ERR_LIBS="com_err/et/libcyrus_com_err.la"
1749          COM_ERR_CPPFLAGS="-I\${top_srcdir}/com_err/et"
1750          ;;
1751  "")   # no problem, we already have it in the paths
1752        # we do nothing to pick it up
1753        COM_ERR_LIBS="-lcom_err" # hope it's not shared
1754        # we already set COMPILE_ET, or we didn't get here
1755        COM_ERR_CPPFLAGS=""
1756      ;;
1757  *) # use whatever they told us, or whatever we found
1758     COM_ERR_LIBS="${with_com_err}/lib/libcom_err.a"
1759     COM_ERR_CPPFLAGS="-I${with_com_err}/include"
1760     # Ever get the feeling people hide this stuff on purpose?
1761     if test -d "${with_com_err}/include/et" ; then
1762       COM_ERR_CPPFLAGS="-I${with_com_err}/include/et"
1763     fi
1764esac
1765AM_CONDITIONAL([COM_ERR], [test "$with_com_err" = "yes"])
1766if test "$with_com_err" = "yes"; then
1767  PKG_CONFIG_COM_ERR_LIB="-lcyrus_com_err"
1768fi
1769AC_SUBST(PKG_CONFIG_COM_ERR_LIB)
1770AC_SUBST(COMPILE_ET)
1771AC_SUBST(COM_ERR_LIBS)
1772AC_SUBST(COM_ERR_CPPFLAGS)
1773
1774if test "$USE_MAINTAINER_MODE" = "yes" ; then
1775    AC_CHECK_PROG(GPERF,gperf,yes,no)
1776    if test "$GPERF" != "yes"; then
1777        AC_MSG_ERROR([gperf is not installed on this system, but is required for maintainer mode build rules])
1778    fi
1779fi
1780
1781AC_MSG_CHECKING(for modern syslog)
1782AC_CACHE_VAL(cyrus_cv_lib_syslog, AC_TRY_CPP([#include <syslog.h>
1783#ifndef LOG_LOCAL6
1784#include </nonexistent>
1785#endif],cyrus_cv_lib_syslog=yes,cyrus_cv_lib_syslog=no))
1786AC_MSG_RESULT($cyrus_cv_lib_syslog)
1787
1788AC_MSG_CHECKING(which syslog facility to use)
1789SYSLOG_FACILITY=LOG_LOCAL6
1790AC_ARG_WITH(syslogfacility,
1791        [AS_HELP_STRING([--with-syslogfacility=FACILITY], [set the syslog facility to use (default LOCAL6)])],
1792               [ if test "$withval" != "yes" -a "$withval" != "no" ; then
1793                       SYSLOG_FACILITY=LOG_$withval
1794               fi; ])
1795AC_DEFINE_UNQUOTED(SYSLOG_FACILITY, $SYSLOG_FACILITY, [Syslog facility to use.])
1796AC_MSG_RESULT($SYSLOG_FACILITY)
1797
1798dnl Have to check getdtabalesize after adding ossup, as some ossups define it
1799AC_REPLACE_FUNCS(getdtablesize)
1800AC_ARG_ENABLE(cmulocal,
1801        [AS_HELP_STRING([--enable-cmulocal], [enable CMU-specific local support])])
1802AM_CONDITIONAL([CMULOCAL], [test "$enable_cmulocal" = "yes"])
1803AC_MSG_CHECKING(to use old sieve service name)
1804AC_ARG_ENABLE(oldsievename,
1805        [AS_HELP_STRING([--enable-oldsievename], [enable the use of 'imap' as the sieve service name])],
1806        if test "$enableval" = yes; then
1807                AC_MSG_RESULT(yes)
1808                AC_DEFINE(OLD_SIEVE_SERVICE_NAME,[],[Use "imap" as sieve service name?])
1809        else
1810                AC_MSG_RESULT(no)
1811        fi,
1812        AC_MSG_RESULT(no))
1813
1814CMU_SASL2_REQUIRE_VER(2,1,7)
1815CMU_SASL2_CHECKAPOP_REQUIRED
1816
1817AC_ARG_WITH(perl,
1818        [AS_HELP_STRING([--with-perl=PERL], [use PERL for perl])],
1819        with_perl="$withval", with_perl="perl")
1820
1821if test "${with_perl}" = yes; then
1822    with_perl="perl"
1823fi
1824if test "${with_perl}" != no; then
1825    if test ${using_static_sasl} = "staticonly"; then
1826        AC_MSG_WARN([Cannot compile perl utilities using static libsasl])
1827        with_perl="no"
1828    else
1829        AC_CHECK_PROGS(PERL, ${with_perl} perl, with_perl=notfound)
1830    fi
1831fi
1832AM_CONDITIONAL([PERL], [test "$with_perl" != "no" -a "$with_perl" != "notfound"])
1833srctoolsdir=`cd ${srcdir};pwd`/tools
1834if test "$with_perl" = "notfound"; then
1835    AC_MSG_WARN(Perl not found: Administrative tools will not be available)
1836elif test "${with_perl}" != "no"; then
1837dnl compile perl stuff and perl/cyradm
1838    PERL="${with_perl}"
1839
1840dnl Make sure perl modules are in the build directory (which isn't necessarily
1841dnl the source directory)
1842    AC_CONFIG_LINKS([perl/sieve/managesieve/managesieve.pm:perl/sieve/managesieve/managesieve.pm])
1843    AC_CONFIG_FILES([perl/sieve/managesieve/MANIFEST])
1844    AC_CONFIG_LINKS([perl/imap/Cyrus/HeaderFile.pm:perl/imap/Cyrus/HeaderFile.pm])
1845    AC_CONFIG_LINKS([perl/imap/Cyrus/CacheFile.pm:perl/imap/Cyrus/CacheFile.pm])
1846    AC_CONFIG_LINKS([perl/imap/Cyrus/IndexFile.pm:perl/imap/Cyrus/IndexFile.pm])
1847    AC_CONFIG_LINKS([perl/imap/Cyrus/DList.pm:perl/imap/Cyrus/DList.pm])
1848    AC_CONFIG_LINKS([perl/imap/Cyrus/ImapClone.pm:perl/imap/Cyrus/ImapClone.pm])
1849    AC_CONFIG_LINKS([perl/imap/Cyrus/SyncProto.pm:perl/imap/Cyrus/SyncProto.pm])
1850    AC_CONFIG_LINKS([perl/imap/IMAP/Shell.pm:perl/imap/IMAP/Shell.pm])
1851    AC_CONFIG_LINKS([perl/imap/IMAP/IMSP.pm:perl/imap/IMAP/IMSP.pm])
1852    AC_CONFIG_LINKS([perl/imap/IMAP/Admin.pm:perl/imap/IMAP/Admin.pm])
1853    AC_CONFIG_LINKS([perl/imap/IMAP.pm:perl/imap/IMAP.pm])
1854    AC_CONFIG_FILES([perl/imap/MANIFEST])
1855    AC_CONFIG_LINKS([perl/annotator/Message.pm:perl/annotator/Message.pm])
1856    AC_CONFIG_LINKS([perl/annotator/AnnotateInlinedCIDs.pm:perl/annotator/AnnotateInlinedCIDs.pm])
1857    AC_CONFIG_LINKS([perl/annotator/Daemon.pm:perl/annotator/Daemon.pm])
1858    AC_CONFIG_FILES([perl/annotator/MANIFEST])
1859
1860dnl add perl cccdlflags when building libraries -- this ensures that the
1861dnl libraries will be compiled as PIC if perl requires PIC objects
1862dnl -- this is needed on NetBSD and Linux, but seems to cause problems on atleast Solaris --
1863    case "${target_os}" in
1864        linux*|netbsd*|freebsd*|dragonfly*)
1865            AC_MSG_CHECKING(for perl cccdlflags needed on "${target_os}")
1866            eval `${PERL} -V:cccdlflags`
1867            PERL_CCCDLFLAGS="$cccdlflags"
1868            AC_SUBST(PERL_CCCDLFLAGS)
1869            AC_MSG_RESULT($PERL_CCCDLFLAGS)
1870            ;;
1871        *)
1872            AC_MSG_WARN(skipping check for perl cccdlflags on "${target_os}")
1873    esac
1874
1875    PERL_PREINSTALL="${PERL} ${srctoolsdir}/fixsearchpath.pl ${prefix} ${bindir}"
1876    AC_SUBST(PERL_PREINSTALL)
1877fi
1878
1879CMU_LIBWRAP
1880CMU_UCDSNMP
1881
1882# Figure out what directories we're linking against.
1883# Lots of fun for the whole family.
1884# This probably chokes on anything with spaces in it.
1885# All we want is the list of -L directories, and -L may or may not be
1886# followed by a space.
1887isdir=no
1888libpath=""
1889#echo "debug ldflags: << ${ldflags} >>"
1890#echo "debug default_ldflags: << ${default_ldflags} >>"
1891for flag in ${ldflags} ${default_ldflags}; do
1892  case $flag in
1893    -L)
1894      # it's a split -L option, we'll mark the next option as a dir.
1895      isdir=yes
1896      ;;
1897
1898    -L*)
1899      # attached -L option: split off the directory
1900      larg=`echo $flag | sed -e 's:-L\(..*\):\1:'`
1901      libpath="${libpath} ${larg}"
1902      ;;
1903
1904    *)
1905      if test $isdir = yes ; then
1906        libpath="${libpath} ${flag}"
1907        isdir=no
1908      fi
1909  esac
1910done
1911
1912AC_SUBST(LIB_SASL)
1913AC_SUBST(LIB_UUID)
1914AC_SUBST(PERL)
1915
1916dnl
1917dnl Enable/disable unit tests.  These are disabled by default, as
1918dnl they require an additional library (the CUnit library).
1919dnl
1920AC_ARG_ENABLE(unit-tests,
1921        [AS_HELP_STRING([--enable-unit-tests], [enable CUnit-based unit regression tests])])
1922
1923dnl Unit tests need the CUnit library, so check if we
1924dnl have both the header and the library.
1925if test "$enable_unit_tests" = "yes" ; then
1926    AC_CHECK_LIB(cunit,CU_initialize_registry,found_lib=yes,found_lib=no)
1927    AC_CHECK_HEADER([CUnit/CUnit.h],found_hdr=yes,found_hdr=no)
1928    if test "$found_lib$found_hdr" != "yesyes" ; then
1929        AC_MSG_NOTICE([Disabling unit tests because the required CUnit library is not installed])
1930        enable_unit_tests=no
1931    fi
1932    AC_CHECK_HEADER([CUnit/Basic.h],
1933        AC_CHECK_TYPE([CU_SetUpFunc],AC_DEFINE(HAVE_CU_SETUPFUNC,[],[Do we have CU_SetUpFunc?]),,
1934            [#include <CUnit/Basic.h>])
1935        ,)
1936fi
1937if test "$enable_unit_tests" = "yes" ; then
1938    dnl Valgrind is an amazingly useful tool for running tests.  It doesn't
1939    dnl need the program under test to be modified in any way, but it we can
1940    dnl optionally use some magic in it's header file to compensate for some
1941    dnl of the shortcomings of a C development environment by giving error
1942    dnl messages with backtraces.  This is so enormously useful for the unit
1943    dnl tests that want to enable it if possible, but we can struggle on
1944    dnl without it.  Besides, on many platforms the header file is in a
1945    dnl different package to the main valgrind binary, and so might not be
1946    dnl installed.
1947    AC_CHECK_HEADERS([valgrind/valgrind.h])
1948
1949    dnl We depend on some data files, which exist in the source directory,
1950    dnl but need to be found at runtime by the built unit tests.
1951    dnl Under VPATH builds the source and build directories are not the same,
1952    dnl so the built unit tests can't easily find their data files.
1953    dnl Solution: just link them into the build directory at the same path.
1954    AC_CONFIG_LINKS([cunit/cacert.pem:cunit/cacert.pem])
1955    AC_CONFIG_LINKS([cunit/cert.pem:cunit/cert.pem])
1956    AC_CONFIG_LINKS([cunit/key.pem:cunit/key.pem])
1957
1958    USE_MAINTAINER_MODE=yes
1959fi
1960
1961AM_CONDITIONAL([CUNIT], [test "$enable_unit_tests" = "yes"])
1962
1963dnl Finally, now that we've checked everything else, we can see whether to link
1964dnl in SQLite or not.
1965dnl
1966if test "x$use_sqlite" = xyes; then
1967  if test "x$HAVE_SQLITE" = x1; then
1968    if test "x$with_sqlite_lib" != xnone; then
1969        CMU_ADD_LIBPATH($with_sqlite_lib)
1970    fi
1971
1972    LIBS="${LIBS} ${SQLITE_LIBADD}"
1973    CPPFLAGS="${SQLITE_INCADD} ${CPPFLAGS}"
1974    AC_DEFINE(HAVE_SQLITE,[],[Build in SQLite support?])
1975    AC_SUBST(SQLITE_LIBADD)
1976  else
1977    AC_MSG_ERROR([SQLite required but not found])
1978  fi
1979fi
1980AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = xyes])
1981
1982
1983dnl CRC32 optimisations
1984
1985dnl if the compiler has support for SSE4.2 then we can compile a hardware
1986dnl implementation of CRC32C
1987AC_MSG_CHECKING(for compiler support for SSE4.2 instruction)
1988AC_CACHE_VAL(cyrus_cv_sse42, AC_TRY_COMPILE([
1989    #include <stdint.h>
1990],[
1991    uint64_t a = 0, b = 1;
1992    __asm__("crc32q\t" "(%1), %0"
1993            : "=r"(b)
1994            : "r"(b), "0"(a));
1995    return b;
1996], cyrus_cv_sse42=yes, cyrus_cv_sse42=no))
1997if test "$cyrus_cv_sse42" = "yes" ; then
1998    AC_DEFINE(HAVE_SSE42,1,"Compiler has support for SSE4.2 extensions")
1999fi
2000AC_MSG_RESULT($cyrus_cv_sse42)
2001
2002dnl documentation generation (sphinx, perl2rst)
2003AC_ARG_VAR(SPHINX_BUILD, [Location of sphinx-build])
2004AC_ARG_WITH([sphinx-build],
2005            AS_HELP_STRING([--with-sphinx-build=(yes|no|PATH)], [Look for sphinx-build in PATH]),
2006            [with_sphinx_build=$withval],
2007            [with_sphinx_build=yes])
2008AS_CASE([$with_sphinx_build],
2009        [yes],  [AC_PATH_PROG(SPHINX_BUILD, sphinx-build)],
2010        [no],   [SPHINX_BUILD=''],
2011        [*],    [AC_PATH_PROG(SPHINX_BUILD, sphinx-build, [], [$with_sphinx_build])])
2012AS_IF([test -z "$SPHINX_BUILD"],
2013      [AC_MSG_WARN([No sphinx-build, won't be able to regenerate docs])])
2014AC_SUBST([SPHINX_BUILD])
2015AX_PROG_PERL_MODULES([Pod::POM::View::Restructured],
2016                     [have_ppvr=yes],
2017                     [AC_MSG_WARN([No Pod::POM::View::Restructured, won't be able to regenerate docs])])
2018AM_CONDITIONAL([HAVE_SPHINX_BUILD], [ test -n "$SPHINX_BUILD" -a x"$have_ppvr" = xyes])
2019
2020AH_TOP([
2021/*
2022 * Copyright (c) 1994-2015 Carnegie Mellon University.  All rights reserved.
2023 *
2024 * Redistribution and use in source and binary forms, with or without
2025 * modification, are permitted provided that the following conditions
2026 * are met:
2027 *
2028 * 1. Redistributions of source code must retain the above copyright
2029 *    notice, this list of conditions and the following disclaimer.
2030 *
2031 * 2. Redistributions in binary form must reproduce the above copyright
2032 *    notice, this list of conditions and the following disclaimer in
2033 *    the documentation and/or other materials provided with the
2034 *    distribution.
2035 *
2036 * 3. The name "Carnegie Mellon University" must not be used to
2037 *    endorse or promote products derived from this software without
2038 *    prior written permission. For permission or any legal
2039 *    details, please contact
2040 *      Carnegie Mellon University
2041 *      Center for Technology Transfer and Enterprise Creation
2042 *      4615 Forbes Avenue
2043 *      Suite 302
2044 *      Pittsburgh, PA  15213
2045 *      (412) 268-7393, fax: (412) 268-7395
2046 *      innovation@andrew.cmu.edu
2047 *
2048 * 4. Redistributions of any form whatsoever must retain the following
2049 *    acknowledgment:
2050 *    "This product includes software developed by Computing Services
2051 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
2052 *
2053 * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
2054 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
2055 * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
2056 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2057 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
2058 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
2059 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2060 */
2061
2062#ifndef _CYRUS_IMAPD_CONFIG_H_
2063#define _CYRUS_IMAPD_CONFIG_H_
2064])
2065
2066AH_BOTTOM([
2067/* time.h */
2068#if TIME_WITH_SYS_TIME
2069# include <sys/time.h>
2070# include <time.h>
2071#else
2072# if HAVE_SYS_TIME_H
2073#  include <sys/time.h>
2074# else
2075#  include <time.h>
2076# endif
2077#endif
2078
2079/* com_err.h, as needed */
2080#ifndef IN_COM_ERR
2081#ifdef HAVE_ET_COM_ERR_H
2082#include <et/com_err.h>
2083#else
2084#include <com_err.h>
2085#endif /* HAVE_ET_COM_ERR_H */
2086#endif /* IN_COM_ERR */
2087
2088/* This allows us to work even when we don't have an fdatasync */
2089#ifndef HAVE_FDATASYNC
2090#define fdatasync(fd) fsync(fd)
2091#endif
2092
2093/* A similar setup for not having O_DSYNC */
2094#include <fcntl.h>
2095
2096#ifndef O_DSYNC
2097#  ifdef O_SYNC
2098#    define O_DSYNC     O_SYNC          /* POSIX */
2099#  else
2100#    define O_DSYNC     O_FSYNC         /* BSD */
2101#  endif
2102#endif
2103
2104#ifndef HAVE_SOCKLEN_T
2105typedef unsigned int socklen_t;
2106#endif
2107
2108#ifndef HAVE_RLIM_T
2109typedef int rlim_t;
2110#endif
2111
2112/* some potentially memory saving tradeoffs,
2113   preconfigured in memory-saving mode */
2114
2115/* save the cmdlines for the ID command */
2116#undef ID_SAVE_CMDLINE
2117
2118/* IPv6 things */
2119#include <netdb.h>
2120#include <sys/types.h>
2121#include <sys/socket.h>
2122#include <netinet/in.h>
2123
2124#ifndef HAVE_STRUCT_SOCKADDR_STORAGE
2125#define _SS_MAXSIZE     128     /* Implementation specific max size */
2126#define _SS_PADSIZE     (_SS_MAXSIZE - sizeof (struct sockaddr))
2127
2128struct sockaddr_storage {
2129        struct  sockaddr ss_sa;
2130        char            __ss_pad2[_SS_PADSIZE];
2131};
2132# define ss_family ss_sa.sa_family
2133# define HAVE_SS_FAMILY
2134#endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */
2135
2136#ifndef AF_INET6
2137/* Define it to something that should never appear */
2138#define AF_INET6        AF_MAX
2139#endif
2140
2141#if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
2142#include "lib/gai.h"
2143#endif
2144
2145/* End IPv6 things */
2146
2147#ifdef OLD_SIEVE_SERVICE_NAME
2148#define SIEVE_SERVICE_NAME "imap"
2149#else
2150#define SIEVE_SERVICE_NAME "sieve"
2151#endif
2152
2153/* filenames */
2154#define FNAME_DBDIR "/db"
2155#define FNAME_USERDIR "/user/"
2156#define FNAME_DOMAINDIR "/domain/"
2157#define FNAME_LOGDIR "/log/"
2158#define FNAME_PTSDB "/ptclient/ptscache.db"
2159#define CONFIG_FILENAME (SYSCONF_DIR "/imapd.conf")
2160#define DEFAULT_MASTER_CONFIG_FILENAME (SYSCONF_DIR "/cyrus.conf")
2161
2162#ifndef HAVE_SHUTDOWN
2163#define shutdown(fd, mode) 0
2164#endif
2165
2166/* *printf() macros */
2167#if (SIZEOF_SIZE_T == SIZEOF_INT)
2168#define SIZE_T_FMT "%u"
2169#elif (SIZEOF_SIZE_T == SIZEOF_LONG)
2170#define SIZE_T_FMT "%lu"
2171#elif (SIZEOF_SIZE_T == SIZEOF_LONG_LONG_INT)
2172#define SIZE_T_FMT "%llu"
2173#else
2174#error dont know what to use for SIZE_T_FMT
2175#endif
2176
2177#if (SIZEOF_OFF_T == SIZEOF_LONG)
2178#define OFF_T_FMT "%ld"
2179#define strtoofft(nptr, endptr, base) strtol(nptr, endptr, base)
2180#elif (SIZEOF_OFF_T == SIZEOF_LONG_LONG_INT)
2181#define OFF_T_FMT "%lld"
2182#define strtoofft(nptr, endptr, base) strtoll(nptr, endptr, base)
2183#else
2184#error dont know what to use for OFF_T_FMT
2185#endif
2186
2187#ifndef HAVE_POSIX_FADVISE
2188#define POSIX_FADV_WILLNEED 0
2189extern int posix_fadvise(int fd, off_t offset, off_t len, int advice);
2190#endif
2191
2192#ifndef HAVE_STRSEP
2193extern char *strsep(char **, const char *);
2194#endif
2195
2196#ifndef HAVE_MEMMEM
2197extern void *memmem(const void *, size_t, const void *, size_t);
2198#endif
2199
2200/* compile time options; think carefully before modifying */
2201enum {
2202    /* should we send an UNAVAILABLE message to master when
2203     * a service is exiting (master is already going to be
2204     * informed of the exit by the SIGCHLD signal anyway) ? */
2205    MESSAGE_MASTER_ON_EXIT = 0,
2206
2207    /* should a hierarchical rename stop on error? */
2208    RENAME_STOP_ON_ERROR = 1,
2209
2210    /* should we call fsync() to maybe help with softupdates? (it should) */
2211    APPEND_ULTRA_PARANOID = 1,
2212
2213    /* should we log extra information at the DEBUG level for DB stuff?
2214     * 0 -> nothing; 1 -> some; higher -> even more */
2215    CONFIG_DB_VERBOSE = 1,
2216
2217    /* log timing information to LOG_DEBUG */
2218    CONFIG_TIMING_VERBOSE = 0,
2219
2220    /* should we be pedantic about namespace or sleezy? */
2221    SLEEZY_NAMESPACE = 1,
2222
2223    /* should we do a fast TLS session shutdown? */
2224    TLS_FAST_SHUTDOWN = 1,
2225
2226    /* should we have long LMTP error messages? */
2227    LMTP_LONG_ERROR_MSGS = 1
2228};
2229
2230#endif /* _CYRUS_IMAPD_CONFIG_H_ */
2231])
2232
2233dnl make sure that Makefile is the last thing output
2234AC_CONFIG_FILES([
2235    libcyrus_imap.pc
2236    libcyrus_min.pc
2237    libcyrus.pc
2238    libcyrus_sieve.pc
2239    Makefile
2240])
2241
2242if test "$with_perl" != "no" -a "$with_perl" != "notfound" ; then
2243CMU_PERL_MAKEMAKER(perl/annotator)
2244CMU_PERL_MAKEMAKER(perl/imap)
2245CMU_PERL_MAKEMAKER(perl/sieve/managesieve)
2246fi
2247
2248dnl check for libicu. we need this for charset conversions.
2249PKG_CHECK_MODULES([ICU], [icu-uc])
2250AC_SUBST([ICU_LIBS])
2251AC_SUBST([ICU_CFLAGS])
2252
2253AC_OUTPUT
2254echo "
2255Cyrus Server configured components
2256
2257   event notification: $enable_event_notification
2258   gssapi:             $gssapi
2259   autocreate:         $enable_autocreate
2260   idled:              $enable_idled
2261   httpd:              $enable_http
2262   kerberos V4:        $krb4
2263   murder:             $enable_murder
2264   nntpd:              $enable_nntp
2265   replication:        $enable_replication
2266   sieve:              $enable_sieve
2267   calalarmd:          $enable_calalarmd
2268   objectstore:        $enable_objectstore
2269   backup:             $enable_backup
2270   com_err:            $with_com_err
2271
2272External dependencies:
2273   ldap:               $have_ldap
2274   openssl:            $with_ssl
2275   zlib:               $with_zlib
2276   pcre:               $cyrus_cv_pcre_utf8
2277   clamav:             $with_clamav
2278   -----------------------
2279   caringo:            $with_caringo
2280   openio:             $with_openio
2281   -----------------------
2282   nghttp2:            $with_nghttp2
2283   brotli:             $with_brotli
2284   xml2:               $with_xml2
2285   ical:               $with_ical
2286   icu4c:              $with_icu4c
2287   shapelib:           $with_shapelib
2288
2289Database support:
2290   mysql:              $with_mysql
2291   postgresql:         $use_pgsql
2292   sqlite:             $use_sqlite
2293   lmdb:               $use_lmdb
2294
2295Search engine:
2296   squat:              $enable_squat
2297   sphinx:             $enable_sphinx
2298   xapian:             $enable_xapian
2299   xapian_flavor:      $xapian_flavor
2300
2301Hardware support:
2302   SSE4.2:             $cyrus_cv_sse42
2303
2304Installation directories:
2305   prefix:             $prefix
2306   sysconfdir:         $sysconfdir
2307"
2308