#MIN_CONFIG(3.1)

AM_INIT_AUTOMAKE(krecipes, 0.8)

#KDE_USE_TQT(3.1)

AC_C_BIGENDIAN
AC_CHECK_KDEMAXPATHLEN

AC_ARG_WITH(sqlite, AC_HELP_STRING([--without-sqlite], [Don't compile SQLite backend support]), , with_sqlite=yes)
AC_ARG_WITH(mysql, AC_HELP_STRING([--without-mysql], [Don't compile MySQL backend support]), , with_mysql=yes)
AC_ARG_WITH(postgresql, AC_HELP_STRING([--without-postgresql], [Don't compile PostgreSQL backend support]), , with_postgresql=yes)

dnl ----- Check if we should enable MySQL ------

if test "x$with_mysql" != "xno"; then
  AC_DEFINE(HAVE_MYSQL, 1, [have MySQL])
  have_mysql="true"
else
  AC_DEFINE(HAVE_MYSQL, 0, [have MySQL])
  have_mysql="false"
fi


dnl ----- Check if we should enable PostgreSQL ------

if test "x$with_postgresql" != "xno"; then
  AC_DEFINE(HAVE_POSTGRESQL, 1, [have PostgreSQL])
  have_postgresql="true"
else
  AC_DEFINE(HAVE_POSTGRESQL, 0, [have PostgreSQL])
  have_postgresql="false"
fi


dnl ------ Check for the SQLite headers -----

AC_DEFUN([AC_HAVE_SQLITE],
[
        AC_DEFINE(HAVE_SQLITE, 1, [have SQLite])
        have_sqlite=true
	SQLITE_LIB="-lsqlite"
	AC_SUBST(SQLITE_LIB)
])

AC_DEFUN([AC_NO_SQLITE],
[
        AC_DEFINE(HAVE_SQLITE, 0, [have SQLite])
        have_sqlite=false
])

AC_DEFUN([AC_HAVE_SQLITE3],
[
        AC_DEFINE(HAVE_SQLITE3, 1, [have SQLite3])
        have_sqlite3=true
	AC_NO_SQLITE
	SQLITE_LIB="-lsqlite3"
	AC_SUBST(SQLITE_LIB)
])

AC_DEFUN([AC_NO_SQLITE3],
[
        AC_DEFINE(HAVE_SQLITE3, 0, [have SQLite3])
        have_sqlite3=false
])

if test "x$with_sqlite" != "xno"; then
  KDE_CHECK_HEADER(sqlite3.h,
           AC_HAVE_SQLITE3,
           AC_NO_SQLITE3
  )
 
  if test "x$have_sqlite3" = "xfalse"; then
  KDE_CHECK_HEADER(sqlite.h,
           AC_HAVE_SQLITE,
           AC_NO_SQLITE
  )
  fi

else
  AC_NO_SQLITE
  AC_NO_SQLITE3
fi

dnl ----------- Should I link or should I not link? ---------
AM_CONDITIONAL(link_lib_MYSQL, test x$have_mysql = xtrue)
AM_CONDITIONAL(link_lib_POSTGRESQL, test x$have_postgresql = xtrue)
AM_CONDITIONAL(link_lib_SQLITE, test x$have_sqlite = xtrue || test x$have_sqlite3 = xtrue)

dnl ----------- Should Krecipes be built at all? ------------
if test "x$have_mysql" = "xfalse" && test "x$have_postgresql" = "xfalse"; then
        if test "x$have_sqlite" = "xfalse" && test "x$have_sqlite3" = "xfalse"; then
        DO_NOT_COMPILE="$DO_NOT_COMPILE krecipes"
        will_not_build_krecipes=true
        fi
fi
