dnl Process this file with autoconf to produce a configure script.

m4_ifdef([HAS_TOP],[m4_ignore],[   
AC_INIT(install-sh)
AC_PREREQ([2.50])
AC_CONFIG_HEADER(config.h)
])

PKG_PROSQLITE="packages/prosqlite"
AC_SUBST(PKG_PROSQLITE)

AC_SUBST(PROSQLITE_TARGETS)
AC_SUBST(PROSQLITE_PLTARGETS)
AC_SUBST(PROSQLITE_CPPFLAGS)
AC_SUBST(PROSQLITE_LDFLAGS)
AC_SUBST(PROSQLITE_LIBS)

m4_ifdef([HAS_TOP],[m4_ignore],[   
m4_include([../ac_swi_c.m4])
])

yap_cv_prosqlite=yes

AC_ARG_WITH(prosqlite,
	[ --with-prosqlite(=location)              interface to sqlite],
	if test "$withval" = yes; then
	    PROSQLITE_DIR=/usr
	elif test "$withval" = no; then
	    yap_cv_prosqlite=no
	else
	    PROSQLITE_DIR="$withval"
	fi,
	[PROSQLITE_DIR=/usr ])

havelib=no

if test $yap_cv_prosqlite = yes; then
    OCPPFLAGS="${CPPFLAGS}"
    OCPPFLAGS="${CPPFLAGS}"
    OCIFLAGS="${CIFLAGS}"
    OLDFLAGS="${LDFLAGS}"

  if test ! -z "$PROSQLITE_DIR"; then
    PROSQLITE_CPPFLAGS="-I${PROSQLITE_DIR}/include"
    PROSQLITE_LDFLAGS="-L${PROSQLITE_DIR}/lib"
    CPPFLAGS="-I${PROSQLITE_DIR}/include ${CPPFLAGS}"
    CIFLAGS="-I${PROSQLITE_DIR}/include ${CIFLAGS}"
    LDFLAGS="-L${PROSQLITE_DIR}/lib ${LDFLAGS}"
  fi

  AC_CHECK_LIB(sqlite3, sqlite3_open,
                       PROSQLITE_LIBS="-lsqlite3 $LIBS"
                       havelib=yes)

  AC_CHECK_HEADERS(sqlite3.h, [], [])

    CPPFLAGS="${OCPPFLAGS}"
    CPPFLAGS="${OCPPFLAGS}"
    CIFLAGS="${OCIFLAGS}"
    LDFLAGS="${OLDFLAGS}"

fi

if test "$yap_cv_prosqlite" != no &&
   test	"$havelib" = yes &&
   test	"$ac_cv_header_sqlite3_h" = yes; then
  PROSQLITE_TARGETS="prosqlite.$SO"
  PROSQLITE_PLTARGETS="prolog/prosqlite.pl"
else
  echo "ERROR:   Cannot find sqlite3 library and/or the header sqlite3.h"
  echo "WARNING: PROSQLITE interface will not be built"
  PROSQLITE_TARGETS=""
fi

m4_ifdef([HAS_TOP],[m4_ignore],[   
AC_OUTPUT(Makefile)
])