configure.in
f51e962f
 dnl   Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
72a1b240
 dnl   gethostbyname_r and readdir_r checks (c) COPYRIGHT MIT 1995
4c8f2d76
 dnl   socklen_t check (c) Alexander V. Lukyanov <lav@yars.free.net>
28e73e95
 dnl
 dnl   This program is free software; you can redistribute it and/or modify
 dnl   it under the terms of the GNU General Public License as published by
 dnl   the Free Software Foundation; either version 2 of the License, or
 dnl   (at your option) any later version.
 dnl
 dnl   This program is distributed in the hope that it will be useful,
 dnl   but WITHOUT ANY WARRANTY; without even the implied warranty of
 dnl   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 dnl   GNU General Public License for more details.
 dnl
 dnl   You should have received a copy of the GNU General Public License
 dnl   along with this program; if not, write to the Free Software
48b7b4a7
 dnl   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 dnl   MA 02110-1301, USA.
28e73e95
 
28241733
 AC_PREREQ([2.59])
4c56bffa
 dnl For a release change [devel] to the real version [0.xy]
 dnl also change VERSION below
295f1d1f
 AC_INIT([ClamAV], [devel], [http://bugs.clamav.net/], [clamav], [http://www.clamav.net/])
4c56bffa
 
 dnl put configure auxiliary into config
6053d09a
 AC_CONFIG_AUX_DIR([config])
 AC_CONFIG_HEADER([clamav-config.h])
4c56bffa
 
 dnl safety check, this used to be a parameter to AC_INIT
 AC_CONFIG_SRCDIR([clamscan/clamscan.c])
6053d09a
 AC_CONFIG_MACRO_DIR([m4])
 AC_CREATE_TARGET_H([target.h])
4c56bffa
 
 dnl -Wall and -Werror here are NOT CFLAGS, they refer to automake warnings
295f1d1f
 dnl enable stealth builds and psychedelic tests
 AM_INIT_AUTOMAKE([-Wall -Wportability -Wno-override -Werror std-options foreign dist-bzip2 no-define color-tests])
 AM_SILENT_RULES([yes])
4c56bffa
 
 dnl we told automake to not define these, since we want to include
 dnl the date in the version
28241733
 AC_DEFINE([PACKAGE], PACKAGE_NAME, [Name of package])
4c56bffa
 
 dnl change this on a release
bd0d3efb
 VERSION="devel-`date +%Y%m%d`"
7b470de3
 dnl VERSION="0.94rc1"
28241733
 AC_DEFINE_UNQUOTED([VERSION],"$VERSION",[Version number of package])
6d6e8271
 
005816e3
 LC_CURRENT=6
8df99a92
 LC_REVISION=4
28e73e95
 LC_AGE=0
 LIBCLAMAV_VERSION="$LC_CURRENT":"$LC_REVISION":"$LC_AGE"
28241733
 AC_SUBST([LIBCLAMAV_VERSION])
28e73e95
 
 AC_PROG_AWK
 AC_PROG_INSTALL
 AC_PROG_LN_S
 AC_PROG_MAKE_SET
a0e5e844
 
094104a7
 LT_CONFIG_LTDL_DIR([libltdl])
 LT_INIT([dlopen])
 LTDL_INIT([recursive])
 AC_CONFIG_FILES([libltdl/Makefile])
28e73e95
 
0b44bb9f
 major=`expr $LC_CURRENT - $LC_AGE`
 AC_DEFINE_UNQUOTED([LIBCLAMAV_FULLVER], "$major.$LC_AGE.$LC_REVISION",
 	  ["Full library version number"])
 AC_DEFINE_UNQUOTED([LIBCLAMAV_MAJORVER], $major,
 	  ["Major library version number"])
28241733
 AC_DEFINE([SCANBUFF], 131072, [scan buffer size])
 AC_DEFINE([FILEBUFF], 8192,   [file i/o buffer size])
28e73e95
 
9d444ac6
 AC_LIB_MULTILIB_GUESS
 
28e73e95
 AC_HEADER_STDC
8b46ba3f
 AC_C_RESTRICT
28241733
 AC_C_CONST
 AC_C_INLINE
 AC_C_FPU_BIGENDIAN
 AC_C_BIGENDIAN
156e643c
 if test $ac_cv_c_bigendian = no; then
     m4_default([], [AC_DEFINE([WORDS_BIGENDIAN], 0)])
 fi
cbc69ae8
 
28241733
 AC_ARG_ENABLE([gcc-vcheck],
cbc69ae8
 [  --disable-gcc-vcheck	  do not check for buggy gcc version ],
 gcc_check=$enableval, gcc_check="yes")
 
 msg_gcc_check="use --disable-gcc-vcheck to disable this check. Before reporting any bugs check with a supported version of gcc"
b105842c
 VERSION_SUFFIX=
cbc69ae8
 dnl Check for gcc-4.1.0
 if test "$gcc_check" = "yes"; then
 	if test "x$ac_compiler_gnu" = "xyes"; then
 		AC_MSG_CHECKING([for a supported version of gcc])
 		gcc_version=`${CC} -dumpversion`
 		case "${gcc_version}" in
 			4.1.0*)
 				AC_MSG_RESULT([no (${gcc_version})])
 				AC_MSG_ERROR([gcc 4.1.0 is known to incorrectly compile upx.c. Upgrade your compiler to at least 4.1.1/4.1.2)])
 				;;
 			*)
 				AC_MSG_RESULT([ok (${gcc_version})])
 				;;
2fd6eb95
 		esac
 		# bb #1581 - temporarely add -fno-strict-aliasing so gcc 4.4.0
 		# works correctly
 		CFLAGS="$CFLAGS -fno-strict-aliasing"
cbc69ae8
 	fi
b105842c
 else
 	CFLAGS="$CFLAGS -O0"
 	VERSION_SUFFIX="$VERSION_SUFFIX-broken-compiler"
cbc69ae8
 fi
 
fd9379f9
 # add distcheck warning flags
 distcheck_enable_flags=0
 if test "x$ac_compiler_gnu" = "xyes"; then
 	gcc_version=`${CC} -dumpversion`
 	case "${gcc_version}" in
 		4.[[3456789]].*)
 			distcheck_enable_flags=1
 			;;
 		[[56789]].*)
 			distcheck_enable_flags=1
 			;;
 	esac
 fi
 AM_CONDITIONAL([DISTCHECK_ENABLE_FLAGS], test "x$distcheck_enable_flags" = "x1")
b105842c
 
cbc69ae8
 dnl Checks if compiler produces valid code, regardless of compiler
 dnl we do these checks here to avoid receiving endless bugreports about
 dnl breakages due to compiler bugs.
 
 dnl Check if compiler produces invalid code on gcc PR27603 (affects upx.c)
6295dc5c
 dnl testcase from gcc testsuite
cbc69ae8
 AC_MSG_CHECKING([for gcc bug PR27603])
 AC_TRY_RUN(
 	   [
6295dc5c
 /* (C) Richard Guenther */	   
cbc69ae8
 void exit (int);
 void abort (void);
 int a;
28241733
 int main(void)
cbc69ae8
 {
   int j;
   for (j = 0; j < 6; j++)
   {
     if ((unsigned)j - 3 <= 1)
       exit (0);
     a = 1000 * (6 - j);
   }
   abort ();
 }
 ], [AC_MSG_RESULT([ok, bug not present])],
c528900f
 [AC_MSG_ERROR([your compiler has gcc PR27603 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27603])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
cbc69ae8
 
 dnl Check if compiler produces invalid code on gcc PR26763-2 (affects upx.c)
6295dc5c
 dnl testcase from gcc testsuite
cbc69ae8
 AC_MSG_CHECKING([for gcc bug PR26763-2])
 AC_TRY_RUN(
 	   [
6295dc5c
 /* (C) Richard Guenther */	   
cbc69ae8
 extern void abort(void);
 
5cd3f734
 static int try (char *a, int d)
cbc69ae8
 {
   return a + d > a;
 }
 
 int main(void)
 {
   char bla[100];
 
   if (try (bla + 50, -1))
     abort ();
 
   return 0;
 }
 ], [AC_MSG_RESULT([ok, bug not present])],
c528900f
 [AC_MSG_ERROR([your compiler has gcc PR26763-2 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26763])],[AC_MSG_RESULT([cross-compiling, assumed ok])])
cbc69ae8
 
 dnl Check if compiler produces invalid code on own testcase based on upx.c
 AC_MSG_CHECKING([for valid code generation of CLI_ISCONTAINED])
 AC_TRY_RUN(
183f9e75
 	   [
cbc69ae8
 #include <stdio.h>
 static struct v{
 	char* dst;
183f9e75
 	unsigned int dsize;
 	unsigned int dcur;
 	unsigned int backsize;
 	signed int unp_offset;
cbc69ae8
 } values[] = {
183f9e75
 	{(char*)0xf78ab008, 0x2e000, 1, 4, -1594},
 	{(char*)0xb7af1008, 0x2e000, 1, 4, -1594}
cbc69ae8
 
 };
 extern void abort(void);
 
 #define CLI_ISCONTAINED(bb, bb_size, sb, sb_size)	\
bdd4b77c
   ((bb_size) > 0 && (sb_size) > 0 && (size_t)(sb_size) <= (size_t)(bb_size) \
    && (sb) >= (bb) && ((sb) + (sb_size)) <= ((bb) + (bb_size)) && ((sb) + (sb_size)) > (bb) && (sb) < ((bb) + (bb_size)))
cbc69ae8
 
183f9e75
 int crashtest()
 {
5cd3f734
 	unsigned int backsize, dcur;
183f9e75
 	int dval=0x12000, unp_offset;
 	int* dsize = &dval;
 	char* dst = (char*)0x12000;
 	while(1) {
 		backsize=4;
 		dcur=0;
 		unp_offset=0x800002c7;
 
 		if (!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) || !CLI_ISCONTAINED(dst, *dsize, dst+dcur, backsize) || unp_offset >=0)
 			return -1;
 		abort();
 	}
 	return 0;
 }
 
28241733
 int main(void)
cbc69ae8
 {
 	int i;
 	for(i=0;i<sizeof(values)/sizeof(values[0]);i++) {
 		struct v* v= &values[i];
 		char* dst = v->dst;
183f9e75
 		unsigned int* dsize = &v->dsize;
 		unsigned int dcur = v->dcur;
 		unsigned int backsize = v->backsize-1;
 		signed int  unp_offset = v->unp_offset;
cbc69ae8
 
 		if(!CLI_ISCONTAINED(dst, *dsize, dst+dcur+unp_offset, backsize) ||
 				!CLI_ISCONTAINED(dst, *dsize,dst+dcur,backsize) || unp_offset >= 0)  {
 			continue;
 		}
 		abort();
 	}
183f9e75
 	crashtest();
cbc69ae8
 	return 0;
 }
 ], [AC_MSG_RESULT([ok, bug not present])],
183f9e75
 [AC_MSG_ERROR([your compiler has a bug that causes clamav bug no. 670, use a different compiler, see http://bugs.clamav.net/bugzilla/show_bug.cgi?id=670])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
 
 dnl Check if compiler produces invalid code on gcc PR28045 (affects upx.c)
 dnl testcase from gcc testsuite
 AC_MSG_CHECKING([for gcc bug PR28045])
 AC_TRY_RUN(
 	   [
 /* (C) Andrew Pinski */
 extern void abort(void);
 struct a
 {
    unsigned int bits : 1;
    signed long val : ((sizeof(long) * 8) - 1);
 };
5cd3f734
 static int Fnegate (struct a b)
183f9e75
 {
   if ((-((long)b.val)) <= ((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))
       && (-((long)b.val)) >= (-(((long) ((1UL << ((sizeof(long) * 8) - 2)) -1UL))) - 1))
      return 0 ;
   abort ();
 }
5cd3f734
 int main (void)
183f9e75
 {
   struct a b = {1, 1};
   Fnegate (b);
   return 0;
 }
 ], [AC_MSG_RESULT([ok, bug not present])],
 [AC_MSG_ERROR([your compiler has gcc PR28045 bug, use a different compiler, see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28045])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
 
a20faa3f
 dnl Check if compiler produces invalid code on gcc PR37573 (affects autoit.c)
 dnl this is a bug in gcc 4.4.0, but for some reason it affects gcc 4.1.2 too
 dnl gcc 4.1.3 is OK. This bug occurs only at -O3.
 AC_MSG_CHECKING([for gcc bug PR37573])
 AC_TRY_RUN(
 	   [
e30a2c40
 #include <stdlib.h>
a35d4b4e
 #include <string.h>
a20faa3f
 struct S
 {
   unsigned int *a;
   unsigned int b;
   unsigned int c[624];
 };
 static unsigned char
 foo (struct S *s)
 {
   unsigned int r;
   if (!--s->b)
     {
       unsigned int *c = s->c;
       unsigned int i;
       s->a = c;
       for (i = 0; i < 227; i++)
 	c[i] =
 	  ((((c[i] ^ c[i + 1]) & 0x7ffffffe) ^ c[i]) >> 1) ^
 	  ((0 - (c[i + 1] & 1)) & 0x9908b0df) ^ c[i + 397];
       for (; i < 623; i++)
 	c[i] =
 	  ((((c[i] ^ c[i + 1]) & 0x7ffffffe) ^ c[i]) >> 1) ^
 	  ((0 - (c[i + 1] & 1)) & 0x9908b0df) ^ c[i - 227];
       c[623] =
 	((((c[623] ^ c[0]) & 0x7ffffffe) ^ c[623]) >> 1) ^ ((0 - (c[0] & 1)) &
 							    0x9908b0df) ^ c[i
 									    -
 									    227];
     }
   r = *(s->a++);
   r ^= (r >> 11);
   r ^= ((r & 0xff3a58ad) << 7);
   r ^= ((r & 0xffffdf8c) << 15);
   r ^= (r >> 18);
   return (unsigned char) (r >> 1);
 }
 
 void
 bar (unsigned char *p, unsigned int q, unsigned int r)
 {
   struct S s;
   unsigned int i;
   unsigned int *c = s.c;
   *c = r;
   for (i = 1; i < 624; i++)
     c[i] = i + 0x6c078965 * ((c[i - 1] >> 30) ^ c[i - 1]);
   s.b = 1;
   while (q--)
     *p++ ^= foo (&s);
 };
 
 static unsigned char p[23] = {
   0xc0, 0x49, 0x17, 0x32, 0x62, 0x1e, 0x2e, 0xd5, 0x4c, 0x19, 0x28, 0x49,
     0x91, 0xe4, 0x72, 0x83, 0x91, 0x3d, 0x93, 0x83, 0xb3, 0x61, 0x38
 };
 
 static unsigned char q[23] = {
   0x3e, 0x41, 0x55, 0x54, 0x4f, 0x49, 0x54, 0x20, 0x55, 0x4e, 0x49, 0x43,
     0x4f, 0x44, 0x45, 0x20, 0x53, 0x43, 0x52, 0x49, 0x50, 0x54, 0x3c
 };
 
 int
 main (void)
 {
   unsigned int s;
   s = 23;
   bar (p, s, s + 0xa25e);
e30a2c40
   if (memcmp (p, q, s) != 0)
 	abort ();
a20faa3f
   return 0;
 }
 
 ], [AC_MSG_RESULT([ok, bug not present])],
c828f71a
 [AC_MSG_ERROR([your compiler has gcc PR37573 bug, use a lower optimization level (-O1 or -O2), see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37573])], [AC_MSG_RESULT([cross-compiling, assumed ok])])
a20faa3f
 
28241733
 dnl Linker feature checks
 dnl check for version script support in the linker (GNU ld, or Solaris ld style)
 AC_CACHE_CHECK([for ld --version-script], [ac_cv_ld_version_script], [dnl
   cat > conftest.c <<EOF
 void cl_symbol1(void) {}
 void cli_symbol2(void) {}
 EOF
   cat > conftest.map <<EOF
 RELEASE
 {
 	global:
 		cl_*;
 	local:
 		*;
 };
 PRIVATE
 {
 	global:
 		cli_*;
 	local:
 		*;
 };
 EOF
   dnl check for GNU ld style linker version script
   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $pic_flag $LDFLAGS -shared
 				-o conftest.so conftest.c
 				-Wl,--version-script,conftest.map
 		       1>&AS_MESSAGE_LOG_FD]);
   then
       VERSIONSCRIPTFLAG=--version-script
       ac_cv_ld_version_script=yes
   else
 	dnl check for Solaris ld style linker version script
 	if AC_TRY_COMMAND([${CC-cc} $CFLAGS $pic_flag $LDFLAGS -shared
 				-o conftest.so conftest.c
 				-Wl,-M,conftest.map
 			1>&AS_MESSAGE_LOG_FD]);
 	then
 		VERSIONSCRIPTFLAG=-M
 		ac_cv_ld_version_script=yes;
 	else
 		ac_cv_ld_version_script=no
 	fi
   fi
  rm -f conftest*])
 AC_SUBST([VERSIONSCRIPTFLAG])
 AM_CONDITIONAL([VERSIONSCRIPT], test "x$ac_cv_ld_version_script" = "xyes")
cbc69ae8
 
fd08e02e
 # it is not fatal if gperf is missing
 AM_MISSING_PROG(GPERF, gperf)
 AC_SUBST(GPERF)
 
28241733
 AC_CHECK_HEADERS([stdint.h unistd.h sys/int_types.h dlfcn.h inttypes.h sys/inttypes.h memory.h ndir.h stdlib.h strings.h string.h sys/mman.h sys/param.h sys/stat.h sys/types.h malloc.h poll.h limits.h sys/filio.h sys/uio.h termios.h stdbool.h pwd.h grp.h])
 AC_CHECK_HEADER([syslog.h],AC_DEFINE([USE_SYSLOG],1,[use syslog]),)
05491efb
 
28e73e95
 AC_TYPE_OFF_T
28241733
 AC_COMPILE_CHECK_SIZEOF([short])
 AC_COMPILE_CHECK_SIZEOF([int])
 AC_COMPILE_CHECK_SIZEOF([long])
 AC_COMPILE_CHECK_SIZEOF([long long])
0281fb4d
 AC_COMPILE_CHECK_SIZEOF([void *])
2d781f3e
 
28241733
 AC_ARG_ENABLE([experimental],
71dd1750
 [  --enable-experimental	enable experimental code],
 enable_experimental=$enableval, enable_experimental="no")
 
 if test "$enable_experimental" = "yes"; then
28241733
   AC_DEFINE([CL_EXPERIMENTAL],1,[enable experimental code])
b105842c
   VERSION_SUFFIX="$VERSION_SUFFIX-exp"
71dd1750
 fi
 
28241733
 AC_CHECK_LIB([socket], [bind], [LIBS="$LIBS -lsocket"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsocket"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lsocket"; CLAMD_LIBS="$CLAMD_LIBS -lsocket"])
ad08b903
 AC_SEARCH_LIBS([gethostent],[nsl], [(LIBS="$LIBS -lnsl"; CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lnsl"; FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lnsl"; CLAMD_LIBS="$CLAMD_LIBS -lnsl")])
5efcc38b
 
e6dedc72
 AC_CHECK_FUNCS([poll setsid memcpy snprintf vsnprintf strerror_r strlcpy strlcat strcasestr inet_ntop setgroups initgroups ctime_r mkstemp mallinfo])
414abe87
 AC_FUNC_FSEEKO
afb48b28
 
86d59b24
 dnl Check if anon maps are available, check if we can determine the page size
 AC_C_FUNC_MMAP_PRIVATE
 AC_C_FUNC_PAGESIZE
af23f58e
 AC_ARG_ENABLE([mempool],[  --disable-mempool       disable memory pools], enable_mempool=$enableval, enable_mempool="yes")
946bd266
 if test "$enable_mempool" = "yes"; then
 	if test "$ac_cv_c_mmap_private" != "yes"; then
af23f58e
 		AC_MSG_NOTICE([****** mempool support disabled (mmap not available or not usable)])
946bd266
 	else
86d59b24
 		if test "$ac_cv_c_can_get_pagesize" != "yes"; then
 			AC_MSG_NOTICE([****** mempool support disabled (pagesize cannot be determined)])
 		else
946bd266
 			AC_C_FUNC_MMAP_ANONYMOUS
 			if test "$ac_cv_c_mmap_anonymous" = "no"; then
af23f58e
 				AC_MSG_NOTICE([****** mempool support disabled (anonymous mmap not available)])
946bd266
 			else
 				AC_DEFINE([USE_MPOOL],1,[enable memory pools])
 			fi
86d59b24
 		fi
946bd266
 	fi
 fi
 
232c4b70
 enable_check_ut=auto
 enable_ut_install=no
fe473bcb
 AC_ARG_ENABLE(check,
232c4b70
 [  --enable-check           Enable 'check' unit tests (default=auto)], enable_check_ut=$enableval, enable_check_ut="auto" )
fe473bcb
 
 if test "$enable_check_ut" != "no" ; then
15d67313
 	AC_LIB_FIND([check],[check.h],
 			AC_LANG_PROGRAM([#include <check.h>],[srunner_create(0)]),
 			[CHECK_CPPFLAGS="$INCCHECK"; CHECK_LIBS="$LTLIBCHECK"],
 			[])
fe473bcb
 fi
15d67313
 AC_SUBST([CHECK_CPPFLAGS])
 AC_SUBST([CHECK_LIBS])
 AM_CONDITIONAL([HAVE_LIBCHECK],test "X$HAVE_LIBCHECK" = "Xyes")
fe473bcb
 
d1d558c9
 if test "x$CHECK_LIBS" = "x" -a "$enable_check_ut" = "yes"; then
     AC_MSG_ERROR([
6115b5ce
 
 ERROR!  Check was configured, but not found.  Get it from http://check.sf.net/
 ])
fe473bcb
 fi
 
232c4b70
 AC_ARG_ENABLE(coverage,
 	      AC_HELP_STRING([--enable-coverage],
 			     [turn on test coverage
 			      @<:@default=no@:>@]),
 [enable_cov=$enableval],[enable_cov="no"])
 
 if test "x$enable_coverage" = "xyes"; then
d1d558c9
 	if test "x$CHECK_LIBS" = "x"; then
 		AC_MSG_ERROR([Coverage testing required, but unit tests not enabled!])
 	fi
232c4b70
 	if test "x$ac_compiler_gnu" != "xyes"; then
 		AC_MSG_ERROR([coverage testing only works if gcc is used])
 	fi
 
 	CFLAGS="$CFLAGS -fprofile-arcs -ftest-coverage"
 	LDFLAGS="$LDFLAGS -lgcov"
3dcc2d78
 	AC_CHECK_PROGS(GCOV, gcov, false)
 	AC_CHECK_PROGS(LCOV, lcov, false)
 	AC_CHECK_PROGS(GENHTML, genhtml, false)
232c4b70
 fi
 
 AM_CONDITIONAL(ENABLE_COVERAGE, test "x$enable_coverage" = "xyes")
e5b07839
 
28e73e95
 have_pthreads=no
28241733
 AC_CHECK_HEADER([pthread.h],[have_pthreads=yes],)
28e73e95
 
6c7dbf7d
 AM_MAINTAINER_MODE
ef1c1b34
 dnl Check for zlib
28241733
 AC_MSG_CHECKING([for zlib installation])
 AC_ARG_WITH([zlib],
ef1c1b34
 [  --with-zlib=DIR	  path to directory containing zlib library (default=
 			  /usr/local or /usr if not found in /usr/local)],
 [
 if test "$withval"; then
   ZLIB_HOME="$withval"
28241733
   AC_MSG_RESULT([using $ZLIB_HOME])
ef1c1b34
 fi
 ], [
 ZLIB_HOME=/usr/local
 if test ! -f "$ZLIB_HOME/include/zlib.h"
 then
   ZLIB_HOME=/usr
 fi
28241733
 AC_MSG_RESULT([$ZLIB_HOME])
ef1c1b34
 ])
 
28241733
 AC_ARG_ENABLE([zlib-vcheck],
3e296a10
 [  --disable-zlib-vcheck	  do not check for buggy zlib version ],
8a057f52
 zlib_check=$enableval, zlib_check="yes")
3e296a10
 
ef1c1b34
 if test ! -f "$ZLIB_HOME/include/zlib.h"
 then
28241733
     AC_MSG_ERROR([Please install zlib and zlib-devel packages])
ef1c1b34
 else
3e296a10
 
ef1c1b34
     vuln=`grep "ZLIB_VERSION \"1.2.0" $ZLIB_HOME/include/zlib.h`
     if test -z "$vuln"; then
 	vuln=`grep "ZLIB_VERSION \"1.2.1" $ZLIB_HOME/include/zlib.h`
     fi
 
     if test -n "$vuln"; then
3e296a10
 	if test "$zlib_check" = "yes"; then
4233b0eb
 	    AC_MSG_ERROR(The installed zlib version may contain a security bug. Please upgrade to 1.2.2 or later: http://www.zlib.net. You can omit this check with --disable-zlib-vcheck but DO NOT REPORT any stability issues then!)
3e296a10
 	else
 	    AC_MSG_WARN([****** This ClamAV installation may be linked against])
 	    AC_MSG_WARN([****** a broken zlib version. Please DO NOT report any])
 	    AC_MSG_WARN([****** stability problems to the ClamAV developers!])
 	fi
ef1c1b34
     fi
 
67e1ca4a
     if test "$ZLIB_HOME" != "/usr"; then
 	CPPFLAGS="$CPPFLAGS -I$ZLIB_HOME/include"
ef38c83d
 	save_LDFLAGS="$LDFLAGS"
4a40b66c
 	save_LIBS="$LIBS"
 	LDFLAGS="$LDFLAGS -L$ZLIB_HOME/lib"
0b4c0baa
 	AC_CHECK_LIB([z], [inflateEnd], [LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -L$ZLIB_HOME/lib -lz";FRESHCLAM_LIBS="$FRESHCLAM_LIBS -L$ZLIB_HOME/lib -lz"], AC_MSG_ERROR([Please install zlib and zlib-devel packages]))
e8d1666f
 	AC_CHECK_LIB([z], [gzopen], [], AC_MSG_ERROR([Your zlib is missing gzopen()]))
ef38c83d
 	LDFLAGS="$save_LDFLAGS"
4a40b66c
 	LIBS="$save_LIBS"
67e1ca4a
     else
0b4c0baa
 	AC_CHECK_LIB([z], [inflateEnd], [LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -lz";FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lz"], AC_MSG_ERROR([Please install zlib and zlib-devel packages]))
e8d1666f
 	AC_CHECK_LIB([z], [gzopen],[], AC_MSG_ERROR([Your zlib is missing gzopen()]))
67e1ca4a
     fi
ef1c1b34
 fi
28e73e95
 
28241733
 AC_ARG_ENABLE([bzip2],
25c90ced
 [  --disable-bzip2	  disable bzip2 support],
8a057f52
 want_bzip2=$enableval, want_bzip2="yes")
28e73e95
 
b22aef42
 if test "$want_bzip2" = "yes"
 then
28241733
     AC_LIB_LINKFLAGS([bz2])
945655bd
     save_LDFLAGS="$LDFLAGS"
871ad508
     LDFLAGS="$LDFLAGS -L$LIBBZ2_PREFIX/$acl_libdirstem";
50b1bff4
 
     have_bzprefix="no"
     AC_CHECK_LIB([bz2], [BZ2_bzReadOpen], [have_bzprefix="yes"])
     if test "x$have_bzprefix" = "xno"; then
         AC_DEFINE([NOBZ2PREFIX],1,[bzip funtions do not have bz2 prefix])
     fi
945655bd
     LDFLAGS="$save_LDFLAGS"
6053d09a
     if test "$HAVE_LIBBZ2" = "yes"; then
28241733
 	AC_CHECK_HEADER([bzlib.h],
440fcf67
 			[AC_C_CVE_2008_1372],
d1d558c9
 			[ac_cv_c_cve_2008_1372="no"])
440fcf67
 	if test "$ac_cv_c_cve_2008_1372" = "bugged"; then
 		AC_MSG_WARN([****** bzip2 libraries are affected by the CVE-2008-1372 bug])
 		AC_MSG_WARN([****** We strongly suggest you to update to bzip2 1.0.5.])
 		AC_MSG_WARN([****** Please do not report stability problems to the ClamAV developers!])
 	fi
d4c8adb3
 	if test "$ac_cv_c_cve_2008_1372" = "linkfailed"; then
 		dnl This shouldn't happen
 		dnl We failed to link but libtool may still be able to link, so don't disable bzip2 just yet
 		AC_MSG_WARN([****** Unable to link bzip2 testcase])
 		AC_MSG_WARN([****** You may be affected by CVE-2008-1372 bug, but I need to be able to link a testcase to verify])
 		AC_MSG_WARN([****** It is recommended to fix your build environment so that we can run the testcase!])
 		AC_MSG_WARN([****** Please do not report stability problems to the ClamAV developers!])
 	fi
440fcf67
 
 	case "$ac_cv_c_cve_2008_1372" in
d4c8adb3
 	ok|bugged|linkfailed)
440fcf67
 		LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS $LTLIBBZ2"
 		AC_DEFINE([HAVE_BZLIB_H],1,[have bzip2])
 		;;
 	*)
 		AC_MSG_WARN([****** bzip2 support disabled])
 		;;
 	esac
 
6053d09a
     else
 	AC_MSG_WARN([****** bzip2 support disabled])
     fi
b22aef42
 fi
 
28241733
 AC_ARG_ENABLE([unrar],
5ca7fd18
 [  --disable-unrar	  don't build libclamunrar and libclamunrar_iface ],
 want_unrar=$enableval, want_unrar="yes")
094104a7
 AM_CONDITIONAL([ENABLE_UNRAR],[test "$want_unrar" = "yes"])
5ca7fd18
 
3027857c
 AC_ARG_ENABLE([getaddrinfo],
 [  --disable-getaddrinfo          disable support for getaddrinfo],
 want_getaddrinfo=$enableval, want_getaddrinfo="yes")
b54eb319
 
3027857c
 if test "$want_getaddrinfo" = "yes"
b54eb319
 then
     AC_MSG_CHECKING([for getaddrinfo])
5348fa8d
     AC_CACHE_VAL([have_cv_gai],[
b54eb319
 		AC_TRY_RUN([
 		    #include <sys/types.h>
 		    #include <sys/socket.h>
 		    #include <netdb.h>
3027857c
 		    #include <unistd.h>
b54eb319
 		    int main(int argc, char **argv)
 		    {
45941d27
 			    struct addrinfo *res;
3027857c
 			    int sd;
b54eb319
 
45941d27
 			if(getaddrinfo("127.0.0.1", NULL, NULL, &res) < 0)
b54eb319
 			    return 1;
 			freeaddrinfo(res);
3027857c
 
b54eb319
 			return 0;
 		    }
 		],
5348fa8d
 		[have_cv_gai=yes],
 		[have_cv_gai=no],
 		[have_cv_gai=no])
b54eb319
 		])
5348fa8d
     AC_MSG_RESULT([$have_cv_gai])
     if test "$have_cv_gai" = yes; then
3027857c
 	AC_DEFINE(HAVE_GETADDRINFO, 1, [have getaddrinfo()])
     fi
 fi
 
 AC_ARG_ENABLE([ipv6],
 [  --disable-ipv6          disable IPv6 support],
 want_ipv6=$enableval, want_ipv6="yes")
 
 if test "$want_ipv6" = "yes"
 then
     AC_MSG_CHECKING([for IPv6 support])
5348fa8d
     AC_CACHE_VAL([have_cv_ipv6],[
3027857c
 		AC_TRY_RUN([
 		    #include <sys/types.h>
 		    #include <sys/socket.h>
45941d27
 		    #include <netdb.h>
3027857c
 		    #include <unistd.h>
 		    int main(int argc, char **argv)
 		    {
45941d27
 			    struct addrinfo *res, hints;
3027857c
 			    int sd;
 
 			if((sd = socket(AF_INET6, SOCK_STREAM, 0)) < 0)
 			    return 1;
 			close(sd);
45941d27
 			/* also check if getaddrinfo() handles AF_UNSPEC -- bb#1196 */
 			memset(&hints, 0, sizeof(hints));
 			hints.ai_family = AF_UNSPEC;
 			if(getaddrinfo("127.0.0.1", NULL, &hints, &res) < 0)
 			    return 1;
 			freeaddrinfo(res);
3027857c
 			return 0;
 		    }
 		],
5348fa8d
 		[have_cv_ipv6=yes],
 		[have_cv_ipv6=no],
 		[have_cv_ipv6=no])
3027857c
 		])
5348fa8d
     AC_MSG_RESULT([$have_cv_ipv6])
     if test "$have_cv_ipv6" = yes; then
3027857c
 	AC_DEFINE(SUPPORT_IPv6, 1, [Support for IPv6])
b54eb319
     fi
 fi
 
55144c47
 AC_C_DNS
28e73e95
 
28241733
 AC_ARG_ENABLE([clamuko],
23a4a7e3
 [  --disable-clamuko	  disable clamuko support (Linux, DragonFly and FreeBSD only)],
8a057f52
 want_clamuko=$enableval, want_clamuko="yes")
32fc1d7b
 
c528900f
 dnl AC_FUNC_SETPGRP does not work when cross compiling
 dnl Instead, assume we will have a prototype for setpgrp if cross compiling.
 dnl testcase from gdb/configure.ac
 if test "$cross_compiling" = no; then
  AC_FUNC_SETPGRP
 else
28241733
  AC_CACHE_CHECK([whether setpgrp takes no argument], [ac_cv_func_setpgrp_void],
c528900f
    [AC_TRY_COMPILE([
 #include <unistd.h>
 ], [
  if (setpgrp(1,1) == -1)
    exit (0);
  else
    exit (1);
 ], ac_cv_func_setpgrp_void=no, ac_cv_func_setpgrp_void=yes)])
 if test $ac_cv_func_setpgrp_void = yes; then
28241733
  AC_DEFINE([SETPGRP_VOID], 1)
c528900f
 fi
 fi
a6945b5d
 
28241733
 AC_ARG_ENABLE([milter],
25c90ced
 [  --enable-milter	  build clamav-milter],
8a057f52
 have_milter=$enableval, have_milter="no")
28e73e95
 
15b3dc23
 have_system_tommath=no
 AC_ARG_WITH([system-tommath],
 [  --with-system-tommath	link against system libtommath (default = no, use bundled)],
 [
 	case "$withval" in
 	yes)
 		AC_CHECK_LIB([tommath], [mp_mul_2d],
 			[
 				AC_DEFINE([HAVE_SYSTEM_TOMMATH], 1, [link against system-wide libtommath])
 				LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -ltommath"
 				have_system_tommath=yes
 			],
 			[AC_MSG_WARN([****** Option --with-system-tommath was given but libtommath does not seem to be available, using bundled files instead])]
 		)
 	;;
 	no) ;;
 	*) AC_MSG_ERROR([--with-system-tommath does not take an argument]) ;;
 	esac
 ])
 AM_CONDITIONAL([LINK_TOMMATH], test "x$have_system_tommath" = "xyes")
 
 
a9ae2f5f
 dnl we need to try to link with iconv, otherwise there could be a 
 dnl mismatch between a 32-bit and 64-bit lib. Detect this at configure time.
 dnl we need to check after zlib/bzip2, because they can change the include path
 AC_ARG_WITH([iconv], [  --with-iconv supports iconv() (default=auto)],
 [
  case "$withval" in
 	 yes|no) wiconv="$withval";;
 	 *) AC_MSG_ERROR([--with-iconv does not take an argument]);;
  esac],
 [ wiconv=auto ])
 if test "X$wiconv" != "Xno"; then
 	AC_CHECK_LIB([iconv], [libiconv_open], LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS -liconv")
 	AC_MSG_CHECKING([for iconv])
 	save_LIBS="$LIBS"
 	LIBS="$LIBCLAMAV_LIBS"
 	AC_TRY_LINK([
 		     #include <iconv.h>
 	],[
 	char** xin,**xout;
f7e2294c
 	unsigned long il,ol;
a9ae2f5f
 	int rc;
 	iconv_t iconv_struct = iconv_open("UTF-16BE","UTF-8");
 	rc = iconv(iconv_struct,xin,&il,xout,&ol);
 	iconv_close(iconv_struct);
 ],[
    AC_MSG_RESULT(yes)
    AC_DEFINE([HAVE_ICONV], 1, [iconv() available])
 ],[
 	AC_MSG_RESULT(no)
 ])
 	LIBS="$save_LIBS"
 fi
 
28241733
 AC_ARG_ENABLE([pthreads],
25c90ced
 [  --disable-pthreads      disable POSIX threads support],
8a057f52
 have_pthreads=$enableval,)
28e73e95
 
28241733
 AC_ARG_ENABLE([cr],
25c90ced
 [  --disable-cr		  don't link with C reentrant library (BSD) ],
c4ce5fd5
 use_cr=$enableval,)
28e73e95
 
28241733
 AC_ARG_ENABLE([id-check],
25c90ced
 [  --enable-id-check	  use id utility instead of /etc/passwd parsing],
8a057f52
 use_id=$enableval, use_id="no")
28e73e95
 
28241733
 AC_ARG_ENABLE([yp-check],
25c90ced
 [  --enable-yp-check	  use ypmatch utility instead of /etc/passwd parsing],
8a057f52
 use_yp=$enableval, use_yp="no")
0f8e1ad4
 
28241733
 AC_ARG_WITH([user], 
25c90ced
 [  --with-user=uid	  name of the clamav user (default=clamav)],
28e73e95
 clamav_user="$withval", clamav_user="clamav")
 
28241733
 AC_ARG_WITH([group], 
25c90ced
 [  --with-group=gid	  name of the clamav group (default=clamav)],
28e73e95
 clamav_group="$withval", clamav_group="clamav")
 
28241733
 AC_DEFINE_UNQUOTED([CLAMAVUSER],"$clamav_user",[name of the clamav user])
 AC_DEFINE_UNQUOTED([CLAMAVGROUP],"$clamav_group",[name of the clamav group])
28e73e95
 
28241733
 AC_ARG_ENABLE([clamav],
25c90ced
 [  --disable-clamav	  disable test for clamav user/group],
8a057f52
 test_clamav=$enableval, test_clamav=yes)
28e73e95
 
28241733
 AC_ARG_ENABLE([debug],
25c90ced
 [  --enable-debug	  enable debug code],
8a057f52
 enable_debug=$enableval, enable_debug="no")
 
 if test "$enable_debug" = "yes"; then
28241733
   AC_DEFINE([CL_DEBUG],1,[enable debugging])
6a21552e
 else
   AC_DEFINE([NDEBUG],1,[disable assertions])
8a057f52
 fi
28e73e95
 
28241733
 AC_ARG_ENABLE([no-cache],
69dfd3de
 [  --enable-no-cache	  use "Cache-Control: no-cache" in freshclam],
 enable_nocache=$enableval, enable_nocache="no")
 
 if test "$enable_nocache" = "yes"; then
28241733
   AC_DEFINE([FRESHCLAM_NO_CACHE],1,[use "Cache-Control: no-cache" in freshclam])
69dfd3de
 fi
 
28241733
 AC_ARG_ENABLE([dns-fix],
4ecce39f
 [  --enable-dns-fix	  enable workaround for broken DNS servers (as in SpeedTouch 510)],
 enable_dnsfix=$enableval, enable_dnsfix="no")
 
 if test "$enable_dnsfix" = "yes"; then
28241733
   AC_DEFINE([FRESHCLAM_DNS_FIX],1,[enable workaround for broken DNS servers])
4ecce39f
 fi
 
28241733
 AC_ARG_ENABLE([bigstack],
25c90ced
 [  --enable-bigstack	  increase thread stack size],
8a057f52
 enable_bigstack=$enableval, enable_bigstack="no")
 
 if test "$enable_bigstack" = "yes"; then
28241733
   AC_DEFINE([C_BIGSTACK],1,[Increase thread stack size.])
8a057f52
 fi
28e73e95
 
28241733
 AC_ARG_WITH([dbdir], 
25c90ced
 [  --with-dbdir=path	  path to virus database directory],
28e73e95
 db_dir="$withval", db_dir="_default_")
 
266f3967
 dnl I had problems with $pkgdatadir thus these funny checks
28e73e95
 if test "$db_dir" = "_default_"
 then
     if test "$prefix" = "NONE"
     then
 	db_dir="$ac_default_prefix/share/clamav"
     else
 	db_dir="$prefix/share/clamav"
     fi
 fi
 
28241733
 AC_DEFINE_UNQUOTED([DATADIR],"$db_dir", [Path to virus database directory.])
28e73e95
 DBDIR="$db_dir"
28241733
 AC_SUBST([DBDIR])
28e73e95
 
158b5aa3
 dnl configure config directory
28e73e95
 cfg_dir=`echo $sysconfdir | grep prefix`
0ee809e8
 
28e73e95
 if test -n "$cfg_dir"; then
0ee809e8
     if test "$prefix" = "NONE"
     then
 	cfg_dir="$ac_default_prefix/etc"
     else
 	cfg_dir="$prefix/etc"
     fi
28e73e95
 else
     cfg_dir="$sysconfdir"
 fi
 
 CFGDIR=$cfg_dir
28241733
 AC_SUBST([CFGDIR])
 AC_DEFINE_UNQUOTED([CONFDIR],"$cfg_dir",[where to look for the config file])
28e73e95
 
158b5aa3
 dnl check for in_port_t definition
c528900f
 AC_MSG_CHECKING([whether in_port_t is defined])
 AC_TRY_COMPILE([
5db1c6b0
 #include <sys/types.h>
da99018d
 #include <netinet/in.h>
c528900f
 ],
b309ed2f
 [in_port_t pt; pt = 0; return pt;],
c528900f
 [
     AC_MSG_RESULT(yes)
28241733
     AC_DEFINE([HAVE_IN_PORT_T],1,[in_port_t is defined])
c528900f
 ],
 AC_MSG_RESULT(no))
feb27080
 
8600c7eb
 dnl check for in_addr_t definition
c528900f
 AC_MSG_CHECKING([for in_addr_t definition])
 AC_TRY_COMPILE([
8600c7eb
 #include <sys/types.h>
 #include <netinet/in.h>
c528900f
 ],
b309ed2f
 [ in_addr_t pt; pt = 0; return pt; ],
c528900f
 [
     AC_MSG_RESULT(yes)
28241733
     AC_DEFINE([HAVE_IN_ADDR_T],1,[in_addr_t is defined])
c528900f
 ],
 AC_MSG_RESULT(no))
8600c7eb
 
28e73e95
 case "$target_os" in
 linux*)
28241733
     AC_DEFINE([C_LINUX],1,[target is linux])
28e73e95
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
28e73e95
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
28e73e95
 	if test "$want_clamuko" = "yes"; then
28241733
 	    AC_DEFINE([CLAMUKO],1,[enable clamuko])
28e73e95
 	fi
     fi
     ;;
cbdc099d
 kfreebsd*-gnu)
28241733
     AC_DEFINE([C_KFREEBSD_GNU],1,[target is kfreebsd-gnu])
cbdc099d
     if test "$have_pthreads" = "yes"; then
099cf13c
        THREAD_LIBS="-lpthread"
cbdc099d
        TH_SAFE="-thread-safe"
28241733
        AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
        AC_DEFINE([_REENTRANT],1,[thread safe])
cbdc099d
        if test "$want_clamuko" = "yes"; then
28241733
            AC_DEFINE([CLAMUKO],1,[enable clamuko])
cbdc099d
        fi
     fi
     ;;
28e73e95
 solaris*)
1d42f2c4
     FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lresolv"
28e73e95
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
 	CLAMD_LIBS="$CLAMD_LIBS -lresolv"
 	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lresolv"
28e73e95
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
28e73e95
     fi
28241733
     AC_DEFINE([C_SOLARIS],1,[os is solaris])
28e73e95
     ;;
a6d4c3f9
 freebsd[[45]]*)
28e73e95
     if test "$have_pthreads" = "yes"; then
fdf715fd
 	THREAD_LIBS="-pthread -lc_r"
28e73e95
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
32fc1d7b
 	if test "$want_clamuko" = "yes"; then
28241733
 	    AC_DEFINE([CLAMUKO],1,[enable clamuko])
32fc1d7b
 	fi
28e73e95
     fi
28241733
     AC_DEFINE([C_BSD],1,[os is freebsd 4 or 5])
d6d9e527
     use_gethostbyname_r="no"
     ;;
4cf912b5
 freebsd*)
d6d9e527
     if test "$have_pthreads" = "yes"; then
 	THREAD_LIBS="-lthr"
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
d6d9e527
 	if test "$want_clamuko" = "yes"; then
28241733
 	    AC_DEFINE([CLAMUKO],1,[enable clamuko])
d6d9e527
 	fi
     fi
28241733
     AC_DEFINE([C_BSD],1,[os is freebsd 6])
289615f7
     use_gethostbyname_r="no"
28e73e95
     ;;
23a4a7e3
 dragonfly*)
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-pthread"
23a4a7e3
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
23a4a7e3
 	if test "$want_clamuko" = "yes"; then
28241733
 	    AC_DEFINE([CLAMUKO],1,[enable clamuko])
23a4a7e3
 	fi
     fi
28241733
     AC_DEFINE([C_BSD],1,[os is dragonfly])
23a4a7e3
     use_gethostbyname_r="no"
     ;;
e7fe9178
 openbsd*)
ee039e40
     if test "$have_pthreads" = "yes"; then
725a2969
 	THREAD_LIBS="-pthread"
 	CLAMD_LIBS="$CLAMD_LIBS -pthread"
 	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -pthread"
ee039e40
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
ee039e40
     fi
28241733
     AC_DEFINE([C_BSD],1,[os is OpenBSD])
289615f7
     use_gethostbyname_r="no"
ee039e40
     ;;
e7fe9178
 bsdi*)
28e73e95
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-pthread"
28e73e95
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
28e73e95
     fi
28241733
     AC_DEFINE([C_BSD],1,[os is BSDI BSD/OS])
289615f7
     use_gethostbyname_r="no"
28e73e95
     ;;
 netbsd*)
ed026d36
      if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
ed026d36
      fi
28241733
     AC_DEFINE([C_BSD],1,[os is NetBSD])
289615f7
     use_gethostbyname_r="no"
28e73e95
     ;;
 bsd*)
28241733
     AC_MSG_RESULT([Unknown BSD detected. Disabling thread support.])
28e73e95
     have_pthreads="no"
28241733
     AC_DEFINE([C_BSD],1,[os is bsd flavor])
289615f7
     use_gethostbyname_r="no"
28e73e95
     ;;
 beos*)
28241733
     AC_MSG_RESULT([BeOS detected. Disabling thread support.])
28e73e95
     have_pthreads="no"
28241733
     AC_DEFINE([C_BEOS],1,[os is beos])
da5717a8
     use_gethostbyname_r="no"
28e73e95
     ;;
 darwin*)
28241733
     AC_DEFINE([C_BSD],1,[os is bsd flavor])
     AC_DEFINE([C_DARWIN],1,[os is darwin])
     AC_DEFINE([BIND_8_COMPAT],1,[enable bind8 compatibility])
28e73e95
     use_netinfo="yes"
289615f7
     use_gethostbyname_r="no"
28e73e95
     ;;
75ccac9f
 os2*)
     FRESHCLAM_LIBS="$FRESHCLAM_LIBS -lsyslog"
     CLAMD_LIBS="$CLAMD_LIBS -lsyslog"
     CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsyslog"
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
75ccac9f
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
75ccac9f
     fi
28241733
     AC_DEFINE([C_OS2],1,[os is OS/2])
75ccac9f
     ;;
28e73e95
 sco*)
     dnl njh@bandsman.sco.uk: SCO Unix port
1d42f2c4
     dnl FRESHCLAM_LIBS="-lsocket"
     dnl CLAMD_LIBS="-lsocket"
     dnl CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lsocket"
28e73e95
     ;;
 hpux*)
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
28e73e95
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
28e73e95
     fi
28241733
     AC_DEFINE([C_HPUX],1,[os is hpux])
ef38c83d
     use_gethostbyname_r="no"
28e73e95
     ;;
 aix*)
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
28e73e95
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
75ce59c1
 	AC_DEFINE([_THREAD_SAFE],1,[thread safe])
28e73e95
     fi
28241733
     AC_DEFINE([C_AIX],1,[os is aix])
28e73e95
     ;;
5d01fefa
 *-*-osf*)
     if test "$have_pthreads" = "yes"; then
 	THREAD_LIBS="-pthread"
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
 	AC_DEFINE([_POSIX_PII_SOCKET],1,[POSIX compatibility])
5d01fefa
     fi
28241733
     AC_DEFINE([C_OSF],1,[os is osf/tru64])
5d01fefa
     ;;
4233b0eb
 nto-qnx*)
      if test "$have_pthreads" = "yes"; then
28241733
        AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
        AC_DEFINE([_REENTRANT],1,[thread safe])
4233b0eb
      fi
28241733
     AC_DEFINE([C_QNX6],1,[os is QNX 6.x.x])
4233b0eb
     ;;
28e73e95
 irix*)
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
28e73e95
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
28e73e95
     fi
cc447ac8
     LIBS="$LIBS -lgen"
28241733
     AC_DEFINE([C_IRIX],1,[os is irix])
28e73e95
     ;;
feeaa333
 interix*)
28241733
     AC_DEFINE([C_INTERIX],1,[os is interix])
feeaa333
     if test "$test_clamav" = "yes"; then
 	if test ! -r /etc/passwd; then
 	   test_clamav="no"
 	fi
     fi
     if test "$have_pthreads" = "yes"; then
099cf13c
 	THREAD_LIBS="-lpthread"
feeaa333
 	TH_SAFE="-thread-safe"
28241733
 	AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
 	AC_DEFINE([_REENTRANT],1,[thread safe])
feeaa333
     fi
     ;;
8bead9a1
 gnu*)
28241733
     AC_DEFINE([C_GNU_HURD],1,[target is gnu-hurd])
8bead9a1
     if test "$have_pthreads" = "yes"; then
        THREAD_LIBS="-lpthread"
        TH_SAFE="-thread-safe"
28241733
        AC_DEFINE([CL_THREAD_SAFE],1,[thread safe])
        AC_DEFINE([_REENTRANT],1,[thread safe])
8bead9a1
     fi
     ;;
28e73e95
 *)
     ;;
 esac
 
28241733
 AC_SUBST([LIBCLAMAV_LIBS])
 AC_SUBST([CLAMD_LIBS])
 AC_SUBST([CLAMAV_MILTER_LIBS])
 AC_SUBST([FRESHCLAM_LIBS])
 AC_SUBST([TH_SAFE])
 AC_SUBST([THREAD_LIBS])
28e73e95
 
158b5aa3
 dnl --enable-milter
44ebbf5b
 if test "$have_milter" = "yes"; then
158b5aa3
     dnl libmilter checking code adapted from spamass-milter by
     dnl Tom G. Christensen <tgc@statsbiblioteket.dk>
44ebbf5b
 
158b5aa3
     dnl Check for libmilter and it's header files in the usual locations
7f3ca528
     save_LIBS="$LIBS"
     CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -lpthread"
44ebbf5b
     if test -d /usr/lib/libmilter ; then
 	CLAMAV_MILTER_LIBS="$CLAMAV_MILTER_LIBS -L/usr/lib/libmilter"
     fi
7f3ca528
     LIBS="$LIBS -lmilter $CLAMAV_MILTER_LIBS"
28241733
     AC_CHECK_LIB([milter],[mi_stop],[CLAMAV_MILTER_LIBS="-lmilter $CLAMAV_MILTER_LIBS"],[
158b5aa3
 	dnl Older sendmails require libsm or libsmutil for support functions
28241733
 	AC_SEARCH_LIBS([strlcpy], [sm smutil], [test "$ac_cv_search_strlcpy" = "none required" || CLAMAV_MILTER_XLIB="$ac_cv_search_strlcpy"])
7f3ca528
 	LIBS="$save_LIBS $CLAMAV_MILTER_LIBS $CLAMAV_MILTER_XLIB"
44ebbf5b
 	$as_unset ac_cv_lib_milter_mi_stop
28241733
 	AC_CHECK_LIB([milter],[mi_stop],[CLAMAV_MILTER_LIBS="-lmilter $CLAMAV_MILTER_XLIB $CLAMAV_MILTER_LIBS"],[
44ebbf5b
 	    AC_MSG_ERROR([Cannot find libmilter])
 	])
     ])
7f3ca528
     LIBS="$save_LIBS"
28241733
     AC_CHECK_HEADERS([libmilter/mfapi.h],[have_milter="yes"],[
44ebbf5b
 	AC_MSG_ERROR([Please install mfapi.h from the sendmail distribution])
     ])
 fi
 
28241733
 AM_CONDITIONAL([BUILD_CLAMD],[test "$have_pthreads" = "yes"])
 AM_CONDITIONAL([HAVE_MILTER],[test "$have_milter" = "yes"])
28e73e95
 
d71dd823
 if test "$have_pthreads" = "yes"
 then
600a7f2b
     save_LIBS="$LIBS"
     LIBS="$THREAD_LIBS $LIBS"
     AC_CHECK_FUNCS([sched_yield pthread_yield])
     LIBS="$save_LIBS"
28241733
     AC_DEFINE([BUILD_CLAMD], 1, "build clamd")
d71dd823
 fi
28e73e95
 
158b5aa3
 dnl Check for gethostbyname_r and number of its arguments
 dnl Code from libwww/configure.in
28241733
 AC_MSG_CHECKING([for gethostbyname_r])
158b5aa3
 if test -z "$ac_cv_gethostbyname_args"; then
 AC_TRY_COMPILE(
 [
 #include <sys/types.h>
 #include <netdb.h>
 ],[
 struct hostent *hp;
 struct hostent h;
 char *name;
 char buffer[10];
 int  h_errno;
 hp = gethostbyname_r(name, &h, buffer, 10, &h_errno);
 ], ac_cv_gethostbyname_args=5)
 fi
 if test -z "$ac_cv_gethostbyname_args"; then
 AC_TRY_COMPILE(
 [
 #include <sys/types.h>
 #include <netdb.h>
 ],[
 struct hostent h;
 struct hostent_data hdata;
 char *name;
 int  rc;
 rc = gethostbyname_r(name, &h, &hdata);
 ], ac_cv_gethostbyname_args=3)
 fi
 if test -z "$ac_cv_gethostbyname_args"; then
 AC_TRY_COMPILE(
 [
 #include <sys/types.h>
 #include <netdb.h>
 ], [
 struct hostent h;
 struct hostent *hp;
 char *name;
 char buf[10];
 int rc;
 int h_errno;
 
 rc = gethostbyname_r(name, &h, buf, 10, &hp, &h_errno);
 ], ac_cv_gethostbyname_args=6)
 fi
25c90ced
 
28241733
 AC_ARG_ENABLE([gethostbyname_r],
25c90ced
 [  --disable-gethostbyname_r	  disable support for gethostbyname_r],
289615f7
 use_gethostbyname_r=$enableval,)
25c90ced
 
289615f7
 if test "$use_gethostbyname_r" = "no"; then
28241733
     AC_MSG_RESULT([support disabled])
9684d386
 elif test -z "$ac_cv_gethostbyname_args"; then
158b5aa3
     AC_MSG_RESULT(no)
 else
     if test "$ac_cv_gethostbyname_args" = 3; then
28241733
 	AC_DEFINE([HAVE_GETHOSTBYNAME_R_3],1,[gethostbyname_r takes 3 arguments])
158b5aa3
     elif test "$ac_cv_gethostbyname_args" = 5; then
28241733
 	AC_DEFINE([HAVE_GETHOSTBYNAME_R_5],1,[gethostbyname_r takes 5 arguments])
158b5aa3
     elif test "$ac_cv_gethostbyname_args" = 6; then
28241733
 	AC_DEFINE([HAVE_GETHOSTBYNAME_R_6],1,[gethostbyname_r takes 6 arguments])
158b5aa3
     fi
     AC_MSG_RESULT([yes, and it takes $ac_cv_gethostbyname_args arguments])
 fi
28e73e95
 
72a1b240
 dnl Check for readdir_r and number of its arguments
 dnl Code from libwww/configure.in
 
28241733
 AC_MSG_CHECKING([for readdir_r])
72a1b240
 if test -z "$ac_cv_readdir_args"; then
     AC_TRY_COMPILE(
     [
 #include <sys/types.h>
 #include <dirent.h>
     ],
     [
     struct dirent dir, *dirp;
     DIR *mydir;
     dirp = readdir_r(mydir, &dir);
     ], ac_cv_readdir_args=2)
 fi
 if test -z "$ac_cv_readdir_args"; then
     AC_TRY_COMPILE(
         [
 #include <sys/types.h>
 #include <dirent.h>
     ],
     [
         struct dirent dir, *dirp;
         DIR *mydir;
         int rc;
         rc = readdir_r(mydir, &dir, &dirp);
     ], ac_cv_readdir_args=3)
 fi
 
28241733
 AC_ARG_ENABLE([readdir_r],
8a057f52
 [  --enable-readdir_r		    enable support for readdir_r],
 enable_readdir_r=$enableval, enable_readdir_r="no")
72a1b240
 
8a057f52
 if test "$enable_readdir_r" = "no"; then
9684d386
     AC_MSG_RESULT(support disabled)
 elif test -z "$ac_cv_readdir_args"; then
72a1b240
     AC_MSG_RESULT(no)
 else
     if test "$ac_cv_readdir_args" = 2; then
28241733
 	AC_DEFINE([HAVE_READDIR_R_2],1,[readdir_r takes 2 arguments])
72a1b240
     elif test "$ac_cv_readdir_args" = 3; then
28241733
 	AC_DEFINE([HAVE_READDIR_R_3],1,[readdir_r takes 3 arguments])
72a1b240
     fi
     AC_MSG_RESULT([yes, and it takes $ac_cv_readdir_args arguments])
 fi
 
28241733
 AC_MSG_CHECKING([for ctime_r])
f4b5b80e
 if test "$ac_cv_func_ctime_r" = "yes"; then
     AC_TRY_COMPILE([
 	#include <time.h>
     ],[
 	char buf[31];
 	time_t t;
 	ctime_r(&t, buf, 30);
     ],[
 	ac_cv_ctime_args=3
28241733
 	AC_DEFINE([HAVE_CTIME_R_3],1,[ctime_r takes 3 arguments])
f4b5b80e
     ],[
 	ac_cv_ctime_args=2
28241733
 	AC_DEFINE([HAVE_CTIME_R_2],1,[ctime_r takes 2 arguments])
f4b5b80e
     ])
 
     AC_MSG_RESULT([yes, and it takes $ac_cv_ctime_args arguments])
 fi
 
4c8f2d76
 dnl Determine socklen_t type. Code from lftp.
28241733
 AC_MSG_CHECKING([for socklen_t])
 AC_CACHE_VAL([ac_cv_socklen_t],
4c8f2d76
 [
     ac_cv_socklen_t=no
     AC_TRY_COMPILE([
 	#include <sys/types.h>
         #include <sys/socket.h>
     ],
     [
 	socklen_t len;
         getpeername(0,0,&len);
     ],
     [
 	ac_cv_socklen_t=yes
     ])
 ])
28241733
 AC_MSG_RESULT([$ac_cv_socklen_t])
4c8f2d76
     if test $ac_cv_socklen_t = no; then
28241733
     AC_MSG_CHECKING([for socklen_t equivalent])
     AC_CACHE_VAL([ac_cv_socklen_t_equiv],
4c8f2d76
     [
 	ac_cv_socklen_t_equiv=int
         for t in int size_t unsigned long "unsigned long"; do
 	    AC_TRY_COMPILE([
 		#include <sys/types.h>
 		#include <sys/socket.h>
 	    ],
             [
 		$t len;
 		getpeername(0,0,&len);
             ],
             [
 		ac_cv_socklen_t_equiv="$t"
 		break
             ])
 	done
     ])
28241733
     AC_MSG_RESULT([$ac_cv_socklen_t_equiv])
     AC_DEFINE_UNQUOTED([socklen_t], $ac_cv_socklen_t_equiv, [Define to "int" if <sys/socket.h> does not define.])
4c8f2d76
 fi
 
158b5aa3
 dnl Check for clamav in /etc/passwd
28e73e95
 if test "$test_clamav" = "yes"
 then
158b5aa3
     dnl parse /etc/passwd
     if test "$use_id" = "no"
28e73e95
     then
28241733
 	AC_MSG_CHECKING([for $clamav_user in /etc/passwd])
28e73e95
 	if test -r /etc/passwd; then
6d0d15d7
 	    clamavuser=`cat /etc/passwd|grep "^$clamav_user:"`
 	    clamavgroup=`cat /etc/group|grep "^$clamav_group:"`
28e73e95
 	fi
     else
28241733
 	AC_MSG_CHECKING([for $clamav_user using id])
28e73e95
 	id $clamav_user > /dev/null 2>&1
 	if test "$?" = 0 ; then
 	    clamavuser=1
 	    AC_PATH_PROG(GETENT, getent)
 	    if test -n "$GETENT" ; then
 		clamavgroup=`$GETENT group | grep "^${clamav_group}:"`
 	    else
 		clamavgroup=`cat /etc/group|grep $clamav_group`
 	    fi
 	fi
     fi
 
     if test "$use_netinfo" = "yes"
     then
9f71410a
 	if test -x /usr/bin/dscl; then
28241733
 	    AC_MSG_CHECKING([for $clamav_user using dscl])
9f71410a
 	    clamavuser=`/usr/bin/dscl . -list /Users |grep ${clamav_user}`
 	    clamavgroup=`/usr/bin/dscl . -list /Groups |grep ${clamav_group}`
 	else
28241733
 	    AC_MSG_CHECKING([for $clamav_user using netinfo])
9f71410a
 	    clamavuser=`/usr/bin/nidump passwd . |grep ${clamav_user}`
 	    clamavgroup=`/usr/bin/nidump group . |grep ${clamav_group}`
 	fi
28e73e95
     fi
 
0f8e1ad4
     if test "$use_yp" = "yes"
     then
28241733
 	AC_MSG_CHECKING([for $clamav_user using ypmatch])
0f8e1ad4
         clamavuser=`ypmatch ${clamav_user} passwd`
         clamavgroup=`ypmatch ${clamav_group} group`
     fi
 
28e73e95
     if test -z "$clamavuser" || test -z "$clamavgroup"
     then
158b5aa3
 	AC_MSG_RESULT(no)
28241733
 	AC_MSG_ERROR([User $clamav_user (and/or group $clamav_group) doesn't exist. Please read the documentation !])
28e73e95
     else
158b5aa3
 	AC_MSG_RESULT([yes, user $clamav_user and group $clamav_group])
         CLAMAVUSER="$clamav_user"
         CLAMAVGROUP="$clamav_group"
28241733
         AC_SUBST([CLAMAVUSER])
         AC_SUBST([CLAMAVGROUP])
28e73e95
     fi
 fi
 
ee039e40
 dnl check for __attribute__((packed))
a9ae2f5f
 dnl but only on compilers claiming to be gcc compatible
 dnl because for example Sun's compiler silently ignores the packed attribute.
ee039e40
 AC_MSG_CHECKING([for structure packing via __attribute__((packed))])
5348fa8d
 AC_CACHE_VAL([have_cv_attrib_packed],[
ee039e40
 	AC_TRY_COMPILE(,
a9ae2f5f
 		[#ifdef __GNUC__
 		 struct { int i __attribute__((packed)); } s;
 		 #else
 		 #error Only checking for packed attribute on gcc-like compilers
 		 #endif],
5348fa8d
 		[have_cv_attrib_packed=yes],
 		[have_cv_attrib_packed=no])
ee039e40
 	])
5348fa8d
 AC_MSG_RESULT([$have_cv_attrib_packed])
ee039e40
 
5348fa8d
 if test "$have_cv_attrib_packed" = no; then
28241733
 	AC_MSG_CHECKING([for structure packing via pragma])
5348fa8d
 	AC_CACHE_VAL([have_cv_pragma_pack],[
4a40b66c
 		AC_TRY_RUN([
 			    int main(int argc, char **argv) {
ee039e40
 #pragma pack(1)			/* has to be in column 1 ! */
 			struct { char c; long l; } s;
 			return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ],
5348fa8d
 			[have_cv_pragma_pack=yes],
 			[have_cv_pragma_pack=no])
ee039e40
 		])
5348fa8d
 	AC_MSG_RESULT([$have_cv_pragma_pack])
 	if test "$have_cv_pragma_pack" = yes; then
28241733
 		AC_DEFINE([HAVE_PRAGMA_PACK], 1, "pragma pack")
ef38c83d
 	else
28241733
 		AC_MSG_CHECKING([for structure packing via hppa/hp-ux pragma])
5348fa8d
 		AC_CACHE_VAL([have_cv_pragma_pack_hpux],[
ef38c83d
 			AC_TRY_RUN([
 			/* hppa/hp-ux wants pragma outside of function */
 #pragma pack 1 /* has to be in column 1 ! */
 			struct { char c; long l; } s;
 			    int main(int argc, char **argv) {
 			return sizeof(s)==sizeof(s.c)+sizeof(s.l) ? 0:1; } ],
5348fa8d
 			[have_cv_pragma_pack_hpux=yes],
 			[have_cv_pragma_pack_hpux=no])
ef38c83d
 		])
5348fa8d
 		AC_MSG_RESULT([$have_cv_pragma_pack_hpux])
28241733
 		AC_DEFINE([HAVE_PRAGMA_PACK_HPPA], 1, "pragma pack hppa/hp-ux style")
ef38c83d
 	fi
ee039e40
 fi
 
46c07372
 dnl check for __attribute__((aligned))
 AC_MSG_CHECKING([for type aligning via __attribute__((aligned))])
5348fa8d
 AC_CACHE_VAL([have_cv_attrib_aligned],[
46c07372
 	AC_TRY_COMPILE(,
 		[typedef int cl_aligned_int __attribute__((aligned));],
5348fa8d
 		[have_cv_attrib_aligned=yes],
 		[have_cv_attrib_aligned=no])
46c07372
 	])
5348fa8d
 AC_MSG_RESULT([$have_cv_attrib_aligned])
46c07372
 
5348fa8d
 if test "$have_cv_attrib_packed" = no -a "$have_cv_pragma_pack" = no -a "$have_cv_pragma_pack_hpux" = no; then
ee039e40
 	AC_MSG_ERROR(Need to know how to pack structures with this compiler)
 fi
46c07372
 
5348fa8d
 if test "$have_cv_attrib_packed" = yes; then
28241733
 	AC_DEFINE([HAVE_ATTRIB_PACKED], 1, [attrib packed])
46c07372
 fi
 
5348fa8d
 if test "$have_cv_attrib_aligned" = yes; then
28241733
 	AC_DEFINE([HAVE_ATTRIB_ALIGNED], 1, [attrib aligned])
ee039e40
 fi
 
158b5aa3
 dnl Check if <sys/select.h> needs to be included for fd_set
b7f57a87
 AC_MSG_CHECKING([for fd_set])
33e22cc0
 AC_HEADER_EGREP([fd_mask], [sys/select.h], [have_fd_set=yes])
5b13eab8
 if test "$have_fd_set" = yes; then
33e22cc0
 	AC_DEFINE([HAVE_SYS_SELECT_H], 1, "have <sys/select.h>")
 	AC_MSG_RESULT([yes, found in sys/select.h])
b7f57a87
 else
33e22cc0
 	AC_TRY_COMPILE([#include <sys/time.h>
 			#include <sys/types.h>
 			#ifdef HAVE_UNISTD_H
 			#include <unistd.h>
 			#endif],
 		[fd_set readMask, writeMask;], have_fd_set=yes, have_fd_set=no)
5b13eab8
 	if test "$have_fd_set" = yes; then
33e22cc0
 		AC_MSG_RESULT([yes, found in sys/types.h])
 	else
 		AC_DEFINE([NO_FD_SET], 1, "no fd_set")
 		AC_MSG_RESULT(no)
 	fi
b7f57a87
 fi
 
28241733
 AC_MSG_CHECKING([default FD_SETSIZE value])
c0d52615
 AC_TRY_RUN([
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/time.h>
e1bb6905
 #ifdef HAVE_SYS_SELECT_H
c0d52615
 #include <sys/select.h>
e1bb6905
 #endif
 #ifdef HAVE_SYS_TYPES_H
c0d52615
 #include <sys/types.h>
e1bb6905
 #endif
4c56bffa
 #include <errno.h>
 int main(void) {
c0d52615
         FILE *fp = fopen("conftestval", "w");
4c56bffa
 	if(fp) {
 		if(fprintf (fp, "%d\n", FD_SETSIZE) < 1)  {
 			perror("fprintf failed");
 			return errno;
 		}
 	} else {
 		perror("fopen failed");
 		return errno;
 	}
e1bb6905
         return 0;
c0d52615
 }
 ],
 DEFAULT_FD_SETSIZE=`cat conftestval`,
 DEFAULT_FD_SETSIZE=256,
 DEFAULT_FD_SETSIZE=256)
28241733
 AC_MSG_RESULT([$DEFAULT_FD_SETSIZE])
 AC_DEFINE_UNQUOTED([DEFAULT_FD_SETSIZE], $DEFAULT_FD_SETSIZE, "default FD_SETSIZE value")
c0d52615
 
35eb6354
 dnl Check signed right shift implementation
28241733
 AC_MSG_CHECKING([whether signed right shift is sign extended])
35eb6354
 AC_TRY_RUN([int main(void){int a=-1;int b=a>>1;return(a!=b);}],
     [have_signed_rightshift_extended=yes],
     [have_signed_rightshift_extended=no],
     [have_signed_rightshift_extended=no])
 if test $have_signed_rightshift_extended = yes; then
28241733
     AC_DEFINE([HAVE_SAR], 1, [Define signed right shift implementation])
35eb6354
 fi
28241733
 AC_MSG_RESULT([$have_signed_rightshift_extended]);
35eb6354
 
725a2969
 AC_C_FDPASSING
 
b105842c
 AC_DEFINE_UNQUOTED([VERSION_SUFFIX],"$VERSION_SUFFIX",[Version suffix for package])
 
8db0a346
 AC_ARG_ENABLE(clamdtop,
 	      AC_HELP_STRING([--enable-clamdtop],
 			     [Enable 'clamdtop' tool @<:@default=auto@:>@]),
 [enable_clamdtop=$enableval], [enable_clamdtop="auto"])
 
 if test "$enable_clamdtop" != "no"; then
 
 AC_LIB_FIND([ncurses], [ncurses/ncurses.h],
 	    AC_LANG_PROGRAM([#include <ncurses/ncurses.h>],
 			    [initscr(); KEY_RESIZE;]),
 	    [CURSES_CPPFLAGS="$INCNCURSES"; CURSES_LIBS="$LTLIBNCURSES";
 	     CURSES_INCLUDE="<ncurses/ncurses.h>"],
 	    [])
 
 if test "X$HAVE_LIBNCURSES" != "Xyes"; then
     HAVE_LIBNCURSES=
     AC_LIB_FIND([ncurses], [ncurses.h],
 	    AC_LANG_PROGRAM([#include <ncurses.h>],
 			    [initscr(); KEY_RESIZE;]),
 	    [CURSES_CPPFLAGS="$INCNCURSES"; CURSES_LIBS="$LTLIBNCURSES";
 	     CURSES_INCLUDE="<ncurses.h>"],
 	    [])
 fi
 
 if test "X$HAVE_LIBNCURSES" != "Xyes"; then
     AC_LIB_FIND([pdcurses],[curses.h],
 			    AC_LANG_PROGRAM([#include <curses.h>],
 					    [initscr(); KEY_RESIZE;]),
 			    [CURSES_CPPFLAGS="$INCPDCURSES";
 			     CURSES_LIBS="$LTLIBPDCURSES";
 			     CURSES_INCLUDE="<curses.h>"],
 			    [AC_MSG_WARN([****** not building clamdtop: ncurses not found])])
 fi
 
 if test "x$CURSES_LIBS" = "x" -a "$enable_clamdtop" = "yes"; then
     AC_MSG_ERROR([
 
 ERROR!  Clamdtop was configured, but not found.  You need to install libncurses5-dev.
 ])
 fi
 
 fi
 
 AC_DEFINE_UNQUOTED([CURSES_INCLUDE], $CURSES_INCLUDE, [curses header location])
 AC_SUBST([CURSES_CPPFLAGS])
 AC_SUBST([CURSES_LIBS])
 AM_CONDITIONAL([HAVE_CURSES],
 	       [test "X$HAVE_LIBNCURSES" = "Xyes" || test "X$HAVE_LIBPDCURSES" = "Xyes"])
 
2c7d5adc
 AC_ARG_ENABLE([llvm],AC_HELP_STRING([--enable-llvm],
 				    [Enable 'llvm' JIT/verifier support @<:@default=auto@:>@]),
 				    [enable_llvm=$enableval], [enable_llvm="auto"])
 
 if test "$enable_llvm" != "no"; then
     dnl Try to configure subdir, optionally
     AC_CONFIG_SUBDIRS_OPTIONAL([libclamav/c++])
 fi
 
28e73e95
 AC_OUTPUT([
 clamscan/Makefile
 database/Makefile
 docs/Makefile
 clamd/Makefile
 clamdscan/Makefile
 clamav-milter/Makefile
 freshclam/Makefile
 sigtool/Makefile
dc4f2ce8
 clamconf/Makefile
28e73e95
 etc/Makefile
ace28304
 test/Makefile
fe473bcb
 unit_tests/Makefile
8db0a346
 clamdtop/Makefile
997a1efe
 clambc/Makefile
28e73e95
 Makefile
9f51cb51
 clamav-config
 libclamav.pc
a39ae468
 docs/man/clamav-milter.8
 docs/man/clamconf.1
8600c7eb
 docs/man/clamd.8
 docs/man/clamd.conf.5
a39ae468
 docs/man/clamdscan.1
 docs/man/clamscan.1
8600c7eb
 docs/man/freshclam.1
 docs/man/freshclam.conf.5
a39ae468
 docs/man/sigtool.1
8db0a346
 docs/man/clamdtop.1
28e73e95
 ])
c528900f
 
2c7d5adc
 AM_CONDITIONAL([ENABLE_LLVM],
 	       [test "$subdirfailed" != "yes" && test "$enable_llvm" != "noi"])
 no_recursion="yes";
 AC_OUTPUT([libclamav/Makefile])
 
b105842c
 # Yep, downgrading the compiler avoids the bug too:
 # 4.0.x, and 4.1.0 are the known buggy versions
 # 3.4 doesn't have the bug
 if test "x$gcc_check" != "xyes"; then
 	AC_MSG_WARN([
 ****** Optimizations disabled to avoid compiler bugs
 ****** The resulting binaries will be slow!
 ****** It is recommended to either upgrade or downgrade your compiler
 ])
 fi
 
 if test "x$cross_compiling" != "xno" || test "x$gcc_check" != "xyes" || test "x$zlib_check" = "xno" ; then
c528900f
 AC_MSG_WARN([
 ****** WARNING:
 ****** You are either cross compiling to a different host or
 ****** you have manually disabled important configure checks.
 ****** Please be aware that this build may be badly broken.
 ****** DO NOT REPORT BUGS BASED ON THIS BUILD !!!
 ])
 fi