dnl Process this file with autoconf to produce a configure script.
AC_INIT(mkzonedb.c)
AC_CONFIG_HEADER(config.h)
AC_PREFIX_DEFAULT(/usr)

CONFIG_MANDIR=`eval echo ${CONFIG_MANDIR:-"/usr/man"}`
CONFIG_SBINDIR=`eval echo ${CONFIG_SBINDIR:-"/sbin"}`

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_CHECK_PROGS(BZIP2, bzip2, bzip2_not_found_or_installed)
if test "$BZIP2" = "bzip2_not_found_or_installed" ; then
	AC_MSG_ERROR(bzip2 not found please install it.)
fi

if test -e ../cdb/i4l_cdb.c  ; then
    AC_DEFINE(USE_CDB)
    CDBEXTRALIBS="../cdb/i4l_cdb.a"
    DBEXT=".cdb"
    RDBEXT=".cdb"
    AC_MSG_RESULT(Using 'cdb' as database)
else
dnl Checks for libraries.
dnl Berkeley DB appends RDBEXT
CDBEXTRALIBS=""
AC_CHECK_LIB(gdbm, gdbm_open, DBMLIB=-lgdbm;DBEXT=".gdbm";RDBEXT=".gdbm"; AC_DEFINE(HAVE_LIBGDBM),
	AC_CHECK_LIB(dbm, dbm_open, DBMLIB=-ldbm;RDBEXT=".db"; AC_DEFINE(HAVE_LIBDBM),
		AC_CHECK_LIB(db, dbm_open, DBMLIB=-ldb;RDBEXT=".db"; AC_DEFINE(HAVE_LIBDB),
			AC_MSG_ERROR("No db found"))))
fi
AC_DEFINE_UNQUOTED(RDBEXT,"$RDBEXT")

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T

dnl Only 1,2,4 will work by now
AC_CHECK_SIZEOF(char,1)
AC_CHECK_SIZEOF(short,2)
AC_CHECK_SIZEOF(long,4)
AC_CHECK_SIZEOF(int,4)
AC_C_BIGENDIAN
if test $ac_cv_c_bigendian = yes; then
	WORDS_BIGENDIAN=yes
fi

dnl Checks for library functions.
AC_CHECK_FUNCS(strdup strtoul)

AC_SUBST(DBMLIB)
AC_SUBST(DBEXT)
AC_SUBST(RDBEXT)
AC_SUBST(CDBEXTRALIBS)
AC_SUBST(CC)
AC_SUBST(INSTALL)
AC_SUBST(CONFIG_SBINDIR)
AC_SUBST(CONFIG_MANDIR)
AC_SUBST(WORDS_BIGENDIAN)
AC_OUTPUT(Makefile)
