configure.in
author Timo Sirainen <tss@iki.fi>
Tue Oct 06 10:53:34 2009 -0400 (2009-10-06)
branchHEAD
changeset 9416 4add5c3f13ea
parent 9413 5c5fc2aa299a
child 9444 a5d8d201bd39
permissions -rw-r--r--
Compiling fix for OpenSSL 0.9.7 and older.
     1 AC_PREREQ([2.59])
     2 AC_INIT([Dovecot],[1.2.6],[dovecot@dovecot.org])
     3 AC_CONFIG_SRCDIR([src])
     4 
     5 AM_INIT_AUTOMAKE([foreign])
     6 
     7 AM_MAINTAINER_MODE
     8 
     9 dnl TEST_WITH(name, value, [plugin])
    10 AC_DEFUN([TEST_WITH], [
    11   want=want_`echo $1|sed s/-/_/g`
    12   if test $2 = yes || test $2 = no || test $2 = auto; then
    13     eval $want=$2
    14   elif test $2 = plugin; then
    15     if test "$3" = plugin; then
    16       eval $want=plugin
    17     else
    18       AC_ERROR([--with-$1=plugin not supported])
    19     fi
    20   elif `echo $2|grep '^/' >/dev/null`; then
    21     AC_ERROR([--with-$1=path not supported. You may want to use instead:
    22 CPPFLAGS=-I$2/include LDFLAGS=-L$2/lib ./configure --with-$1])
    23   else
    24     AC_ERROR([--with-$1: Unknown value: $2])
    25   fi
    26 ])
    27 
    28 AC_ARG_ENABLE(devel-checks,
    29 [  --enable-devel-checks   Enable some extra expensive checks for developers],
    30 	if test x$enableval = xyes; then
    31 		AC_DEFINE(DEBUG,, Build with extra debugging checks)
    32 	fi)
    33 
    34 AC_ARG_ENABLE(asserts,
    35 [  --enable-asserts        Enable asserts (default)],
    36 	if test x$enableval = xno; then
    37 		AC_DEFINE(DISABLE_ASSERTS,, Disable asserts)
    38 	fi)
    39 
    40 AC_ARG_WITH(mem-align,
    41 [  --with-mem-align=BYTES  Set the memory alignment (default: 8)],
    42 	mem_align=$withval,
    43 	mem_align=8)
    44 
    45 AC_ARG_WITH(ioloop,
    46 [  --with-ioloop=IOLOOP    Specify the I/O loop method to use
    47                           (epoll, kqueue, poll; best for the fastest available;
    48 			   default is best)],
    49 	ioloop=$withval,
    50 	ioloop=best)
    51 
    52 AC_ARG_WITH(notify,
    53 [  --with-notify=NOTIFY    Specify the file system notification method to use
    54                           (inotify, kqueue, dnotify, none;
    55                            default is detected in the above order)],
    56 	notify=$withval,
    57 	notify=)
    58 
    59 AC_ARG_WITH(passwd,
    60 [  --with-passwd           Build with /etc/passwd support (default)],
    61   TEST_WITH(passwd, $withval),
    62   want_passwd=yes)
    63 
    64 AC_ARG_WITH(nss,
    65 [  --with-nss              Build with NSS module support (auto)],
    66   TEST_WITH(nss, $withval),
    67   want_nss=auto)
    68 
    69 AC_ARG_WITH(passwd-file,
    70 [  --with-passwd-file      Build with passwd-like file support (default)],
    71   TEST_WITH(passwd-file, $withval),
    72   want_passwd_file=yes)
    73 
    74 AC_ARG_WITH(shadow,
    75 [  --with-shadow           Build with shadow password support (auto)],
    76   TEST_WITH(shadow, $withval),
    77   want_shadow=auto)
    78 
    79 AC_ARG_WITH(pam,
    80 [  --with-pam              Build with PAM support (auto)],
    81   TEST_WITH(pam, $withval),
    82   want_pam=auto)
    83 
    84 AC_ARG_WITH(checkpassword,
    85 [  --with-checkpassword    Build with checkpassword support (default)],
    86   TEST_WITH(checkpassword, $withval),
    87   want_checkpassword=yes)
    88 
    89 AC_ARG_WITH(bsdauth,
    90 [  --with-bsdauth          Build with BSD authentication support (auto)],
    91   TEST_WITH(bsdauth, $withval),
    92   want_bsdauth=auto)
    93 
    94 AC_ARG_WITH(gssapi,
    95 [  --with-gssapi=yes|plugin Build with GSSAPI authentication support],
    96   TEST_WITH(gssapi, $withval, plugin),
    97   want_gssapi=no)
    98 
    99 AC_ARG_WITH(sia,
   100 [  --with-sia              Build with Tru64 SIA support],
   101   TEST_WITH(sia, $withval),
   102   want_sia=no)
   103 
   104 AC_ARG_WITH(ldap,
   105 [  --with-ldap=yes|plugin  Build with LDAP support],
   106   TEST_WITH(ldap, $withval, plugin),
   107   want_ldap=no)
   108 
   109 AC_ARG_WITH(vpopmail,
   110 [  --with-vpopmail         Build with vpopmail support (auto)],
   111 	if test x$withval = xno; then
   112 		want_vpopmail=no
   113 	else
   114 		if test x$withval = xyes || test x$withval = xauto; then
   115 			vpopmail_home="`echo ~vpopmail`"
   116 			want_vpopmail=$withval
   117 		else
   118 			vpopmail_home="$withval"
   119 			want_vpopmail=yes
   120 		fi
   121 	fi, [
   122 		want_vpopmail=auto
   123 		vpopmail_home="`echo ~vpopmail`"
   124 	])
   125 
   126 AC_ARG_WITH(static-userdb,
   127 [  --with-static-userdb    Build with static userdb support (default)],
   128   TEST_WITH(static-userdb, $withval),
   129   want_static_userdb=yes)
   130 
   131 AC_ARG_WITH(prefetch-userdb,
   132 [  --with-prefetch-userdb  Build with prefetch userdb support (default)],
   133   TEST_WITH(prefetch-userdb, $withval),
   134   want_prefetch_userdb=yes)
   135 
   136 AC_ARG_WITH(db,
   137 [  --with-db               Build with Berkeley DB support],
   138   TEST_WITH(db, $withval),
   139   want_db=no)
   140 
   141 dnl The --with-sql is useful only if Dovecot is being built with all the SQL
   142 dnl drivers as modules. If any SQL driver is built-in, this option is ignored.
   143 AC_ARG_WITH(sql,
   144 [  --with-sql=yes|plugin   Build with generic SQL support],
   145   TEST_WITH(sql, $withval, plugin),
   146   want_sql=no)
   147 
   148 AC_ARG_WITH(pgsql,
   149 [  --with-pgsql            Build with PostgreSQL driver support],
   150   TEST_WITH(pgsql, $withval),
   151   want_pgsql=no)
   152 
   153 AC_ARG_WITH(mysql,
   154 [  --with-mysql            Build with MySQL driver support],
   155   TEST_WITH(mysql, $withval),
   156   want_mysql=no)
   157 
   158 AC_ARG_WITH(sqlite,
   159 [  --with-sqlite           Build with SQLite3 driver support],
   160   TEST_WITH(sqlite, $withval),
   161   want_sqlite=no)
   162 
   163 AC_ARG_WITH(lucene,
   164 [  --with-lucene           Build with CLucene full text search support],
   165   TEST_WITH(lucene, $withval),
   166   want_lucene=no)
   167 AM_CONDITIONAL(BUILD_LUCENE, test "$want_lucene" = "yes")
   168 
   169 AC_ARG_WITH(solr,
   170 [  --with-solr             Build with Solr full text search support],
   171   TEST_WITH(solr, $withval),
   172   want_solr=no)
   173 
   174 AC_ARG_WITH(zlib,
   175 [  --with-zlib             Build with zlib compression support],
   176   TEST_WITH(zlib, $withval),
   177   want_zlib=auto)
   178 
   179 AC_ARG_WITH(bzlib,
   180 [  --with-bzlib            Build with bzlib compression support],
   181   TEST_WITH(bzlib, $withval),
   182   want_bzlib=auto)
   183 
   184 AC_ARG_WITH(libcap,
   185 [  --with-libcap           Build with libcap support (Dropping capabilities).],
   186   TEST_WITH(libcap, $withval),
   187   want_libcap=auto)
   188 
   189 AC_ARG_WITH(ssl,
   190 [  --with-ssl=gnutls|openssl Build with GNUTLS or OpenSSL (default)],
   191 	if test x$withval = xno; then
   192 		want_gnutls=no
   193 		want_openssl=no
   194 	elif test x$withval = xgnutls; then
   195 		want_gnutls=yes
   196 		want_openssl=no
   197 	elif test x$withval = xopenssl; then
   198 		want_gnutls=no
   199 		want_openssl=yes
   200 	elif test x$withval = xyes; then
   201 		want_gnutls=no
   202 		want_openssl=yes
   203 	else
   204 		AC_ERROR([--with-ssl: Invalid value: $withval])
   205 	fi, [
   206 		want_gnutls=no
   207 		want_openssl=auto
   208 	])
   209 
   210 AC_ARG_WITH(ssldir,
   211 [  --with-ssldir=DIR       SSL base directory for certificates (/etc/ssl)],
   212 	ssldir="$withval",
   213 	ssldir=/etc/ssl
   214 )
   215 AC_SUBST(ssldir)
   216 
   217 AC_ARG_WITH(rundir,
   218 [  --with-rundir=DIR       Runtime data directory (LOCALSTATEDIR/run/dovecot)],
   219 	rundir="$withval",
   220 	rundir=$localstatedir/run/$PACKAGE
   221 )
   222 AC_SUBST(rundir)
   223 
   224 AC_ARG_WITH(statedir,
   225 [  --with-statedir=DIR     Permanent data directory (LOCALSTATEDIR/lib/dovecot)],
   226 	statedir="$withval",
   227 	statedir=$localstatedir/lib/$PACKAGE
   228 )
   229 AC_SUBST(statedir)
   230 
   231 AC_ARG_WITH(gc,
   232 [  --with-gc               Use Boehm garbage collector],
   233   TEST_WITH(gc, $withval),
   234   want_gc=no)
   235 
   236 AC_ARG_WITH(storages,
   237 [  --with-storages         Build with specified mail storage formats
   238                           (maildir mbox dbox cydir)], [
   239 	if test "$withval" = "yes" || test "$withval" = "no"; then
   240 		AC_MSG_ERROR([--with-storages needs storage list as parameter])
   241 	fi
   242 	mail_storages="shared `echo "$withval"|sed 's/,/ /g'`" ],
   243 	mail_storages="shared maildir mbox dbox cydir")
   244 AC_SUBST(mail_storages)
   245 
   246 AC_ARG_WITH(sql-drivers,
   247 [  --with-sql-drivers      Build with specified SQL drivers (all)], [
   248 	sql_drivers=`echo "$withval"|sed 's/,/ /g'` ],
   249 	sql_drivers="all")
   250 
   251 if test "$sql_drivers" = "all" || test "$sql_drivers" = "yes"; then
   252   all_sql_drivers=yes
   253   sql_drivers=
   254 elif test "$sql_drivers" = "no"; then
   255   # --without-sql-drivers given
   256   sql_drivers=
   257 fi
   258 not_sql_drivers=
   259 
   260 AC_ARG_WITH(moduledir,
   261 [  --with-moduledir=DIR    Base directory for dynamically loadable modules],
   262 	moduledir="$withval",
   263 	moduledir=$libdir/dovecot
   264 )
   265 AC_SUBST(moduledir)
   266 
   267 AC_ARG_WITH(docs,
   268 [  --with-docs             Install documentation (default)],
   269 	if test x$withval = xno; then
   270 		want_docs=no
   271 	else
   272 		want_docs=yes
   273 	fi,
   274 	want_docs=yes)
   275 AM_CONDITIONAL(BUILD_DOCS, test "$want_docs" = "yes")
   276 
   277 AC_ARG_ENABLE(header-install,
   278 [  --enable-header-install Install development headers],
   279 	if test x$enableval = xno; then
   280 		want_headers=no
   281 	else
   282 		want_headers=yes
   283 	fi,
   284 	want_headers=no)
   285 AM_CONDITIONAL(INSTALL_HEADERS, test "$want_headers" = "yes")
   286 
   287 AC_ISC_POSIX
   288 AC_PROG_CC
   289 AC_PROG_CPP
   290 AC_PROG_CXX # lucene plugin needs this
   291 AC_HEADER_STDC
   292 AC_C_INLINE
   293 AC_PROG_LIBTOOL
   294 AM_ICONV
   295 
   296 AC_CHECK_HEADERS(strings.h stdint.h unistd.h dirent.h malloc.h inttypes.h \
   297   sys/uio.h sys/sysmacros.h sys/resource.h sys/select.h libgen.h \
   298   sys/quota.h sys/fs/ufs_quota.h ufs/ufs/quota.h jfs/quota.h sys/fs/quota_common.h \
   299   mntent.h sys/mnttab.h sys/event.h sys/time.h sys/mkdev.h linux/dqblk_xfs.h \
   300   xfs/xqm.h execinfo.h ucontext.h malloc_np.h sys/utsname.h sys/vmount.h \
   301   sys/utsname.h glob.h)
   302 
   303 dnl * gcc specific options
   304 if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
   305 	# -Wcast-qual -Wcast-align -Wconversion -Wunreachable-code # too many warnings
   306 	# -Wstrict-prototypes -Wredundant-decls # may give warnings in some systems
   307 	# -Wmissing-format-attribute -Wmissing-noreturn -Wwrite-strings # a couple of warnings
   308 	CFLAGS="$CFLAGS -Wall -W -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wchar-subscripts -Wformat=2 -Wbad-function-cast"
   309 
   310 	AC_TRY_COMPILE([
   311 	#if __GNUC__ < 4
   312 	#  error old gcc
   313 	#endif
   314 	],,[
   315 	  # gcc4
   316 	  CFLAGS="$CFLAGS -Wstrict-aliasing=2"
   317 	])
   318 
   319 	# Use std=gnu99 if we have new enough gcc
   320 	old_cflags=$CFLAGS
   321 	CFLAGS="-std=gnu99"
   322 	AC_TRY_COMPILE([
   323 	],, [
   324 	  CFLAGS="$CFLAGS $old_cflags"
   325 	], [
   326 	  CFLAGS="$old_cflags"
   327 	])
   328 fi
   329 
   330 dnl **
   331 dnl ** just some generic stuff...
   332 dnl **
   333 
   334 AC_SEARCH_LIBS(socket, socket)
   335 AC_SEARCH_LIBS(inet_addr, nsl)
   336 AC_SEARCH_LIBS(fdatasync, rt, [
   337   AC_DEFINE(HAVE_FDATASYNC,, Define if you have fdatasync())
   338 ])
   339 
   340 if test $want_libcap != no; then
   341   AC_CHECK_LIB(cap, cap_init, [
   342     AC_DEFINE(HAVE_LIBCAP,, libcap is installed for cap_init())
   343     LIBCAP="-lcap"
   344     AC_SUBST(LIBCAP)
   345   ], [
   346     if test "$want_libcap" = "yes"; then
   347       AC_ERROR([Can't build with libcap support: libcap not found])
   348     fi
   349   ])
   350 fi
   351 
   352 AC_DEFINE(PACKAGE_WEBPAGE, "http://www.dovecot.org/", Support URL)
   353 
   354 dnl * after -lsocket and -lnsl tests, inet_aton() may be in them
   355 AC_CHECK_FUNCS(fcntl flock lockf inet_aton sigaction getpagesize madvise \
   356                strcasecmp stricmp vsyslog writev pread uname unsetenv \
   357 	       setrlimit setproctitle seteuid setreuid setegid setresgid \
   358 	       strtoull strtoll strtouq strtoq \
   359 	       setpriority quotactl getmntent kqueue kevent backtrace_symbols \
   360 	       walkcontext dirfd clearenv malloc_usable_size glob)
   361 
   362 AC_CHECK_LIB(rt, clock_gettime, [
   363   AC_DEFINE(HAVE_CLOCK_GETTIME,, Define if you have the clock_gettime function)
   364   LIBS="$LIBS -lrt"
   365 ], [
   366   # OpenBSD
   367   AC_CHECK_FUNCS(clock_gettime)
   368 ])
   369 
   370 dnl strtoimax and strtoumax are macros in HP-UX, so inttypes.h must be included
   371 dnl Link instead of just compiling since there's something wrong with Tru64
   372 AC_MSG_CHECKING([for strtoimax])
   373 AC_TRY_LINK([
   374   #include <inttypes.h>
   375 ], [
   376   strtoimax(0, 0, 0);
   377 ], [
   378   AC_DEFINE(HAVE_STRTOIMAX,, Define if you have strtoimax function)
   379   AC_MSG_RESULT(yes)
   380 ], [
   381   AC_MSG_RESULT(no)
   382 ])
   383 
   384 AC_MSG_CHECKING([for strtoumax])
   385 AC_TRY_LINK([
   386   #include <inttypes.h>
   387 ], [
   388   strtoumax(0, 0, 0);
   389 ], [
   390   AC_DEFINE(HAVE_STRTOUMAX,, Define if you have strtoumax function)
   391   AC_MSG_RESULT(yes)
   392 ], [
   393   AC_MSG_RESULT(no)
   394 ])
   395 
   396 dnl * I/O loop function
   397 have_ioloop=no
   398 
   399 if test "$ioloop" = "best" || test "$ioloop" = "epoll"; then
   400   AC_CACHE_CHECK([whether we can use epoll],i_cv_epoll_works,[
   401     AC_TRY_RUN([
   402       #include <sys/epoll.h>
   403   
   404       int main()
   405       {
   406 	return epoll_create(5) < 1;
   407       }
   408     ], [
   409       i_cv_epoll_works=yes
   410     ], [
   411       i_cv_epoll_works=no
   412     ])
   413   ])
   414   if test $i_cv_epoll_works = yes; then
   415     AC_DEFINE(IOLOOP_EPOLL,, Implement I/O loop with Linux 2.6 epoll())
   416     have_ioloop=yes
   417     ioloop=epoll
   418   else
   419     if test "$ioloop" = "epoll" ; then
   420       AC_MSG_ERROR([epoll ioloop requested but epoll_create() is not available])
   421     fi
   422   fi
   423 fi
   424 
   425 if test "$ioloop" = "best" || test "$ioloop" = "kqueue"; then
   426     if test "$ac_cv_func_kqueue" = yes && test "$ac_cv_func_kevent" = yes; then
   427       AC_DEFINE(IOLOOP_KQUEUE,, [Implement I/O loop with BSD kqueue()])
   428       ioloop=kqueue
   429       have_ioloop=yes
   430     elif test "$ioloop" = "kqueue"; then
   431       AC_MSG_ERROR([kqueue ioloop requested but kqueue() is not available])
   432     fi
   433 fi
   434 
   435 if test "$ioloop" = "best" || test "$ioloop" = "poll"; then
   436   AC_CHECK_FUNC(poll, [
   437     AC_DEFINE(IOLOOP_POLL,, Implement I/O loop with poll())
   438     ioloop=poll
   439     have_ioloop=yes
   440   ])
   441 fi
   442 
   443 if test "$have_ioloop" = "no"; then
   444   AC_DEFINE(IOLOOP_SELECT,, Implement I/O loop with select())
   445   ioloop="select"
   446 fi
   447 
   448 have_notify=none
   449 
   450 if test "$notify" = "" || test "$notify" = "inotify" ; then
   451   dnl * inotify?
   452   AC_CACHE_CHECK([whether we can use inotify],i_cv_inotify_works,[
   453     AC_TRY_RUN([
   454       #define _GNU_SOURCE
   455       #include <sys/ioctl.h>
   456       #include <fcntl.h>
   457       #include <sys/inotify.h>
   458       #include <stdio.h>
   459     
   460       int main()
   461       {
   462 	int wd, fd;
   463 	char * fn = "/tmp";
   464       
   465 	fd = inotify_init ();
   466 	if (fd < 0)
   467 	  {
   468 	    perror ("inotify_init");
   469 	    return 1;
   470 	  }
   471   
   472 	wd = inotify_add_watch (fd, fn, IN_ALL_EVENTS);
   473   
   474 	if (wd < 0)
   475 	  {
   476 	    perror ("inotify_add_watch");
   477 	    return 2;
   478 	  }
   479   
   480 	inotify_rm_watch (fd, wd);
   481   
   482 	close (fd);
   483 	return 0;
   484       }
   485     ], [
   486       i_cv_inotify_works=yes
   487     ], [
   488       i_cv_inotify_works=no
   489     ])
   490   ])
   491   if test $i_cv_inotify_works = yes; then
   492     have_notify=inotify
   493     notify=inotify
   494     AC_DEFINE(IOLOOP_NOTIFY_INOTIFY,, Use Linux inotify)
   495   else
   496     if test "$notify" = "inotify"; then
   497       AC_MSG_ERROR([inotify requested but not available])
   498       notify=""
   499     fi
   500   fi
   501 fi
   502 
   503 if (test "$notify" = "" && test "$ioloop" = kqueue) || test "$notify" = "kqueue"; then
   504   AC_MSG_CHECKING([if we can use BSD kqueue() notify])
   505   dnl * BSD kqueue() notify
   506   if test "$ac_cv_func_kqueue" = yes && test "$ac_cv_func_kevent" = yes ; then
   507     have_notify=kqueue
   508     notify=kqueue
   509     AC_MSG_RESULT("yes")
   510     AC_DEFINE(IOLOOP_NOTIFY_KQUEUE,,
   511       Use BSD kqueue directory changes notificaton)
   512   else 
   513     AC_MSG_RESULT("no")
   514     if test "$notfify" = "kqueue" ; then
   515       AC_MSG_ERROR([kqueue notify requested but kqueue() is not available])
   516       notify=""
   517     fi
   518   fi
   519 fi
   520 
   521 if test "$notify" = "" || test "$notify" = "dnotify"; then
   522   AC_MSG_CHECKING([whether we can use dnotify])
   523   dnl * dnotify?
   524   AC_TRY_COMPILE([
   525     #define _GNU_SOURCE
   526     #include <fcntl.h>
   527     #include <signal.h>
   528     #include <unistd.h>
   529   ], [
   530     fcntl(0, F_SETSIG, SIGRTMIN);
   531     fcntl(0, F_NOTIFY, DN_CREATE | DN_DELETE | DN_RENAME | DN_MULTISHOT);
   532   ], [
   533     AC_MSG_RESULT(yes)
   534     AC_DEFINE(IOLOOP_NOTIFY_DNOTIFY,, Use Linux dnotify)
   535     have_notify=dnotify
   536     notify=dnotify
   537   ], [
   538     AC_MSG_RESULT(no)
   539     if test "$notify" = "dnotify"; then
   540       AC_MSG_ERROR([dnotify requested but not available])
   541     fi
   542   ])
   543 fi
   544 
   545 if test "$have_notify" = "none"; then
   546   AC_DEFINE(IOLOOP_NOTIFY_NONE,, No special notify support)
   547 fi
   548 
   549 dnl * GLIBC?
   550 AC_TRY_COMPILE([
   551   #include <stdlib.h>
   552   #ifdef __GLIBC__
   553     we have glibc
   554   #endif
   555 ],,, [
   556   AC_DEFINE(PREAD_WRAPPERS,, Define if pread/pwrite needs _XOPEN_SOURCE 500)
   557 ])
   558 
   559 dnl * Old glibcs have broken posix_fallocate(). Make sure not to use it.
   560 dnl * It may also be broken in AIX.
   561 AC_CACHE_CHECK([whether posix_fallocate() works],i_cv_posix_fallocate_works,[
   562   AC_TRY_RUN([
   563     #define _XOPEN_SOURCE 600
   564     #include <stdio.h>
   565     #include <stdlib.h>
   566     #include <fcntl.h>
   567     #include <unistd.h>
   568     #if defined(__GLIBC__) && (__GLIBC__ < 2 || __GLIBC_MINOR__ < 7)
   569       possibly broken posix_fallocate
   570     #endif
   571     int main() {
   572       int fd = creat("conftest.temp", 0600);
   573       int ret;
   574       if (fd == -1) {
   575 	perror("creat()");
   576 	return 2;
   577       }
   578       ret = posix_fallocate(fd, 1024, 1024) < 0 ? 1 : 0;
   579       unlink("conftest.temp");
   580       return ret;
   581     }
   582   ], [
   583     i_cv_posix_fallocate_works=yes
   584   ], [
   585     i_cv_posix_fallocate_works=no
   586   ])
   587 ])
   588 if test $i_cv_posix_fallocate_works = yes; then
   589   AC_DEFINE(HAVE_POSIX_FALLOCATE,, Define if you have a working posix_fallocate())
   590 fi
   591 
   592 dnl * OS specific options
   593 case "$host_os" in
   594 	hpux*)
   595 		CFLAGS="$CFLAGS -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"
   596 		# for getting fd_send/fd_recv working:
   597 		LDFLAGS="$LDFLAGS -Wl,+b,:"
   598 		LIBS="-lxnet $LIBS"
   599 		AC_DEFINE(PREAD_BROKEN,, Defint if pread/pwrite implementation is broken)
   600 		;;
   601 	*)
   602 		;;
   603 esac
   604 
   605 AC_CHECK_SIZEOF(int)
   606 AC_CHECK_SIZEOF(long)
   607 AC_CHECK_SIZEOF(void *)
   608 AC_CHECK_SIZEOF(long long)
   609 
   610 AC_DEFUN([AC_TYPEOF], [
   611   dnl * first check if we can get the size with redefining typedefs
   612 
   613   order="$2"
   614   if test "$2" = ""; then
   615     order="int long long-long"
   616   fi
   617 
   618   result=""
   619   visible="unknown"
   620   AC_MSG_CHECKING([type of $1])
   621 
   622   if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
   623     dnl * try with printf() + -Werror
   624     old_CFLAGS="$CFLAGS"
   625     CFLAGS="$CFLAGS -Werror"
   626 
   627     for type in $order; do
   628       case "$type" in
   629         int)
   630 	  fmt="%d"
   631 	  ;;
   632         unsigned-int)
   633 	  fmt="%u"
   634 	  ;;
   635         long)
   636 	  fmt="%ld"
   637 	  ;;
   638         unsigned-long)
   639 	  fmt="%lu"
   640 	  ;;
   641         long-long)
   642 	  fmt="%lld"
   643 	  ;;
   644         unsigned-long-long)
   645 	  fmt="%llu"
   646 	  ;;
   647 	*)
   648 	  fmt=""
   649 	  ;;
   650       esac
   651 
   652       if test "$fmt" != ""; then
   653 	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   654 	  #include <sys/types.h>
   655 	  #include <stdio.h>
   656 	]], [[
   657 	  printf("$fmt", ($1)0);
   658 	]])],[
   659 	  if test "$result" != ""; then
   660 	    dnl * warning check isn't working
   661 	    result=""
   662 	    visible="unknown"
   663 	    break
   664 	  fi
   665 	  result="`echo $type|sed 's/-/ /g'`"
   666 	  visible="$result"
   667 	],[])
   668       fi
   669     done
   670     CFLAGS="$old_CFLAGS"
   671   fi
   672 
   673   if test "$result" = ""; then
   674     for type in $order; do
   675       type="`echo $type|sed 's/-/ /g'`"
   676       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   677 	#include <sys/types.h>
   678 	typedef $type $1;
   679       ]], [[]])],[
   680 	if test "$result" != ""; then
   681 	  dnl * compiler allows redefining to anything
   682 	  result=""
   683 	  visible="unknown"
   684 	  break
   685 	fi
   686 	result="$type"
   687 	visible="$type"
   688       ],[])
   689     done
   690   fi
   691 
   692   if test "$result" = ""; then
   693     dnl * check with sizes
   694 
   695     dnl * older autoconfs don't include sys/types.h, so do it manually
   696     AC_RUN_IFELSE([AC_LANG_SOURCE([[
   697       #include <stdio.h>
   698       #include <sys/types.h>
   699       int main() {
   700 	FILE *f=fopen("conftestval", "w");
   701 	if (!f) exit(1);
   702 	fprintf(f, "%d\n", sizeof($1));
   703 	exit(0);
   704       }
   705     ]])],[
   706       size=`cat conftestval`
   707       rm -f conftestval
   708 
   709       for type in $order; do
   710         actype="ac_cv_sizeof_`echo $type|sed 's/-/_/g'`"
   711         if test "$size" = "`eval echo \\$$actype`"; then
   712 	  result="`echo $type|sed 's/-/ /g'`"
   713 	  visible="`expr $size \* 8`bit (using $result)"
   714 	  break
   715 	fi
   716       done
   717       if test "$result" = ""; then
   718         result=unknown
   719 	visible="`expr $size \* 8`bit (unknown type)"
   720       fi
   721     ],[],[])
   722   fi
   723 
   724   typeof_$1=$result
   725   AC_MSG_RESULT($visible)
   726 ])
   727 
   728 AC_SYS_LARGEFILE
   729 AC_CHECK_TYPES(_Bool)
   730 
   731 AC_CHECK_TYPE(uoff_t, [
   732   have_uoff_t=yes
   733   AC_DEFINE(HAVE_UOFF_T,, Define if you have a native uoff_t type)
   734 ], [
   735   have_uoff_t=no
   736 ])
   737 
   738 AC_TYPEOF(off_t, long int long-long)
   739 case "$typeof_off_t" in
   740   int)
   741     offt_max=INT_MAX
   742     uofft_fmt="u"
   743     if test "$have_uoff_t" != "yes"; then
   744       AC_DEFINE(UOFF_T_INT,, Define if off_t is int)
   745     fi
   746     offt_bits=`expr 8 \* $ac_cv_sizeof_int`
   747     ;;
   748   long)
   749     offt_max=LONG_MAX
   750     uofft_fmt="lu"
   751     if test "$have_uoff_t" != "yes"; then
   752       AC_DEFINE(UOFF_T_LONG,, Define if off_t is long)
   753     fi
   754     offt_bits=`expr 8 \* $ac_cv_sizeof_long`
   755     ;;
   756   "long long")
   757     offt_max=LLONG_MAX
   758     uofft_fmt="llu"
   759     if test "$have_uoff_t" != "yes"; then
   760       AC_DEFINE(UOFF_T_LONG_LONG,, Define if off_t is long long)
   761     fi
   762     offt_bits=`expr 8 \* $ac_cv_sizeof_long_long`
   763     ;;
   764   *)
   765     AC_MSG_ERROR([Unsupported off_t type])
   766     ;;
   767 esac
   768 
   769 dnl * Do we have struct dirent->d_type
   770 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   771   #include <dirent.h>
   772 ]], [[
   773   struct dirent d;
   774   d.d_type = DT_DIR;
   775 ]])],[
   776   AC_DEFINE(HAVE_DIRENT_D_TYPE,, Define if you have struct dirent->d_type)
   777 ],[])
   778 
   779 dnl * Do we have OFF_T_MAX?
   780 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   781   #include <limits.h>
   782   #include <sys/types.h>
   783 ]], [[
   784   off_t i = OFF_T_MAX;
   785 ]])],[
   786   :
   787 ],[
   788   AC_DEFINE_UNQUOTED(OFF_T_MAX, $offt_max, Maximum value of off_t)
   789 ])
   790 
   791 AC_DEFINE_UNQUOTED(PRIuUOFF_T, "$uofft_fmt", printf() format for uoff_t)
   792 
   793 dnl * make sure size_t isn't signed. we'd probably work fine with it, but
   794 dnl * it's more likely vulnerable to buffer overflows. Anyway, C99 specifies
   795 dnl * that it's unsigned and only some old systems define it as signed.
   796 AC_CACHE_CHECK([whether size_t is signed],i_cv_signed_size_t,[
   797   AC_RUN_IFELSE([AC_LANG_SOURCE([[
   798     #include <sys/types.h>
   799     int main() {
   800       /* return 0 if we're signed */
   801       exit((size_t)(int)-1 <= 0 ? 0 : 1);
   802     }
   803   ]])],[
   804     i_cv_signed_size_t=yes
   805 
   806     echo
   807     echo "Your system's size_t is a signed integer, Dovecot isn't designed to"
   808     echo "support it. It probably works just fine, but it's less resistant to"
   809     echo "buffer overflows. If you're not worried about this and still want to"
   810     echo "compile Dovecot, set ignore_signed_size=1 environment."
   811   
   812     if test "$ignore_signed_size" = ""; then
   813       AC_MSG_ERROR([aborting])
   814     fi
   815     echo "..ignoring as requested.."
   816   ],[
   817     i_cv_signed_size_t=no
   818   ],[])
   819 ])
   820 dnl Note: we check size_t rather than ssize_t here, because on OSX 10.2
   821 dnl ssize_t = int and size_t = unsigned long. We're mostly concerned about
   822 dnl printf format here, so check the size_t one.
   823 AC_TYPEOF(size_t, unsigned-int unsigned-long unsigned-long-long)
   824 case "$typeof_size_t" in
   825   "unsigned long")
   826     ssizet_max=LONG_MAX
   827     sizet_fmt="lu"
   828     ;;
   829   "unsigned long long")
   830     ssizet_max=LLONG_MAX
   831     sizet_fmt="llu"
   832     ;;
   833   *)
   834     dnl older systems didn't have ssize_t, default to int
   835     ssizet_max=INT_MAX
   836     sizet_fmt="u"
   837 
   838     if test "$typeof_size_t" = ""; then
   839       AC_DEFINE(size_t, unsigned int, Define to 'unsigned int' if you don't have it)
   840       AC_DEFINE(ssize_t, int, Define to 'int' if you don't have it)
   841     fi
   842     ;;
   843 esac
   844 
   845 AC_DEFINE_UNQUOTED(SSIZE_T_MAX, $ssizet_max, Maximum value of ssize_t)
   846 AC_DEFINE_UNQUOTED(PRIuSIZE_T, "$sizet_fmt", printf() format for size_t)
   847 
   848 AC_DEFUN([AC_CHECKTYPE2], [
   849   AC_MSG_CHECKING([for $1])
   850   AC_CACHE_VAL(i_cv_type_$1,
   851   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   852   #include <sys/types.h>
   853   $2]], [[$1 t;]])],[i_cv_type_$1=yes],[i_cv_type_$1=no])])
   854   AC_MSG_RESULT($i_cv_type_$1)
   855 ])
   856 
   857 dnl some systems don't have stdint.h, but still have some of the types
   858 dnl defined elsewhere
   859 AC_CHECK_HEADER(stdint.h, [
   860   stdint_include="#include <stdint.h>"
   861 ])
   862 
   863 AC_CHECKTYPE2(uintmax_t, [$stdint_include])
   864 if test $i_cv_type_uintmax_t = yes; then
   865   AC_DEFINE(HAVE_UINTMAX_T,, Define if you have uintmax_t (C99 type))
   866 fi
   867 
   868 dnl use separate check, eg. Solaris 8 has uintmax_t but not uint_fast32_t
   869 AC_CHECKTYPE2(uint_fast32_t, [$stdint_include])
   870 if test $i_cv_type_uint_fast32_t = yes; then
   871   AC_DEFINE(HAVE_UINT_FAST32_T,, Define if you have uint_fast32_t (C99 type))
   872 fi
   873 
   874 AC_CHECKTYPE2(socklen_t, [#include <sys/socket.h>])
   875 if test $i_cv_type_socklen_t = yes; then
   876   AC_DEFINE(HAVE_SOCKLEN_T,, Define to 'int' if you don't have socklen_t)
   877 fi
   878 
   879 AC_DEFINE_UNQUOTED(MEM_ALIGN_SIZE, $mem_align, Required memory alignment)
   880 
   881 dnl * find random source
   882 AC_MSG_CHECKING([for OpenBSD /dev/arandom])
   883 if test -c /dev/arandom; then
   884   AC_MSG_RESULT(yes)
   885   AC_DEFINE(DEV_URANDOM_PATH, "/dev/arandom", Path to /dev/urandom)
   886   have_random_source=yes
   887 else
   888   AC_MSG_RESULT(no)
   889   AC_MSG_CHECKING([for /dev/urandom])
   890   if test -c /dev/urandom || test -s /dev/urandom; then
   891     AC_MSG_RESULT(yes)
   892     AC_DEFINE(DEV_URANDOM_PATH, "/dev/urandom", Path to /dev/urandom)
   893     have_random_source=yes
   894   else
   895     AC_MSG_RESULT(no)
   896   fi
   897 fi
   898 
   899 if test "$have_random_source" != "yes"; then
   900   AC_CHECK_HEADER(openssl/rand.h, [
   901     AC_DEFINE(HAVE_OPENSSL_RAND_H,, Define if you have openssl/rand.h)
   902     LIBS="$LIBS -lcrypto"
   903   ])
   904 fi
   905 
   906 dnl * do we have tm_gmtoff
   907 AC_MSG_CHECKING([for tm_gmtoff])
   908 AC_CACHE_VAL(i_cv_field_tm_gmtoff,
   909 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
   910 #include <time.h>]],
   911 [[struct tm *tm; return tm->tm_gmtoff;]])],
   912 [i_cv_field_tm_gmtoff=yes],
   913 [i_cv_field_tm_gmtoff=no])])
   914 if test $i_cv_field_tm_gmtoff = yes; then
   915 	AC_DEFINE(HAVE_TM_GMTOFF,, Define if you have struct tm->tm_gmtoff)
   916 fi
   917 AC_MSG_RESULT($i_cv_field_tm_gmtoff)
   918 
   919 dnl * how large time_t values does gmtime() accept?
   920 AC_CACHE_CHECK([how large time_t values gmtime() accepts],i_cv_gmtime_max_time_t,[
   921   AC_RUN_IFELSE([AC_LANG_SOURCE([[
   922     #include <stdio.h>
   923     #include <time.h>
   924     int main() {
   925       FILE *f;
   926       int bits;
   927   
   928       for (bits = 1; bits < sizeof(time_t)*8; bits++) {
   929 	time_t t = ((time_t)1 << bits) - 1;
   930 	if (gmtime(&t) == NULL) {
   931 	  bits--;
   932 	  break;
   933 	}
   934       }
   935       if (bits > 40) {
   936 	/* Solaris 9 breaks after 55 bits. Perhaps other systems break earlier.
   937 	   Let's just do the same as Cyrus folks and limit it to 40 bits. */
   938 	bits = 40;
   939       }
   940   
   941       f = fopen("conftest.temp", "w");
   942       if (f == NULL) {
   943 	perror("fopen()");
   944 	return 1;
   945       }
   946       fprintf(f, "%d", bits);
   947       fclose(f);
   948       return 0;
   949     }
   950   ]])],[
   951     i_cv_gmtime_max_time_t=`cat conftest.temp`
   952     rm -f conftest.temp
   953   ], [
   954     printf "check failed, assuming "
   955     i_cv_gmtime_max_time_t=31
   956   ],[])
   957 ])
   958 AC_DEFINE_UNQUOTED(TIME_T_MAX_BITS, $i_cv_gmtime_max_time_t, max. time_t bits gmtime() can handle)
   959 
   960 AC_CACHE_CHECK([whether time_t is signed],i_cv_signed_time_t,[
   961   AC_RUN_IFELSE([AC_LANG_SOURCE([[
   962     #include <sys/types.h>
   963     int main() {
   964       /* return 0 if we're signed */
   965       exit((time_t)(int)-1 <= 0 ? 0 : 1);
   966     }
   967   ]])],[
   968     i_cv_signed_time_t=yes
   969   ], [
   970     i_cv_signed_time_t=no
   971   ])
   972 ])
   973 if test $i_cv_signed_time_t = yes; then
   974   AC_DEFINE(TIME_T_SIGNED,, Define if your time_t is signed)
   975 fi
   976 
   977 dnl Our implementation of AC_C_FLEXIBLE_ARRAY_MEMBER.
   978 dnl Use it until autoconf 2.61+ becomes more widely used
   979 AC_MSG_CHECKING([if we can use C99-like flexible array members])
   980 AC_TRY_COMPILE([
   981   struct foo {
   982     int x;
   983     char y[];
   984   };
   985 ], [
   986   struct foo foo;
   987 ], [
   988   flexible_value=""
   989   AC_MSG_RESULT(yes)
   990 ], [
   991   flexible_value=1
   992   AC_MSG_RESULT(no)
   993 ])
   994 AC_DEFINE_UNQUOTED(FLEXIBLE_ARRAY_MEMBER, $flexible_value, How to define flexible array members in structs)
   995 
   996 dnl * do we have struct iovec
   997 AC_MSG_CHECKING([for struct iovec])
   998 AC_CACHE_VAL(i_cv_struct_iovec,
   999 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1000 #include <sys/types.h>
  1001 #include <sys/uio.h>
  1002 #include <unistd.h>]],
  1003 [[struct iovec *iovec;]])],
  1004 [i_cv_struct_iovec=yes],
  1005 [i_cv_struct_iovec=no])])
  1006 
  1007 if test $i_cv_struct_iovec = yes; then
  1008 	AC_DEFINE(HAVE_STRUCT_IOVEC,, Define if you have struct iovec)
  1009 fi
  1010 AC_MSG_RESULT($i_cv_struct_iovec)
  1011 
  1012 dnl * is dev_t an integer or something else?
  1013 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1014   #include <sys/types.h>
  1015   struct test { dev_t a; };
  1016   static struct test t = { 0 };
  1017 ]], [[]])],[],[
  1018   AC_DEFINE(DEV_T_STRUCT,, Define if your dev_t is a structure instead of integer type)
  1019 
  1020   dnl we can't initialize structures, so don't warn about them either
  1021   if test "x$ac_cv_c_compiler_gnu" = "xyes"; then
  1022     CFLAGS=`echo $CFLAGS|sed 's/ -W\b//'`
  1023   fi
  1024 ])
  1025 
  1026 dnl * Do we have RLIMIT_AS?
  1027 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1028   #include <sys/types.h>
  1029   #include <sys/time.h>
  1030   #include <sys/resource.h>
  1031 ]], [[
  1032   struct rlimit r;
  1033   getrlimit(RLIMIT_AS, &r);
  1034 ]])],[
  1035   AC_DEFINE(HAVE_RLIMIT_AS,, Define if you have RLIMIT_AS for setrlimit())
  1036 ],[])
  1037 
  1038 dnl * Do we have RLIMIT_NPROC?
  1039 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1040   #include <sys/types.h>
  1041   #include <sys/time.h>
  1042   #include <sys/resource.h>
  1043 ]], [[
  1044   struct rlimit r;
  1045   getrlimit(RLIMIT_NPROC, &r);
  1046 ]])],[
  1047   AC_DEFINE(HAVE_RLIMIT_NPROC,, Define if you have RLIMIT_NPROC for setrlimit())
  1048 ],[])
  1049 
  1050 dnl * Do we have RLIMIT_CORE?
  1051 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1052   #include <sys/types.h>
  1053   #include <sys/time.h>
  1054   #include <sys/resource.h>
  1055 ]], [[
  1056   struct rlimit r;
  1057   getrlimit(RLIMIT_CORE, &r);
  1058 ]])],[
  1059   AC_DEFINE(HAVE_RLIMIT_CORE,, Define if you have RLIMIT_CORE for getrlimit())
  1060 ],[])
  1061 
  1062 AC_MSG_CHECKING([PR_SET_DUMPABLE])
  1063 AC_TRY_LINK([
  1064   #include <sys/prctl.h>
  1065 ], [
  1066   prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
  1067 ], [
  1068   AC_DEFINE(HAVE_PR_SET_DUMPABLE,, Define if you have prctl(PR_SET_DUMPABLE))
  1069   AC_MSG_RESULT(yes)
  1070 ], [
  1071   AC_MSG_RESULT(no)
  1072 ])
  1073 
  1074 dnl * Linux compatible mremap()
  1075 AC_MSG_CHECKING([Linux compatible mremap()])
  1076 AC_TRY_LINK([
  1077   #include <unistd.h>
  1078   #define __USE_GNU
  1079   #include <sys/mman.h>
  1080 ], [
  1081   mremap(0, 0, 0, MREMAP_MAYMOVE);
  1082 ], [
  1083   AC_DEFINE(HAVE_LINUX_MREMAP,, Define if you have Linux-compatible mremap())
  1084   AC_MSG_RESULT(yes)
  1085 ], [
  1086   AC_MSG_RESULT(no)
  1087 ])
  1088 
  1089 dnl * If mmap() plays nicely with write()
  1090 AC_CACHE_CHECK([whether shared mmaps get updated by write()s],i_cv_mmap_plays_with_write,[
  1091   AC_TRY_RUN([
  1092     #include <stdio.h>
  1093     #include <sys/types.h>
  1094     #include <sys/stat.h>
  1095     #include <unistd.h>
  1096     #include <fcntl.h>
  1097     #include <sys/mman.h>
  1098     int main() {
  1099       /* return 0 if we're signed */
  1100       int f = open("conftest.mmap", O_RDWR|O_CREAT|O_TRUNC, 0600);
  1101       void *mem;
  1102       if (f == -1) {
  1103 	perror("open()");
  1104 	return 1;
  1105       }
  1106       unlink("conftest.mmap");
  1107   
  1108       write(f, "1", 2);
  1109       mem = mmap(NULL, 2, PROT_READ|PROT_WRITE, MAP_SHARED, f, 0);
  1110       if (mem == MAP_FAILED) {
  1111 	perror("mmap()");
  1112 	return 1;
  1113       }
  1114       strcpy(mem, "2");
  1115       msync(mem, 2, MS_SYNC);
  1116       lseek(f, 0, SEEK_SET);
  1117       write(f, "3", 2);
  1118     
  1119       return strcmp(mem, "3") == 0 ? 0 : 1;
  1120     }
  1121   ], [
  1122     i_cv_mmap_plays_with_write=yes
  1123   ], [
  1124     i_cv_mmap_plays_with_write=no
  1125   ])
  1126 ])
  1127 if test $i_cv_mmap_plays_with_write = no; then
  1128   AC_DEFINE(MMAP_CONFLICTS_WRITE,, [Define if shared mmaps don't get updated by write()s])
  1129 fi
  1130 
  1131 dnl * see if fd passing works
  1132 AC_CACHE_CHECK([whether fd passing works],i_cv_fd_passing,[
  1133   for i in 1 2; do
  1134     old_cflags="$CFLAGS"
  1135     CFLAGS="$CFLAGS -I$srcdir/src/lib $srcdir/src/lib/fdpass.c"
  1136     if test $i = 2; then
  1137       CFLAGS="$CFLAGS -DBUGGY_CMSG_MACROS"
  1138     fi
  1139   
  1140     AC_TRY_RUN([
  1141       #include <sys/types.h>
  1142       #include <sys/socket.h>
  1143       #include <sys/wait.h>
  1144       #include <sys/stat.h>
  1145       #include <unistd.h>
  1146       #include <fcntl.h>
  1147       #include "fdpass.h"
  1148       
  1149       int nopen(void)
  1150       {
  1151 	      int i, n;
  1152 	      struct stat sb;
  1153 	      for (i = n = 0; i < 256; i++)
  1154 		  if (fstat(i, &sb) == 0) n++;
  1155 	      return n;
  1156       }
  1157       int main(void)
  1158       {
  1159 	      int fd[2], send_fd, recv_fd, status, n1, n2;
  1160 	      struct stat st, st2;
  1161 	      char data;
  1162       
  1163 	      send_fd = creat("conftest.fdpass", 0600);
  1164 	      if (send_fd == -1) return 2;
  1165 	      unlink("conftest.fdpass");
  1166 	      if (fstat(send_fd, &st) < 0) return 2;
  1167 	      if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) return 2;
  1168 	      n1 = nopen();
  1169       
  1170 	      switch (fork()) {
  1171 	      case -1:
  1172 		      return 2;
  1173 	      case 0:
  1174 		      alarm(1);
  1175 		      if (fd_send(fd[0], send_fd, &data, 1) != 1) return 2;
  1176 		      return 0;
  1177 	      default:
  1178 		      alarm(2);
  1179 		      if (wait(&status) == -1)
  1180 			return 2;
  1181 		      if (status != 0)
  1182 			return status;
  1183 		      if (fd_read(fd[1], &data, 1, &recv_fd) != 1) return 1;
  1184 		      if (fstat(recv_fd, &st2) < 0) return 2;
  1185 		      /* nopen check is for making sure that only a single fd
  1186 		         was received */
  1187 		      n2 = nopen();
  1188 		      return st.st_ino == st2.st_ino && n2 == n1 + 1 ? 0 : 1;
  1189 	      }
  1190       }
  1191     ], [
  1192       CFLAGS=$old_cflags
  1193       if test $i = 2; then
  1194 	i_cv_fd_passing=buggy_cmsg_macros
  1195       else
  1196         i_cv_fd_passing=yes
  1197       fi
  1198       break
  1199     ], [
  1200       dnl no, try with BUGGY_CMSG_MACROS
  1201       CFLAGS=$old_cflags
  1202       i_cv_fd_passing=no
  1203     ])
  1204   done
  1205 ]);
  1206 
  1207 case "$host_os" in
  1208 darwin[[1-9]].*)
  1209 	if test "$i_cv_fd_passing" = "yes"; then
  1210 		i_cv_fd_passing=buggy_cmsg_macros
  1211 	fi
  1212 	;;
  1213 esac
  1214 
  1215 if test $i_cv_fd_passing = buggy_cmsg_macros; then
  1216   AC_DEFINE(BUGGY_CMSG_MACROS,, Define if you have buggy CMSG macros)
  1217 fi
  1218 
  1219 dnl * Solaris compatible sendfile()
  1220 AC_CHECK_LIB(sendfile, sendfile, [
  1221   LIBS="$LIBS -lsendfile"
  1222   AC_DEFINE(HAVE_SOLARIS_SENDFILE,, Define if you have Solaris-compatible sendfile())
  1223 ], [
  1224   dnl * Linux compatible sendfile() - don't check if Solaris one was found.
  1225   dnl * This seems to pass with Solaris for some reason..
  1226   AC_MSG_CHECKING([Linux compatible sendfile()])
  1227   AC_TRY_LINK([
  1228     #undef _FILE_OFFSET_BITS
  1229     #include <sys/types.h>
  1230     #include <sys/socket.h>
  1231     #include <sys/sendfile.h>
  1232   ], [
  1233     sendfile(0, 0, (void *) 0, 0);
  1234   ], [
  1235     AC_DEFINE(HAVE_LINUX_SENDFILE,, Define if you have Linux-compatible sendfile())
  1236     AC_MSG_RESULT(yes)
  1237   ], [
  1238     AC_MSG_RESULT(no)
  1239   ])
  1240 
  1241   dnl * FreeBSD compatible sendfile()
  1242   AC_MSG_CHECKING([FreeBSD compatible sendfile()])
  1243   AC_TRY_LINK([
  1244     #include <sys/types.h>
  1245     #include <sys/socket.h>
  1246     #include <sys/uio.h>
  1247   ], [
  1248     struct sf_hdtr hdtr;
  1249     sendfile(0, 0, 0, 0, &hdtr, (void *) 0, 0);
  1250   ], [
  1251     AC_DEFINE(HAVE_FREEBSD_SENDFILE,, Define if you have FreeBSD-compatible sendfile())
  1252     AC_MSG_RESULT(yes)
  1253   ], [
  1254     AC_MSG_RESULT(no)
  1255   ])
  1256 ])
  1257 
  1258 dnl * Check for crypt() if unistd.h compiles with _XOPEN_SOURCE + _XPG6
  1259 dnl * Add other macros there too "just in case".
  1260 AC_MSG_CHECKING([if we should use _XPG6 macro for crypt()])
  1261 AC_TRY_COMPILE([
  1262   #define _XOPEN_SOURCE 4
  1263   #define _XOPEN_SOURCE_EXTENDED 1
  1264   #define _XOPEN_VERSION 4
  1265   #define _XPG4_2
  1266   #define _XPG6
  1267   #include <unistd.h>
  1268 ], [
  1269   crypt("a", "b");
  1270 ], [
  1271   AC_DEFINE(CRYPT_USE_XPG6,, Define if _XPG6 macro is needed for crypt())
  1272   AC_MSG_RESULT(yes)
  1273 ], [
  1274   AC_MSG_RESULT(no)
  1275 ])
  1276 
  1277 AC_MSG_CHECKING([if struct stat has st_?tim timespec fields])
  1278 AC_TRY_COMPILE([
  1279   #include <sys/types.h>
  1280   #include <sys/stat.h>
  1281   #include <unistd.h>
  1282 ], [
  1283   struct stat st;
  1284   unsigned long x = st.st_mtim.tv_nsec;
  1285 
  1286   return 0;
  1287 ], [
  1288   AC_DEFINE(HAVE_STAT_XTIM,, Define if you have st_?tim timespec fields in struct stat)
  1289   AC_MSG_RESULT(yes)
  1290 ], [
  1291   AC_MSG_RESULT(no)
  1292 ])
  1293 
  1294 AC_MSG_CHECKING([if struct stat has st_?timespec fields])
  1295 AC_TRY_COMPILE([
  1296   #include <sys/types.h>
  1297   #include <sys/stat.h>
  1298   #include <unistd.h>
  1299 ], [
  1300   struct stat st;
  1301   unsigned long x = st.st_mtimespec.tv_nsec;
  1302 
  1303   return 0;
  1304 ], [
  1305   AC_DEFINE(HAVE_STAT_XTIMESPEC,, Define if you have st_?timespec fields in struct stat)
  1306   AC_MSG_RESULT(yes)
  1307 ], [
  1308   AC_MSG_RESULT(no)
  1309 ])
  1310 
  1311 dnl * Check if statvfs() can be used to find out block device for files
  1312 AC_MSG_CHECKING([if statvfs.f_mntfromname exists])
  1313 AC_TRY_COMPILE([
  1314   #include <sys/types.h>
  1315   #include <sys/statvfs.h>
  1316 ], [
  1317   struct statvfs buf;
  1318   char *p = buf.f_mntfromname;
  1319 
  1320   statvfs(".", &buf);
  1321 ], [
  1322   AC_DEFINE(HAVE_STATVFS_MNTFROMNAME,, Define if you have statvfs.f_mntfromname)
  1323   AC_MSG_RESULT(yes)
  1324 ], [
  1325   AC_MSG_RESULT(no)
  1326 ])
  1327 
  1328 dnl * Check if statvfs() can be used to find out block device for files
  1329 AC_MSG_CHECKING([if statvfs.f_mntfromname exists])
  1330 AC_TRY_COMPILE([
  1331   #include <sys/types.h>
  1332   #include <sys/statvfs.h>
  1333 ], [
  1334   struct statvfs buf;
  1335   char *p = buf.f_mntfromname;
  1336 
  1337   statvfs(".", &buf);
  1338 ], [
  1339   AC_DEFINE(HAVE_STATVFS_MNTFROMNAME,, Define if you have statvfs.f_mntfromname)
  1340   AC_MSG_RESULT(yes)
  1341 ], [
  1342   AC_MSG_RESULT(no)
  1343 ])
  1344 
  1345 dnl * Check if statfs() can be used to find out block device for files
  1346 AC_MSG_CHECKING([if statfs.f_mntfromname exists])
  1347 AC_TRY_COMPILE([
  1348   #include <sys/param.h>
  1349   #include <sys/mount.h>
  1350 ], [
  1351   struct statfs buf;
  1352   char *p = buf.f_mntfromname;
  1353 
  1354   statfs(".", &buf);
  1355 ], [
  1356   AC_DEFINE(HAVE_STATFS_MNTFROMNAME,, Define if you have statfs.f_mntfromname)
  1357   AC_MSG_RESULT(yes)
  1358 ], [
  1359   AC_MSG_RESULT(no)
  1360 ])
  1361 
  1362 dnl * Check if we have struct dqblk.dqb_curblocks
  1363 AC_MSG_CHECKING([if struct dqblk.dqb_curblocks exists])
  1364 AC_TRY_COMPILE([
  1365   #include <sys/types.h>
  1366   #include "$srcdir/src/plugins/quota/quota-fs.h"
  1367 ], [
  1368   struct dqblk dqblk;
  1369   unsigned int x = dqblk.dqb_curblocks;
  1370 ], [
  1371   AC_DEFINE(HAVE_STRUCT_DQBLK_CURBLOCKS,, Define if struct sqblk.dqb_curblocks exists)
  1372   AC_MSG_RESULT(yes)
  1373 ], [
  1374   AC_MSG_RESULT(no)
  1375 ])
  1376 
  1377 dnl * Check if we have struct dqblk.dqb_curspace
  1378 AC_MSG_CHECKING([if struct dqblk.dqb_curspace exists])
  1379 AC_TRY_COMPILE([
  1380   #include <sys/types.h>
  1381   #include "$srcdir/src/plugins/quota/quota-fs.h"
  1382 ], [
  1383   struct dqblk dqblk;
  1384   unsigned int x = dqblk.dqb_curspace;
  1385 ], [
  1386   AC_DEFINE(HAVE_STRUCT_DQBLK_CURSPACE,, Define if struct sqblk.dqb_curspace exists)
  1387   AC_MSG_RESULT(yes)
  1388 ], [
  1389   AC_MSG_RESULT(no)
  1390 ])
  1391 
  1392 dnl * Check if we have Q_QUOTACTL ioctl (Solaris)
  1393 AC_MSG_CHECKING([if struct Q_QUOTACTL ioctl exists])
  1394 AC_TRY_COMPILE([
  1395   #include <sys/types.h>
  1396   #include <sys/fs/ufs_quota.h>
  1397 ], [
  1398   struct quotctl ctl;
  1399   ioctl(0, Q_QUOTACTL, &ctl);
  1400 ], [
  1401   AC_DEFINE(HAVE_Q_QUOTACTL,, Define if Q_QUOTACTL exists)
  1402   AC_MSG_RESULT(yes)
  1403 ], [
  1404   AC_MSG_RESULT(no)
  1405 ])
  1406 
  1407 dnl ***
  1408 dnl *** C99 vsnprintf()?
  1409 dnl ***
  1410 
  1411 AC_CACHE_CHECK([for C99 vsnprintf()],i_cv_c99_vsnprintf,[
  1412   AC_RUN_IFELSE([AC_LANG_SOURCE([[
  1413   #include <stdio.h>
  1414   #include <stdarg.h>
  1415   static int f(const char *fmt, ...) {
  1416     va_list args;
  1417     char buf[13];
  1418     int ret;
  1419 
  1420     va_start(args, fmt);
  1421     ret = vsnprintf(buf, 11, fmt, args) != 12 || buf[11-1] != '\0';
  1422     va_end(args);
  1423     return ret;
  1424   }
  1425   int main() {
  1426     return f("hello %s%d", "world", 1);
  1427   }]])],
  1428   [i_cv_c99_vsnprintf=yes],
  1429   [i_cv_c99_vsnprintf=no])
  1430 ])
  1431 if test $i_cv_c99_vsnprintf = no; then
  1432   AC_DEFINE(HAVE_OLD_VSNPRINTF,, Define if you don't have C99 compatible vsnprintf() call)
  1433 fi
  1434 
  1435 dnl ***
  1436 dnl *** va_copy checks (from GLIB)
  1437 dnl ***
  1438 
  1439 AC_CACHE_CHECK([for an implementation of va_copy()],lib_cv_va_copy,[
  1440 	AC_RUN_IFELSE([AC_LANG_SOURCE([[
  1441 	#include <stdarg.h>
  1442 	void f (int i, ...) {
  1443 	va_list args1, args2;
  1444 	va_start (args1, i);
  1445 	va_copy (args2, args1);
  1446 	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
  1447 	  exit (1);
  1448 	va_end (args1); va_end (args2);
  1449 	}
  1450 	int main() {
  1451 	  f (0, 42);
  1452 	  return 0;
  1453 	}]])],
  1454 	[lib_cv_va_copy=yes],
  1455 	[lib_cv_va_copy=no],[])
  1456 ])
  1457 AC_CACHE_CHECK([for an implementation of __va_copy()],lib_cv___va_copy,[
  1458 	AC_RUN_IFELSE([AC_LANG_SOURCE([[
  1459 	#include <stdarg.h>
  1460 	void f (int i, ...) {
  1461 	va_list args1, args2;
  1462 	va_start (args1, i);
  1463 	__va_copy (args2, args1);
  1464 	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
  1465 	  exit (1);
  1466 	va_end (args1); va_end (args2);
  1467 	}
  1468 	int main() {
  1469 	  f (0, 42);
  1470 	  return 0;
  1471 	}]])],
  1472 	[lib_cv___va_copy=yes],
  1473 	[lib_cv___va_copy=no],[])
  1474 ])
  1475 
  1476 if test "x$lib_cv_va_copy" = "xyes"; then
  1477   va_copy_func=va_copy
  1478 else if test "x$lib_cv___va_copy" = "xyes"; then
  1479   va_copy_func=__va_copy
  1480 fi
  1481 fi
  1482 
  1483 if test -n "$va_copy_func"; then
  1484   AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,[A 'va_copy' style function])
  1485 fi
  1486 
  1487 AC_CACHE_CHECK([whether va_lists can be copied by value],lib_cv_va_val_copy,[
  1488 	AC_RUN_IFELSE([AC_LANG_SOURCE([[
  1489 	#include <stdarg.h>
  1490 	void f (int i, ...) {
  1491 	va_list args1, args2;
  1492 	va_start (args1, i);
  1493 	args2 = args1;
  1494 	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
  1495 	  exit (1);
  1496 	va_end (args1); va_end (args2);
  1497 	}
  1498 	int main() {
  1499 	  f (0, 42);
  1500 	  return 0;
  1501 	}]])],
  1502 	[lib_cv_va_val_copy=yes],
  1503 	[lib_cv_va_val_copy=no],[])
  1504 ])
  1505 
  1506 if test "x$lib_cv_va_val_copy" = "xno"; then
  1507   AC_DEFINE(VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copies as values])
  1508 fi
  1509 
  1510 dnl * dynamic modules?
  1511 have_modules=no
  1512 AC_CHECK_FUNC(dlopen, [
  1513   have_modules=yes
  1514   MODULE_LIBS="-export-dynamic"
  1515 ], [
  1516   AC_CHECK_LIB(dl, dlopen, [
  1517     have_modules=yes
  1518     MODULE_LIBS="-export-dynamic -ldl"
  1519     DLLIB=-ldl
  1520   ])
  1521 ])
  1522 
  1523 dnl **
  1524 dnl ** AIX mntctl
  1525 dnl **
  1526 
  1527 if test $ac_cv_header_sys_vmount_h = yes; then
  1528   AC_MSG_CHECKING([for reasonable mntctl buffer size])
  1529   AC_RUN_IFELSE([AC_LANG_SOURCE([[
  1530     #include <stdio.h>
  1531     #include <stdlib.h>
  1532     #include <sys/vmount.h>
  1533     int main() {
  1534       int size,count; char *m;
  1535       FILE *f=fopen("conftestval", "w");
  1536       if (!f) exit(1);
  1537       if ((count=mntctl(MCTL_QUERY,sizeof(size),&size))!=0 || !(m=malloc(size)) ||
  1538           (count=mntctl(MCTL_QUERY,size,m))<=0) exit(1);
  1539         fprintf(f, "%d\n",(size * (count + 5))/count & ~1); /* 5 mounts more */
  1540         exit(0);
  1541     }
  1542   ]])],[
  1543     size=`cat conftestval`
  1544     rm -f conftestval
  1545     AC_DEFINE_UNQUOTED(STATIC_MTAB_SIZE,$size, reasonable mntctl buffer size)
  1546     AC_MSG_RESULT($size)
  1547   ],[
  1548     AC_MSG_RESULT(default)
  1549   ])
  1550 fi
  1551 
  1552 
  1553 dnl **
  1554 dnl ** SSL
  1555 dnl **
  1556 
  1557 have_ssl=no
  1558 
  1559 if test $want_openssl != no && test $have_ssl = no; then
  1560   if pkg-config --exists openssl 2>/dev/null; then
  1561     PKG_CHECK_MODULES(SSL, openssl)
  1562     CFLAGS="$CFLAGS $SSL_CFLAGS"
  1563     have_openssl=yes
  1564   else
  1565     # openssl 0.9.8 wants -ldl and it's required if there's only .a lib
  1566     AC_CHECK_LIB(ssl, SSL_read, [
  1567       AC_CHECK_HEADERS(openssl/ssl.h openssl/err.h, [
  1568         SSL_LIBS="-lssl -lcrypto $DLLIB"
  1569         AC_SUBST(SSL_LIBS)
  1570 	have_openssl=yes
  1571       ], [
  1572 	if test $want_openssl = yes; then
  1573 	  AC_ERROR([Can't build with OpenSSL: openssl/ssl.h or openssl/err.h not found])
  1574 	fi
  1575       ])
  1576     ], [
  1577       if test $want_openssl = yes; then
  1578         AC_ERROR([Can't build with OpenSSL: libssl not found])
  1579       fi
  1580     ], -lcrypto $DLLIB)
  1581   fi
  1582   if test "$have_openssl" = "yes"; then
  1583     AC_DEFINE(HAVE_OPENSSL,, Build with OpenSSL support)
  1584     have_ssl="yes (OpenSSL)"
  1585 
  1586     AC_CHECK_LIB(ssl, SSL_get_current_compression, [
  1587       AC_DEFINE(HAVE_SSL_COMPRESSION,, Build with OpenSSL compression)
  1588     ],, $SSL_LIBS)
  1589   fi
  1590 fi
  1591 
  1592 if test $want_gnutls != no && test $have_ssl = no; then
  1593   AC_CHECK_LIB(gnutls, gnutls_global_init, [
  1594     AC_CHECK_HEADER(gnutls/gnutls.h, [
  1595       AC_DEFINE(HAVE_GNUTLS,, Build with GNUTLS support)
  1596       SSL_LIBS="-lgnutls -lgcrypt"
  1597       AC_SUBST(SSL_LIBS)
  1598       have_ssl="yes (GNUTLS)"
  1599       have_gnutls=yes
  1600     ], [
  1601       if test $want_gnutls = yes; then
  1602 	AC_ERROR([Can't build with GNUTLS: gnutls/gnutls.h not found])
  1603       fi
  1604     ])
  1605   ], [
  1606     if test $want_gnutls = yes; then
  1607       AC_ERROR([Can't build with GNUTLS: libgnutls not found])
  1608     fi
  1609   ], -lgcrypt)
  1610 fi
  1611 
  1612 if test "$have_ssl" != "no"; then
  1613 	AC_DEFINE(HAVE_SSL,, Build with SSL/TLS support)
  1614 fi
  1615 
  1616 dnl **
  1617 dnl ** Garbage Collector
  1618 dnl ** 
  1619 
  1620 if test $want_gc != no; then
  1621   AC_CHECK_LIB(gc, GC_malloc, [
  1622     AC_CHECK_HEADERS(gc/gc.h gc.h)
  1623     AC_DEFINE(USE_GC,, Define if you want to use Boehm GC)
  1624     LIBS="$LIBS -lgc"
  1625   ], [
  1626     if test $want_gc = yes; then
  1627       AC_ERROR([Can't build with GC: libgc not found])
  1628     fi
  1629   ])
  1630 fi
  1631 
  1632 dnl **
  1633 dnl ** userdb and passdb checks
  1634 dnl **
  1635 
  1636 userdb=""
  1637 passdb=""
  1638 not_userdb=""
  1639 not_passdb=""
  1640 
  1641 if test $want_static_userdb != no; then
  1642         AC_DEFINE(USERDB_STATIC,, Build with static userdb support)
  1643 	userdb="$userdb static"
  1644 else
  1645 	not_userdb="$not_userdb static"
  1646 fi
  1647 
  1648 if test $want_prefetch_userdb != no; then
  1649         AC_DEFINE(USERDB_PREFETCH,, Build with prefetch userdb support)
  1650 	userdb="$userdb prefetch"
  1651 else
  1652 	not_userdb="$not_userdb prefetch"
  1653 fi
  1654 
  1655 if test $want_passwd != no; then
  1656         AC_DEFINE(USERDB_PASSWD,, Build with passwd support)
  1657         AC_DEFINE(PASSDB_PASSWD,, Build with passwd support)
  1658 	userdb="$userdb passwd"
  1659 	passdb="$passdb passwd"
  1660 else
  1661 	not_passdb="$not_passdb passwd"
  1662 	not_userdb="$not_userdb passwd"
  1663 fi
  1664 
  1665 if test $want_passwd_file != no; then
  1666         AC_DEFINE(USERDB_PASSWD_FILE,, Build with passwd-file support)
  1667         AC_DEFINE(PASSDB_PASSWD_FILE,, Build with passwd-file support)
  1668 	userdb="$userdb passwd-file"
  1669 	passdb="$passdb passwd-file"
  1670 else
  1671 	not_passdb="$not_passdb passwd-file"
  1672 	not_userdb="$not_userdb passwd-file"
  1673 fi
  1674 
  1675 have_shadow=no
  1676 if test $want_shadow != no; then
  1677   AC_CHECK_FUNC(getspnam, [
  1678     AC_CHECK_HEADER(shadow.h, [
  1679       AC_DEFINE(PASSDB_SHADOW,, Build with shadow support)
  1680       have_shadow=yes
  1681     ], [
  1682       if test $want_shadow = yes; then
  1683         AC_ERROR([Can't build with shadow support: shadow.h not found])
  1684       fi
  1685     ])
  1686   ], [
  1687     if test $want_shadow = yes; then
  1688       AC_ERROR([Can't build with shadow support: getspnam() not found])
  1689     fi
  1690   ])
  1691 fi
  1692 if test $have_shadow = no; then
  1693   not_passdb="$not_passdb shadow"
  1694 else
  1695   passdb="$passdb shadow"
  1696 fi
  1697 
  1698 if test $want_pam != no; then
  1699 	AC_CHECK_LIB(pam, pam_start, [
  1700 		have_pam=no
  1701 		AC_CHECK_HEADER(security/pam_appl.h, [
  1702 			AC_DEFINE(HAVE_SECURITY_PAM_APPL_H,,
  1703 				  Define if you have security/pam_appl.h)
  1704 			have_pam=yes
  1705 		])
  1706 
  1707 		AC_CHECK_HEADER(pam/pam_appl.h, [
  1708 			AC_DEFINE(HAVE_PAM_PAM_APPL_H,,
  1709 				  Define if you have pam/pam_appl.h)
  1710 			have_pam=yes
  1711 		])
  1712 	], [
  1713 	  if test $want_pam = yes; then
  1714 	    AC_ERROR([Can't build with PAM support: libpam not found])
  1715 	  fi
  1716 	])
  1717 fi
  1718 
  1719 if test "$have_pam" = "yes"; then
  1720   AUTH_LIBS="$AUTH_LIBS -lpam"
  1721   AC_DEFINE(PASSDB_PAM,, Build with PAM support)
  1722   passdb="$passdb pam"
  1723 
  1724   AC_CHECK_LIB(pam, pam_setcred, [
  1725     AC_DEFINE(HAVE_PAM_SETCRED,, Define if you have pam_setcred())
  1726   ])
  1727 elif test $want_pam = yes; then
  1728   AC_ERROR([Can't build with PAM support: pam_appl.h not found])
  1729 else
  1730   not_passdb="$not_passdb pam"
  1731 fi
  1732 
  1733 if test $want_checkpassword != no; then
  1734         AC_DEFINE(PASSDB_CHECKPASSWORD,, Build with checkpassword passdb support)
  1735         AC_DEFINE(USERDB_CHECKPASSWORD,, Build with checkpassword userdb support)
  1736 	passdb="$passdb checkpassword"
  1737 	userdb="$userdb checkpassword"
  1738 else
  1739 	not_passdb="$not_passdb checkpassword"
  1740 	not_userdb="$not_userdb checkpassword"
  1741 fi
  1742 
  1743 have_bsdauth=no
  1744 if test $want_bsdauth != no; then
  1745 	AC_CHECK_FUNC(auth_userokay, [
  1746 		AC_DEFINE(PASSDB_BSDAUTH,, Build with BSD authentication support)
  1747 		have_bsdauth=yes
  1748 	], [
  1749 	  if test $want_bsdauth = yes; then
  1750 	    AC_ERROR([Can't build with BSD authentication support: auth_userokay() not found])
  1751 	  fi
  1752 	])
  1753 fi
  1754 if test $have_bsdauth = no; then
  1755   not_passdb="$not_passdb bsdauth"
  1756 else
  1757   passdb="$passdb bsdauth"
  1758 fi
  1759 
  1760 have_gssapi=no
  1761 if test $want_gssapi != no; then
  1762 	AC_CHECK_PROG(KRB5CONFIG, krb5-config, YES, NO)
  1763 	if test $KRB5CONFIG = YES; then
  1764 		if ! krb5-config --version gssapi 2>/dev/null > /dev/null; then
  1765 		  # krb5-config doesn't support gssapi.
  1766 		  KRB5_LIBS="`krb5-config --libs`"
  1767 		  KRB5_CFLAGS=`krb5-config --cflags`
  1768 		  AC_CHECK_LIB(gss, gss_acquire_cred, [
  1769 		    # Solaris
  1770 		    KRB5_LIBS="$KRB5_LIBS -lgss"
  1771 		  ], [
  1772 		    # failed
  1773 		    KRB5_LIBS=
  1774 		  ], $KRB5_LIBS)
  1775 		else
  1776 		  KRB5_LIBS=`krb5-config --libs gssapi`
  1777 		  KRB5_CFLAGS=`krb5-config --cflags gssapi`
  1778 		fi
  1779 		if test "$KRB5_LIBS" != ""; then
  1780 			AC_SUBST(KRB5_LIBS)
  1781 			AC_SUBST(KRB5_CFLAGS)
  1782 			
  1783 			# Although krb5-config exists, all systems still don't
  1784 			# have gssapi.h
  1785 			old_CFLAGS=$CFLAGS
  1786 			CFLAGS="$CFLAGS $KRB5_CFLAGS"
  1787 			AC_CHECK_HEADER([gssapi/gssapi.h], [
  1788 				AC_DEFINE(HAVE_GSSAPI_GSSAPI_H,, GSSAPI headers in gssapi/gssapi.h)
  1789 				have_gssapi=yes
  1790 			])
  1791 			AC_CHECK_HEADER([gssapi.h], [
  1792 				AC_DEFINE(HAVE_GSSAPI_H,, GSSAPI headers in gssapi.h)
  1793 				have_gssapi=yes
  1794 			])
  1795 			if test $have_gssapi != no; then
  1796 				if test $want_gssapi = plugin; then
  1797 					have_gssapi=plugin
  1798 				fi
  1799 				AC_DEFINE(HAVE_GSSAPI,, Build with GSSAPI support)
  1800 				AC_CHECK_HEADERS(gssapi/gssapi_ext.h gssapi_krb5.h gssapi/gssapi_krb5.h)
  1801 				AC_CHECK_LIB(gss, __gss_userok, [
  1802 					AC_DEFINE(HAVE___GSS_USEROK,,
  1803 						Define if you have __gss_userok())
  1804 					KRB5_LIBS="$KRB5_LIBS -lgss"
  1805 				],, $KRB5_LIBS)
  1806 
  1807 				# MIT has a #define for Heimdal acceptor_identity, but it's way too
  1808 				# difficult to test for it..
  1809 				old_LIBS=$LIBS
  1810 				LIBS="$LIBS $KRB5_LIBS"
  1811 				AC_CHECK_FUNCS(gsskrb5_register_acceptor_identity krb5_gss_register_acceptor_identity)
  1812 
  1813 				# does the kerberos library support SPNEGO?
  1814 				AC_CACHE_CHECK([whether GSSAPI supports SPNEGO],i_cv_gssapi_spnego,[
  1815 				  AC_TRY_RUN([
  1816 				    #ifdef HAVE_GSSAPI_H
  1817 				    #  include <gssapi.h>
  1818 				    #else
  1819 				    #  include <gssapi/gssapi.h>
  1820 				    #endif
  1821 				    #include <krb5.h>
  1822 				    #include <string.h>
  1823 				    int main(void) {
  1824 				      OM_uint32 minor_status;
  1825 				      gss_OID_set mech_set;
  1826 				      unsigned char spnego_oid[] = { 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02 };
  1827 				      unsigned int i;
  1828     
  1829 				      gss_indicate_mechs(&minor_status, &mech_set);
  1830 				      for (i = 0; i < mech_set->count; i++) {
  1831 					if (mech_set->elements[i].length == 6 &&
  1832 					    memcmp(mech_set->elements[i].elements,
  1833 						   spnego_oid, 6) == 0)
  1834 					      return 0;
  1835 				      }
  1836 				      return 1;
  1837 				    }
  1838 				  ], [
  1839 				    i_cv_gssapi_spnego=yes
  1840 				  ], [
  1841 				    i_cv_gssapi_spnego=no
  1842 				  ])
  1843 				])
  1844 				if test "$i_cv_gssapi_spnego" = "yes"; then
  1845 				  AC_DEFINE(HAVE_GSSAPI_SPNEGO,, GSSAPI supports SPNEGO)
  1846 				fi
  1847 				LIBS=$old_LIBS
  1848 
  1849 				if test $want_gssapi != plugin; then
  1850 				  AUTH_LIBS="$AUTH_LIBS $KRB5_LIBS"
  1851 				  AUTH_CFLAGS="$AUTH_CFLAGS $KRB5_CFLAGS"
  1852 				  AC_DEFINE(BUILTIN_GSSAPI,, GSSAPI support is built in)
  1853 				else
  1854 				  have_gssapi_plugin=yes
  1855 				fi
  1856 			else
  1857 			  if test $want_gssapi != auto; then
  1858 			    AC_ERROR([Can't build with GSSAPI support: gssapi.h not found])
  1859 			  fi
  1860 			fi
  1861 			CFLAGS=$old_CFLAGS
  1862 		fi
  1863 	else
  1864 	  if test $want_gssapi != auto; then
  1865 	    AC_ERROR([Can't build with GSSAPI support: krb5-config not found])
  1866 	  fi
  1867 	fi
  1868 fi
  1869 AM_CONDITIONAL(GSSAPI_PLUGIN, test "$have_gssapi_plugin" = "yes")
  1870 
  1871 have_sia=no
  1872 if test $want_sia != no; then
  1873 	AC_CHECK_FUNC(sia_validate_user, [
  1874 		AC_DEFINE(PASSDB_SIA,, Build with Tru64 SIA support)
  1875 		AUTH_LIBS="$AUTH_LIBS -depth_ring_search"
  1876 		have_sia=yes
  1877 	], [
  1878 	  if test $want_sia = yes; then
  1879 	    AC_ERROR([Can't build with SIA support: sia_validate_user() not found])
  1880 	  fi
  1881 	])
  1882 fi
  1883 
  1884 if test $have_sia = no; then
  1885   not_passdb="$not_passdb sia"
  1886 else
  1887   passdb="$passdb sia"
  1888 fi
  1889 
  1890 have_ldap=no
  1891 if test $want_ldap != no; then
  1892 	AC_CHECK_LIB(ldap, ldap_init, [
  1893 		AC_CHECK_HEADER(ldap.h, [
  1894 			AC_CHECK_LIB(ldap, ldap_initialize, [
  1895 				AC_DEFINE(LDAP_HAVE_INITIALIZE,, Define if you have ldap_initialize)
  1896 			])
  1897 			AC_CHECK_LIB(ldap, ldap_start_tls_s, [
  1898 				AC_DEFINE(LDAP_HAVE_START_TLS_S,, Define if you have ldap_start_tls_s)
  1899 			])
  1900 			LDAP_LIBS=-lldap
  1901 			AC_SUBST(LDAP_LIBS)
  1902 			if test $want_ldap != plugin; then
  1903 				AUTH_LIBS="$AUTH_LIBS $LDAP_LIBS"
  1904 		        	AC_DEFINE(BUILTIN_LDAP,, LDAP support is built in)
  1905 			fi
  1906 
  1907         		AC_DEFINE(USERDB_LDAP,, Build with LDAP support)
  1908 		        AC_DEFINE(PASSDB_LDAP,, Build with LDAP support)
  1909 			AC_CHECK_HEADERS(sasl.h sasl/sasl.h)
  1910 			have_ldap=yes
  1911 		], [
  1912 		  if test $want_ldap != auto; then
  1913 		    AC_ERROR([Can't build with LDAP support: ldap.h not found])
  1914 		  fi
  1915 		])
  1916 	], [
  1917 	  if test $want_ldap != auto; then
  1918 	    AC_ERROR([Can't build with LDAP support: libldap not found])
  1919 	  fi
  1920 	])
  1921 fi
  1922 
  1923 if test $have_ldap = no; then
  1924   not_passdb="$not_passdb ldap"
  1925   not_userdb="$not_userdb ldap"
  1926 else
  1927   userdb="$userdb ldap"
  1928   passdb="$passdb ldap"
  1929   if test $want_ldap = plugin; then
  1930     have_ldap_plugin=yes
  1931     userdb="$userdb (plugin)"
  1932     passdb="$passdb (plugin)"
  1933   fi
  1934 fi
  1935 AM_CONDITIONAL(LDAP_PLUGIN, test "$have_ldap_plugin" = "yes")
  1936 
  1937 dict_drivers=client
  1938 
  1939 if test $want_db != no; then
  1940 	AC_MSG_CHECKING([db_env_create in -ldb])
  1941 	old_LIBS=$LIBS
  1942 	LIBS="$LIBS -ldb"
  1943 	AC_TRY_LINK([
  1944 		#include <db.h>
  1945 	], [
  1946 		db_env_create(0, 0);
  1947 	], [
  1948 		AC_MSG_RESULT(yes)
  1949 		AC_CHECK_HEADER(db.h, [
  1950         		DICT_LIBS="$DICT_LIBS -ldb"
  1951 			dict_drivers="$dict_drivers db"
  1952 			AC_DEFINE(BUILD_DB,, Build with Berkeley DB support)
  1953 		], [
  1954 		  if test $want_db = yes; then
  1955 		    AC_ERROR([Can't build with db support: db.h not found])
  1956 		  fi
  1957 		])
  1958 	], [
  1959 		AC_MSG_RESULT(no)
  1960 		if test $want_db = yes; then
  1961 		  AC_ERROR([Can't build with db support: libdb not found])
  1962 		fi
  1963 	])
  1964 	LIBS=$old_LIBS
  1965 fi
  1966 
  1967 if test $want_pgsql != no; then
  1968   AC_CHECK_PROG(PG_CONFIG, pg_config, YES, NO)
  1969   if test $PG_CONFIG = NO; then
  1970     # based on code from PHP
  1971     for i in /usr /usr/local /usr/local/pgsql; do
  1972       for j in include include/pgsql include/postgres include/postgresql ""; do
  1973 	if test -r "$i/$j/libpq-fe.h"; then
  1974 	  PGSQL_INCLUDE=$i/$j
  1975 	fi
  1976       done
  1977       for lib in lib lib64; do
  1978 	for j in $lib $lib/pgsql $lib/postgres $lib/postgresql ""; do
  1979 	  if test -f "$i/$j/libpq.so" || test -f "$i/$j/libpq.a"; then
  1980 	    PGSQL_LIBDIR=$i/$j
  1981 	  fi
  1982 	done
  1983       done
  1984     done
  1985   else
  1986     PGSQL_INCLUDE="`pg_config --includedir`"
  1987     PGSQL_LIBDIR="`pg_config --libdir`"  
  1988   fi
  1989 
  1990   old_LIBS=$LIBS
  1991   if test "$PGSQL_LIBDIR" != ""; then
  1992     LIBS="$LIBS -L$PGSQL_LIBDIR"
  1993   fi
  1994 
  1995   AC_CHECK_LIB(pq, PQconnectdb, [
  1996 	  AC_CHECK_LIB(pq, PQescapeStringConn, [
  1997 		  AC_DEFINE(HAVE_PQESCAPE_STRING_CONN,, Define if libpq has PQescapeStringConn function)
  1998 	  ])
  1999 	  old_CPPFLAGS=$CPPFLAGS
  2000 	  if test "$PGSQL_INCLUDE" != ""; then
  2001 		  CPPFLAGS="$CPPFLAGS -I $PGSQL_INCLUDE"
  2002 	  fi
  2003 	  AC_CHECK_HEADER(libpq-fe.h, [
  2004 		  if test "$PGSQL_INCLUDE" != ""; then
  2005 			  PGSQL_CFLAGS="$PGSQL_CFLAGS -I$PGSQL_INCLUDE"
  2006 		  fi
  2007 		  if test "$PGSQL_LIBDIR" != ""; then
  2008 			  PGSQL_LIBS="$PGSQL_LIBS -L$PGSQL_LIBDIR"
  2009 		  fi
  2010 		  PGSQL_LIBS="$PGSQL_LIBS -lpq"
  2011 		  AC_DEFINE(HAVE_PGSQL,, Build with PostgreSQL support)
  2012 		  found_sql_drivers="$found_sql_drivers pgsql"
  2013 
  2014 		  if test "$all_sql_drivers" = "yes"; then
  2015 		    sql_drivers="$sql_drivers pgsql"
  2016 		  fi
  2017 	  ], [
  2018 	    if test $want_pgsql = yes; then
  2019 	      AC_ERROR([Can't build with PostgreSQL support: libpq-fe.h not found])
  2020 	    fi
  2021 	  ])
  2022 	  CPPFLAGS=$old_CPPFLAGS
  2023   ], [
  2024     if test $want_pgsql = yes; then
  2025       AC_ERROR([Can't build with PostgreSQL support: libpq not found])
  2026     fi
  2027   ])
  2028   LIBS=$old_LIBS
  2029 fi
  2030 
  2031 if test $want_mysql != no; then
  2032 	# based on code from PHP
  2033 	for i in /usr /usr/local /usr/local/mysql; do
  2034 		for j in include include/mysql ""; do
  2035 			if test -r "$i/$j/mysql.h"; then
  2036 				MYSQL_INCLUDE=$i/$j
  2037 			fi
  2038 		done
  2039 		for j in lib lib/mysql lib64 lib64/mysql ""; do
  2040 			if test -f "$i/$j/libmysqlclient.so" || test -f "$i/$j/libmysqlclient.a"; then
  2041 				MYSQL_LIBDIR=$i/$j
  2042 			fi
  2043 		done
  2044 	done
  2045 
  2046 	old_LIBS=$LIBS
  2047 	if test "$MYSQL_LIBDIR" != ""; then
  2048 		LIBS="$LIBS -L$MYSQL_LIBDIR"
  2049 	fi
  2050 
  2051 	mysql_lib=""
  2052 	LIBS="$LIBS -lz -lm"
  2053 	AC_CHECK_LIB(mysqlclient, mysql_init, [
  2054 		old_CPPFLAGS=$CPPFLAGS
  2055 		if test "$MYSQL_INCLUDE" != ""; then
  2056 			CPPFLAGS="$CPPFLAGS -I $MYSQL_INCLUDE"
  2057 		fi
  2058 		AC_CHECK_HEADER(mysql.h, [
  2059 			if test "$MYSQL_INCLUDE" != ""; then
  2060 				MYSQL_CFLAGS="$MYSQL_CFLAGS -I$MYSQL_INCLUDE"
  2061 			fi
  2062 			if test "$MYSQL_LIBDIR" != ""; then
  2063 				MYSQL_LIBS="$MYSQL_LIBS -L$MYSQL_LIBDIR"
  2064 			fi
  2065 			MYSQL_LIBS="$MYSQL_LIBS -lmysqlclient -lz -lm"
  2066 
  2067 			AC_CHECK_LIB(mysqlclient, mysql_ssl_set, [
  2068 				AC_DEFINE(HAVE_MYSQL_SSL,, Define if your MySQL library has SSL functions)
  2069 				if test "x$have_openssl" = "yes"; then
  2070 				  ssl_define="#define HAVE_OPENSSL"
  2071 				else
  2072 				  ssl_define=""
  2073 				fi
  2074 				AC_TRY_COMPILE([
  2075 				  $ssl_define
  2076 				  #include <mysql.h>
  2077 				], [
  2078 				  mysql_set_ssl(0, 0, 0, 0, 0, 0);
  2079 				], [
  2080 					AC_DEFINE(HAVE_MYSQL_SSL_CIPHER,, Define if your MySQL library supports setting cipher)
  2081 				])
  2082 			])
  2083 			
  2084 			AC_DEFINE(HAVE_MYSQL,, Build with MySQL support)
  2085 			found_sql_drivers="$found_sql_drivers mysql"
  2086 		], [
  2087 		  if test $want_mysql = yes; then
  2088 		    AC_ERROR([Can't build with MySQL support: mysql.h not found])
  2089 		  fi
  2090 		])
  2091 		CPPFLAGS=$old_CPPFLAGS
  2092 	], [
  2093 	  if test $want_mysql = yes; then
  2094 	    AC_ERROR([Can't build with MySQL support: libmysqlclient not found])
  2095 	  fi
  2096 	])
  2097 
  2098 	LIBS=$old_LIBS
  2099 fi
  2100 
  2101 if test $want_sqlite != no; then
  2102 	AC_CHECK_LIB(sqlite3, sqlite3_open, [
  2103 		AC_CHECK_HEADER(sqlite3.h, [
  2104 			SQLITE_LIBS="$SQLITE_LIBS -lsqlite3 -lz"
  2105 
  2106 			AC_DEFINE(HAVE_SQLITE,, Build with SQLite3 support)
  2107 			found_sql_drivers="$found_sql_drivers sqlite"
  2108 		], [
  2109 		  if test $want_sqlite = yes; then
  2110 		    AC_ERROR([Can't build with SQLite support: sqlite3.h not found])
  2111 		  fi
  2112 		])
  2113 	], [
  2114 	  if test $want_sqlite = yes; then
  2115 	    AC_ERROR([Can't build with SQLite support: libsqlite3 not found])
  2116 	  fi
  2117 	])
  2118 fi
  2119 	
  2120 SQL_CFLAGS="$MYSQL_CFLAGS $PGSQL_CFLAGS $SQLITE_CFLAGS"
  2121 if test "$want_sql" != "plugin"; then
  2122 	SQL_LIBS="$MYSQL_LIBS $PGSQL_LIBS $SQLITE_LIBS"
  2123 else
  2124 	AC_DEFINE(SQL_DRIVER_PLUGINS,, Build SQL drivers as plugins)
  2125 fi
  2126 
  2127 if test "$found_sql_drivers" != "" || test "$want_sql" != "no"; then
  2128 	if test "$all_sql_drivers" = "yes"; then
  2129 	  sql_drivers="$found_sql_drivers"
  2130 	fi
  2131 
  2132 	AC_DEFINE(PASSDB_SQL,, Build with SQL support)
  2133 	AC_DEFINE(USERDB_SQL,, Build with SQL support)
  2134 	AUTH_LIBS="$AUTH_LIBS $SQL_LIBS"
  2135 	passdb="$passdb sql"
  2136 	userdb="$userdb sql"
  2137 else
  2138 	not_passdb="$not_passdb sql"
  2139 	not_userdb="$not_userdb sql"
  2140 fi
  2141 
  2142 have_vpopmail=no
  2143 if test $want_vpopmail != no; then
  2144 	vpop_etc="$vpopmail_home/etc"
  2145 	AC_MSG_CHECKING([for vpopmail configuration at $vpop_etc/lib_deps])
  2146 	if ! test -f $vpop_etc/lib_deps; then
  2147 		AC_MSG_RESULT(not found)
  2148 		vpop_etc="$vpopmail_home"
  2149 		AC_MSG_CHECKING([for vpopmail configuration at $vpop_etc/lib_deps])
  2150 	fi
  2151 	if test -f $vpop_etc/lib_deps; then
  2152 		AUTH_CFLAGS="$AUTH_CFLAGS `cat $vpop_etc/inc_deps` $CFLAGS"
  2153 		AUTH_LIBS="$AUTH_LIBS `cat $vpop_etc/lib_deps`"
  2154 		AC_DEFINE(USERDB_VPOPMAIL,, Build with vpopmail support)
  2155 		AC_DEFINE(PASSDB_VPOPMAIL,, Build with vpopmail support)
  2156 		AC_MSG_RESULT(found)
  2157 		have_vpopmail=yes
  2158 	else
  2159 		AC_MSG_RESULT(not found)
  2160 		if test $want_vpopmail = yes; then
  2161 		  AC_ERROR([Can't build with vpopmail support: $vpop_etc/lib_deps not found])
  2162 		fi
  2163 	fi
  2164 fi
  2165 
  2166 if test $have_vpopmail = no; then
  2167   not_passdb="$not_passdb vpopmail"
  2168   not_userdb="$not_userdb vpopmail"
  2169 else
  2170   userdb="$userdb vpopmail"
  2171   passdb="$passdb vpopmail"
  2172 fi
  2173 
  2174 AC_CHECK_FUNC(crypt,, [
  2175   AC_CHECK_LIB(crypt, crypt, [
  2176     AUTH_LIBS="-lcrypt $AUTH_LIBS"
  2177   ], [
  2178     AC_MSG_ERROR([crypt() wasn't found])
  2179   ])
  2180 ])
  2181 
  2182 if test $have_modules = yes; then
  2183   AC_DEFINE(HAVE_MODULES,, Define if you have dynamic module support)
  2184   AC_SUBST(MODULE_LIBS)
  2185 
  2186   # shrext_cmds comes from libtool.m4
  2187   module=yes eval MODULE_SUFFIX=$shrext_cmds
  2188   if test "$MODULE_SUFFIX" = ""; then
  2189     # too old libtool?
  2190     MODULE_SUFFIX=.so
  2191   fi
  2192   AC_DEFINE_UNQUOTED(MODULE_SUFFIX,"$MODULE_SUFFIX",Dynamic module suffix)
  2193   AC_SUBST(MODULE_SUFFIX)
  2194 fi
  2195 
  2196 have_nss=no
  2197 if test $want_nss != no; then
  2198   if test $have_modules != yes; then
  2199     if test $want_nss = yes; then
  2200       AC_ERROR([Can't build with NSS support: Dynamic modules not supported])
  2201     fi
  2202   else
  2203     AC_TRY_COMPILE([
  2204       #include <nss.h>
  2205     ], [
  2206       enum nss_status status = NSS_STATUS_TRYAGAIN;
  2207     ], [
  2208       AC_DEFINE(USERDB_NSS,, Build with NSS module support)
  2209       have_nss=yes
  2210     ], [
  2211       if test $want_nss = yes; then
  2212         AC_ERROR([Can't build with NSS support: nss.h not found or not usable])
  2213       fi
  2214     ])
  2215   fi
  2216 fi
  2217 
  2218 if test $have_nss = no; then
  2219   not_userdb="$not_userdb nss"
  2220 else
  2221   userdb="$userdb nss"
  2222 fi
  2223 
  2224 AC_SUBST(AUTH_CFLAGS)
  2225 AC_SUBST(AUTH_LIBS)
  2226 AC_SUBST(SQL_CFLAGS)
  2227 AC_SUBST(SQL_LIBS)
  2228 AC_SUBST(MYSQL_CFLAGS)
  2229 AC_SUBST(MYSQL_LIBS)
  2230 AC_SUBST(PGSQL_CFLAGS)
  2231 AC_SUBST(PGSQL_LIBS)
  2232 AC_SUBST(SQLITE_CFLAGS)
  2233 AC_SUBST(SQLITE_LIBS)
  2234 
  2235 AC_SUBST(DICT_LIBS)
  2236 AC_SUBST(dict_drivers)
  2237 
  2238 dnl **
  2239 dnl ** Endianess
  2240 dnl **
  2241 
  2242 dnl At least Apple's gcc supports __BIG_ENDIAN__ and __LITTLE_ENDIAN__
  2243 dnl defines. Use them if possible to allow cross-compiling.
  2244 AC_MSG_CHECKING([if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined])
  2245 AC_TRY_COMPILE([
  2246   #if !(__BIG_ENDIAN__ || __LITTLE_ENDIAN__)
  2247   #error nope
  2248   #endif
  2249 ], [
  2250 ], [
  2251   AC_DEFINE(WORDS_BIGENDIAN, __BIG_ENDIAN__, Define if your CPU is big endian)
  2252   AC_MSG_RESULT(yes)
  2253 ], [
  2254   AC_MSG_RESULT(no)
  2255   AC_C_BIGENDIAN
  2256 ])
  2257 
  2258 dnl **
  2259 dnl ** IPv6 support
  2260 dnl **
  2261 
  2262 have_ipv6=no
  2263 AC_MSG_CHECKING([for IPv6])
  2264 AC_CACHE_VAL(i_cv_type_in6_addr,
  2265 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  2266 #include <sys/types.h>
  2267 #include <sys/socket.h>
  2268 #include <netinet/in.h>
  2269 #include <netdb.h>
  2270 #include <arpa/inet.h>]],
  2271 [[struct in6_addr i;]])],
  2272 [i_cv_type_in6_addr=yes],
  2273 [i_cv_type_in6_addr=no])])
  2274 if test $i_cv_type_in6_addr = yes; then
  2275 	AC_DEFINE(HAVE_IPV6,, Build with IPv6 support)
  2276 	have_ipv6=yes
  2277 fi
  2278 AC_MSG_RESULT($i_cv_type_in6_addr)
  2279 
  2280 dnl **
  2281 dnl ** storage classes
  2282 dnl **
  2283 
  2284 maildir_libs='$(top_builddir)/src/lib-storage/index/maildir/libstorage_maildir.a'
  2285 mbox_libs='$(top_builddir)/src/lib-storage/index/mbox/libstorage_mbox.a'
  2286 dbox_libs='$(top_builddir)/src/lib-storage/index/dbox/libstorage_dbox.a'
  2287 cydir_libs='$(top_builddir)/src/lib-storage/index/cydir/libstorage_cydir.a'
  2288 raw_libs='$(top_builddir)/src/lib-storage/index/raw/libstorage_raw.a'
  2289 shared_libs='$(top_builddir)/src/lib-storage/index/shared/libstorage_shared.a'
  2290 
  2291 REGISTER_LIBS='$(top_builddir)/src/lib-storage/register/libstorage-register.a '\
  2292 '$(top_builddir)/src/lib-storage/list/libstorage_list.a'
  2293 
  2294 CORE_LIBS='$(top_builddir)/src/lib-storage/index/libstorage_index.a '\
  2295 '$(top_builddir)/src/lib-storage/libstorage.a '\
  2296 '$(top_builddir)/src/lib-index/libindex.a '\
  2297 '$(top_builddir)/src/lib-imap/libimap.a '\
  2298 '$(top_builddir)/src/lib-mail/libmail.a '\
  2299 '$(top_builddir)/src/lib-auth/libauth.a '\
  2300 '$(top_builddir)/src/lib-charset/libcharset.a '\
  2301 '$(top_builddir)/src/lib/liblib.a'
  2302 
  2303 mail_storages="$mail_storages raw"
  2304 # drop duplicates
  2305 mail_storages=`(for i in $mail_storages; do echo $i; done)|sort|uniq|xargs echo`
  2306 STORAGE_LIBS=
  2307 for storage in $mail_storages; do
  2308   STORAGE_LIBS="$STORAGE_LIBS `eval echo \\$${storage}_libs`"
  2309 done
  2310 STORAGE_LIBS="$REGISTER_LIBS $STORAGE_LIBS $CORE_LIBS"
  2311 AC_SUBST(STORAGE_LIBS)
  2312 AC_DEFINE_UNQUOTED(MAIL_STORAGES, "$mail_storages", List of compiled in mail storages)
  2313 
  2314 dnl **
  2315 dnl ** SQL drivers
  2316 dnl **
  2317 
  2318 build_pgsql=no
  2319 build_mysql=no
  2320 build_sqlite=no
  2321 for driver in $sql_drivers; do
  2322   if test "$driver" = "pgsql"; then
  2323     AC_DEFINE(BUILD_PGSQL,, Built-in PostgreSQL support)
  2324     build_pgsql=yes
  2325   elif test "$driver" = "mysql"; then
  2326     AC_DEFINE(BUILD_MYSQL,, Built-in MySQL support)
  2327     build_mysql=yes
  2328   elif test "$driver" = "sqlite"; then
  2329     AC_DEFINE(BUILD_SQLITE,, Built-in SQLite support)
  2330     build_sqlite=yes
  2331   fi
  2332 done
  2333 if test $build_pgsql = no; then
  2334   not_sql_drivers="$not_sql_drivers pgsql"
  2335 fi
  2336 if test $build_mysql = no; then
  2337   not_sql_drivers="$not_sql_drivers mysql"
  2338 fi
  2339 if test $build_sqlite = no; then
  2340   not_sql_drivers="$not_sql_drivers sqlite"
  2341 fi
  2342 
  2343 AC_SUBST(sql_drivers)
  2344 AM_CONDITIONAL(BUILD_PGSQL, test "$build_pgsql" = "yes")
  2345 AM_CONDITIONAL(BUILD_MYSQL, test "$build_mysql" = "yes")
  2346 AM_CONDITIONAL(BUILD_SQLITE, test "$build_sqlite" = "yes")
  2347 AM_CONDITIONAL(SQL_PLUGINS, test "$want_sql" = "plugin")
  2348 
  2349 dnl **
  2350 dnl ** Plugins
  2351 dnl **
  2352 
  2353 if test "$want_zlib" != "no"; then
  2354   AC_CHECK_HEADER(zlib.h, [
  2355     have_zlib=yes
  2356     have_zlib_plugin=yes
  2357     AC_DEFINE(HAVE_ZLIB,, Define if you have zlib library)
  2358   ], [
  2359     if test "$want_zlib" = "yes"; then
  2360       AC_ERROR([Can't build with zlib support: zlib.h not found])
  2361     fi
  2362   ])
  2363 fi
  2364 AM_CONDITIONAL(BUILD_ZLIB, test "$have_zlib" = "yes")
  2365 
  2366 if test "$want_bzlib" != "no"; then
  2367   AC_CHECK_HEADER(bzlib.h, [
  2368     AC_CHECK_LIB(bz2, BZ2_bzdopen, [
  2369       have_bzlib=yes
  2370       have_zlib_plugin=yes
  2371       AC_DEFINE(HAVE_BZLIB,, Define if you have bzlib library)
  2372     ], [
  2373       if test "$want_bzlib" = "yes"; then
  2374 	AC_ERROR([Can't build with bzlib support: libbz2 not found])
  2375       fi
  2376     ])
  2377   ], [
  2378     if test "$want_bzlib" = "yes"; then
  2379       AC_ERROR([Can't build with bzlib support: bzlib.h not found])
  2380     fi
  2381   ])
  2382 fi
  2383 AM_CONDITIONAL(BUILD_BZLIB, test "$have_bzlib" = "yes")
  2384 AM_CONDITIONAL(BUILD_ZLIB_PLUGIN, test "$have_zlib_plugin" = "yes")
  2385 
  2386 RPCGEN=${RPCGEN-rpcgen}
  2387 if ! $RPCGEN -c /dev/null > /dev/null; then
  2388   RPCGEN=
  2389 fi
  2390 AC_SUBST(RPCGEN)
  2391 
  2392 have_rquota=no
  2393 if test -f /usr/include/rpcsvc/rquota.x && test -n "$RPCGEN"; then
  2394   AC_DEFINE(HAVE_RQUOTA,, Define if you wish to retrieve quota of NFS mounted mailboxes)
  2395   have_rquota=yes
  2396 fi
  2397 AM_CONDITIONAL(HAVE_RQUOTA, test "$have_rquota" = "yes")
  2398 
  2399 if test "$want_solr" != "no"; then
  2400   AC_CHECK_PROG(CURLCONFIG, curl-config, YES, NO)
  2401   if test $CURLCONFIG = YES; then
  2402     CURL_CFLAGS=`curl-config --cflags`
  2403     CURL_LIBS=`curl-config --libs`
  2404     
  2405     dnl libcurl found, also need libexpat
  2406     AC_CHECK_LIB(expat, XML_Parse, [
  2407       AC_CHECK_HEADER(expat.h, [
  2408         AC_SUBST(CURL_CFLAGS)
  2409         AC_SUBST(CURL_LIBS)
  2410 	have_solr=yes
  2411       ], [
  2412 	if test $want_solr = yes; then
  2413 	  AC_ERROR([Can't build with Solr support: expat.h not found])
  2414 	fi
  2415       ])
  2416     ], [
  2417       if test $want_solr = yes; then
  2418 	AC_ERROR([Can't build with Solr support: libexpat not found])
  2419       fi
  2420     ])
  2421   else
  2422     if test $want_solr = yes; then
  2423       AC_ERROR([Can't build with Solr support: curl-config not found])
  2424     fi
  2425   fi
  2426 fi
  2427 AM_CONDITIONAL(BUILD_SOLR, test "$have_solr" = "yes")
  2428 
  2429 dnl **
  2430 dnl ** capabilities
  2431 dnl **
  2432 
  2433 capability_banner="IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE"
  2434 capability="$capability_banner SORT THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH"
  2435 AC_DEFINE_UNQUOTED(CAPABILITY_STRING, "$capability", IMAP capabilities)
  2436 AC_DEFINE_UNQUOTED(CAPABILITY_BANNER_STRING, "$capability_banner", IMAP capabilities advertised in banner) 
  2437 
  2438 CFLAGS="$CFLAGS $EXTRA_CFLAGS"
  2439 
  2440 if test "$docdir" = ""; then
  2441   dnl docdir supported only by autoconf v2.59c and later
  2442   docdir='${datadir}/doc/${PACKAGE_TARNAME}'
  2443 fi
  2444 AC_SUBST(docdir)
  2445 
  2446 AC_CONFIG_HEADERS([config.h])
  2447 AC_CONFIG_FILES([
  2448 Makefile
  2449 doc/Makefile
  2450 doc/wiki/Makefile
  2451 src/Makefile
  2452 src/lib/Makefile
  2453 src/lib-sql/Makefile
  2454 src/lib-auth/Makefile
  2455 src/lib-charset/Makefile
  2456 src/lib-dict/Makefile
  2457 src/lib-imap/Makefile
  2458 src/lib-index/Makefile
  2459 src/lib-mail/Makefile
  2460 src/lib-ntlm/Makefile
  2461 src/lib-otp/Makefile
  2462 src/lib-settings/Makefile
  2463 src/lib-storage/Makefile
  2464 src/lib-storage/list/Makefile
  2465 src/lib-storage/index/Makefile
  2466 src/lib-storage/index/maildir/Makefile
  2467 src/lib-storage/index/mbox/Makefile
  2468 src/lib-storage/index/dbox/Makefile
  2469 src/lib-storage/index/cydir/Makefile
  2470 src/lib-storage/index/raw/Makefile
  2471 src/lib-storage/index/shared/Makefile
  2472 src/lib-storage/register/Makefile
  2473 src/auth/Makefile
  2474 src/deliver/Makefile
  2475 src/dict/Makefile
  2476 src/imap/Makefile
  2477 src/imap-login/Makefile
  2478 src/login-common/Makefile
  2479 src/master/Makefile
  2480 src/pop3/Makefile
  2481 src/pop3-login/Makefile
  2482 src/tests/Makefile
  2483 src/util/Makefile
  2484 src/plugins/Makefile
  2485 src/plugins/acl/Makefile
  2486 src/plugins/imap-acl/Makefile
  2487 src/plugins/autocreate/Makefile
  2488 src/plugins/convert/Makefile
  2489 src/plugins/expire/Makefile
  2490 src/plugins/fts/Makefile
  2491 src/plugins/fts-lucene/Makefile
  2492 src/plugins/fts-solr/Makefile
  2493 src/plugins/fts-squat/Makefile
  2494 src/plugins/lazy-expunge/Makefile
  2495 src/plugins/listescape/Makefile
  2496 src/plugins/mail-log/Makefile
  2497 src/plugins/mbox-snarf/Makefile
  2498 src/plugins/quota/Makefile
  2499 src/plugins/imap-quota/Makefile
  2500 src/plugins/trash/Makefile
  2501 src/plugins/virtual/Makefile
  2502 src/plugins/zlib/Makefile
  2503 stamp.h
  2504 dovecot-config.in])
  2505 
  2506 AC_OUTPUT
  2507 
  2508 if test "$want_sql" = "plugin"; then
  2509   sql_drivers="$sql_drivers (plugins)"
  2510 fi
  2511 
  2512 not_passdb=`echo "$not_passdb"|sed 's/ / -/g'`
  2513 not_userdb=`echo "$not_userdb"|sed 's/ / -/g'`
  2514 not_sql_drivers=`echo "$not_sql_drivers"|sed 's/ / -/g'`
  2515 
  2516 echo
  2517 echo "Install prefix . : $prefix"
  2518 echo "File offsets ... : ${offt_bits}bit"
  2519 echo "I/O polling .... : $ioloop"
  2520 echo "I/O notifys .... : $have_notify"
  2521 echo "SSL ............ : $have_ssl"
  2522 echo "GSSAPI ......... : $have_gssapi"
  2523 echo "passdbs ........ :$passdb"
  2524 if test "$not_passdb" != ""; then
  2525   echo "                 :$not_passdb"
  2526 fi
  2527 echo "userdbs ........ :$userdb"
  2528 if test "$not_userdb" != ""; then
  2529   echo "                 :$not_userdb"
  2530 fi
  2531 echo "SQL drivers .... :$sql_drivers"
  2532 if test "$not_sql_drivers" != ""; then
  2533   echo "                 :$not_sql_drivers"
  2534 fi