
dnl Initialize automake
AC_INIT(src/aide.c)

AM_INIT_AUTOMAKE(aide, 0.6)
dnl The name of the configure h-file.
AM_CONFIG_HEADER(config.h)

# We want an absolute path to the source-dir.
case "$srcdir" in
    /*)
    ;;
    *)
        oldsrcdir="$srcdir"
        srcdir="`cd \"$srcdir\";pwd`"
    ;;
esac



CPPFLAGS="$CPPFLAGS -I$srcdir -I$srcdir/src"



dnl Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_PROG_YACC
if test "x${YACC}" != "xbison -y"; then
        echo "AIDE requires GNU bison"
        exit 5
fi

AM_PROG_LEX
if test "x${LEX}" != "xflex"; then
        echo "AIDE requires GNU flex"
        exit 5
fi

AM_PROG_CC_STDC

AM_SANITY_CHECK
AM_MAINTAINER_MODE

dnl This macro is new in autoconf-2.13
AC_SEARCH_LIBS(syslog, bsd socket inet, AC_DEFINE(HAVE_SYSLOG))

AIDE_CHECK_ENDIAN

AIDE_CHECK_TYPEDEF(byte, HAVE_BYTE_TYPEDEF)
AIDE_CHECK_TYPEDEF(ushort, HAVE_USHORT_TYPEDEF)
AIDE_CHECK_TYPEDEF(ulong, HAVE_ULONG_TYPEDEF)
AIDE_CHECK_TYPEDEF(u16, HAVE_U16_TYPEDEF)
AIDE_CHECK_TYPEDEF(u32, HAVE_U32_TYPEDEF)

AC_CHECK_SIZEOF(unsigned short, 2)
AC_CHECK_SIZEOF(unsigned int, 4)
AC_CHECK_SIZEOF(unsigned long, 4)

AC_HEADER_STDC
AC_CHECK_FUNCS(readdir readdir_r mmap)

AC_CHECK_HEADERS(syslog.h)
AC_ARG_WITH(zlib,
  [--with-zlib    use zlib compression],,
  [with_zlib=yes])


AC_ARG_WITH(config_file,
  [--with-config_file=config_file   use config_file as the default
  config file],
  AC_DEFINE_UNQUOTED(CONFIG_FILE,"$withval")
  config_file=$withval
,
  if test "x$prefix" != xNONE; then
    AC_DEFINE_UNQUOTED(CONFIG_FILE,"$prefix/etc/aide.conf") 
    config_file="$prefix/etc/aide.conf"
  else
    AC_DEFINE_UNQUOTED(CONFIG_FILE,"$ac_default_prefix/etc/aide.conf") 
    config_file="$ac_default_prefix/etc/aide.conf"
  fi

)

if test "x$prefix" != xNONE; then
     AC_DEFINE_UNQUOTED(DEFAULT_DB,"$prefix/etc/aide.db")
     AC_DEFINE_UNQUOTED(DEFAULT_DB_OUT,"$prefix/etc/aide.db.new")
else
     AC_DEFINE_UNQUOTED(DEFAULT_DB,"$ac_default_prefix/etc/aide.db")
     AC_DEFINE_UNQUOTED(DEFAULT_DB_OUT,"$ac_default_prefix/etc/aide.db.new")
fi


if test x$with_zlib = xyes; then
  AC_CHECK_HEADERS(zlib.h,, [with_zlib=no])
fi

AC_ARG_WITH(gnu-regexp,
  [--with-gnu-regexp  use the bundled GNU regexp(use only if necessary)],
  AC_DEFINE(REGEX, 1)
,
  AC_CHECK_FUNCS(regexec regcomp,,
	AC_DEFINE(REGEX,1))
)


AC_ARG_WITH(mhash,
  [--with-mhash   use mhash hash library instead of the builtin hash algorithms],
  AC_DEFINE(WITH_MHASH)
  AC_CHECK_LIB(mhash,mhash_get_block_size,,
	exit 1)
  CRYPTLIB="-lmhash crypt/libcipher.a"
  compoptionstring="${compoptionstring}WITH_MHASH\\n"
,	
  CRYPTLIB="crypt/libcipher.a"
  [with_mhash=no])

AC_SUBST(CRYPTLIB)

compoptionstring="${compoptionstring}CONFIG_FILE = \\\"${config_file}\\\"\\n"

AC_DEFINE_UNQUOTED(AIDECOMPILEOPTIONS, "${compoptionstring}")

AC_OUTPUT(Makefile src/Makefile src/crypt/Makefile doc/Makefile
doc/aide.conf aide.spec)

