dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/extras/mdb-dump.c)
AM_INIT_AUTOMAKE(mdbtools,0.5)

AC_PROG_CC(gcc)
dnl Checks for programs.
AC_PROG_MAKE_SET
AC_PROG_LIBTOOL
AM_PROG_LEX
AC_PROG_YACC

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

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

dnl no optional stuff by default
OPTDIRS=""

dnl ---------------------------------------------------------------------
dnl Compile time options
dnl ---------------------------------------------------------------------

sql=true
AC_MSG_CHECKING( Are we using flex )
if test "x$LEX" = "xflex"; then
LFLAGS="$LFLAGS -i"
AC_MSG_RESULT( yes );
else
AC_MSG_RESULT( no - SQL engine disable);
sql=false
fi

if test "x$YACC" = "x"; then
sql=false
fi

if test "x$sql" = "xtrue"; then
	CFLAGS="$CFLAGS -DSQL"
	OPTDIRS="$OPTDIRS sql"
fi

AM_CONDITIONAL(SQL, test x$sql = xtrue)
AC_SUBST(SQL)
AC_SUBST(LFLAGS)

dnl check for iODBC

AC_ARG_WITH(iodbc,
[  --with-iodbc=/path/to/iodbc build odbc driver against iODBC])
if test "$with_iodbc"; then
     CFLAGS="$CFLAGS -DIODBC";
     ODBC_INC=$with_iodbc/include;
     odbc=true
     OPTDIRS="$OPTDIRS odbc"
     if test "x$sql" != "xtrue" ; then
          echo
          echo ODBC requires flex and bison for the SQL engine
          exit 1
     fi
fi

dnl check for unixODBC
AC_ARG_WITH(unixodbc,
[  --with-unixodbc=/path/to/unixodbc build odbc driver against unixODBC])
if test "$with_unixodbc"; then
     CFLAGS="$CFLAGS -DUNIXODBC"
     ODBC_INC=$with_unixodbc/include
     odbc=true
     OPTDIRS="$OPTDIRS odbc"
     if test "x$sql" != "xtrue" ; then
          echo
          echo ODBC requires flex and bison for the SQL engine
          exit 1
     fi
fi
AM_CONDITIONAL(HAVE_ODBC, test x$odbc = xtrue)
AC_SUBST(HAVE_ODBC)
AC_SUBST(ODBC_INC)

dnl check for glib/gtk/gnome
AM_PATH_GLIB_2_0(2.0.0)

if test "$no_glib" == yes; then
	echo
	echo "glib 2.0 is required by MDB Tools."
	echo "It can be downloaded at www.gtk.org."
	echo
	exit 1
fi

PKG_CHECK_MODULES(GNOME,libglade-2.0 libgnomeui-2.0, HAVE_GNOME=true, HAVE_GNOME=false)

if test "x$HAVE_GNOME" = "xtrue"; then
	AC_SUBST(GNOME_CFLAGS)
	AC_SUBST(GNOME_LIBS)
	OPTDIRS="$OPTDIRS gmdb2"
fi

AC_SUBST([OPTDIRS])
AC_CONFIG_FILES([src/Makefile])

dnl Checks for library functions.

OLDLDFLAGS=$LDFLAGS

AC_CHECK_LIB(ncurses,initscr,[
	READLINE_LIBS="$READLINE_LIBS -lncurses"
	LDFLAGS="$LDFLAGS -lncurses"
	],[])

AC_CHECK_LIB(readline, add_history, [
	READLINE_LIBS="$READLINE_LIBS -lreadline"
	AC_DEFINE(HAVE_READLINE,1,[ ]) 
	],[])

LDFLAGS=$OLDLDFLAGS

AC_SUBST(READLINE_LIBS)

AC_OUTPUT(src/util/Makefile src/extras/Makefile Makefile include/Makefile src/Makefile src/libmdb/Makefile include/Makefile src/sql/Makefile src/odbc/Makefile src/gmdb2/Makefile doc/Makefile)