## File:      configure.in
## Author(s): kifer
## Contact:   xsb-contact@cs.sunysb.edu
## 
## Copyright (C) The Research Foundation of SUNY, 2003
## 
## XSB is free software; you can redistribute it and/or modify it under the
## terms of the GNU Library General Public License as published by the Free
## Software Foundation; either version 2 of the License, or (at your option)
## any later version.
## 
## XSB is distributed in the hope that it will be useful, but WITHOUT ANY
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
## more details.
## 
## You should have received a copy of the GNU Library General Public License
## along with XSB; if not, write to the Free Software Foundation,
## Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
##
## $Id: configure.in,v 1.1 2003/09/29 09:40:02 kifer Exp $
## 
##

dnl  Autoconf script for XSB
dnl  To rebuild the `configure' script from this, execute the command
dnl	autoconf
dnl  in the directory containing this script.
dnl
dnl

AC_PREREQ(2.12)dnl

AC_INIT(mysql_driver_config.P)

SHELL=/bin/sh

AC_ARG_WITH(mysql,
[  --with-mysql-libdir=DIR	   the directory where the MySQL library lives]
[  --with-mysql-incdir=DIR	   the directory of MySQL include files]
   )



build_dir="`pwd`"
# strip the last three directories and possibly trailing slashes
topdir=`echo "${build_dir}" | sed 's,/[[^/]][[^/]]*/*/[[^/]][[^/]]*/*/[[^/]][[^/]]*/*$,,'`


# Tell where the autoconf scripts are
AC_CONFIG_AUX_DIR($topdir/build)

dnl Check configuration for a Unix variant
if test -z "$with_config"; then
echo '
- You did not tell me what kind of host system you want to configure.
- I will attempt to guess the kind of system this is.
' 1>&6
    AC_CANONICAL_HOST
    canonical=$host
    configuration=$host_alias
fi


# make sure new files are readable 
umask 022

/bin/rm config.cache

with_mysql=
mysql_error=

if test -z "$with_mysql_libdir" ; then
   libdir="/usr/lib/mysql"
else
   libdir=$with_mysql_libdir
fi
if test -z "$with_mysql_incdir" ; then
   incdir="/usr/include/mysql"
else
   incdir=$with_mysql_incdir
fi

# check if libmysqlclient.so can be found
# If the MySQL library is missing, set mysql_error
# If libmysqlclient.so is not in a standard place, we must use --with-mysql-libdir
if test -n "$libdir" ; then
   LDFLAGS="-L${libdir} ${LDFLAGS}"
fi

AC_CHECK_LIB(mysqlclient, , mysql_error=yes)
# Here we provide additional directories to check headers in
# AC_CHECK_HEADERS uses CPPFLAGS to find the include path.
#
# If any of the headers is not in a standard place, use --with-mysql-incdir
if test -n "${incdir}"; then
   CPPFLAGS=" -I${incdir} ${CPPFLAGS}"
   CFLAGS="-I${incdir} ${CPFLAGS}"
fi

AC_CHECK_HEADERS(mysql.h mysql_com.h, with_mysql=yes, mysql_error=yes)

if test "$mysql_error" = "yes"; then
echo ""
AC_MSG_WARN([ ****Your system is missing mysql.h or mysql_com.h, which are required for MySQL support
****MySQL driver will be disabled])
echo ""

support=no
else
support=yes
fi


AC_SUBST(support)
AC_SUBST(libdir)
AC_SUBST(CFLAGS)
AC_SUBST(LDFLAGS)


(
echo ""
echo "  MySQL support:                                  $support"
echo "  MySQL library directory:                        $libdir"
echo "  MySQL header directory:                         $incdir"
echo "  MySQL C Flags:                                  $CFLAGS"
echo "  MySQL Loader Flags:                             $LDFLAGS"
echo ""
) | tee Installation_summary

AC_OUTPUT([mysql_init.P:mysql_init.in])
