dnl $Id: configure.in,v 1.2 1997/11/24 21:32:14 grubba Exp $
dnl (C) 1997 Francesco Chemolli <kinkie@comedia.it>

AC_INIT(msqlmod.c)
AC_CONFIG_HEADER(msql_config.h)

AC_ARG_WITH(msql,    [  --with(out)-msql      mSQL Database engine support ],[]
,[with_msql=yes])

echo "Configuring msql module, (C) 1996,1997 Francesco Chemolli <kinkie@comedia.it>"

sinclude(../module_configure.in)

dnl set up "reasonable" search paths
pike_msql_reasonable_prefixes="/usr/local /usr /opt"
pike_msql_reasonable_directories="Minerva Hughes minerva hughes msql Msql msql2 Msql2 /"
pike_msql_extra_include_directories="$HOME/include"
pike_msql_extra_lib_directories="$HOME/lib"

for a in $pike_msql_reasonable_prefixes
do
	for b in $pike_msql_reasonable_directories
	do
		pike_msql_reasonable_include_searchpath="$pike_msql_reasonable_include_searchpath $a/$b/include"
		pike_msql_reasonable_lib_searchpath="$pike_msql_reasonable_lib_searchpath $a/$b/lib"
	done
done
pike_msql_reasonable_include_searchpath="$pike_msql_reasonable_include_searchpath $pike_msql_extra_include_directories"
pike_msql_reasonable_lib_searchpath="$pike_msql_reasonable_lib_searchpath $pike_msql_extra_lib_directories"

dnl let's start the actual tests
if test x$with_msql = xyes; then
	OLD_CPPFLAGS=$CPPFLAGS
	OLD_LIBS=$LIBS
	OLD_LDFLAGS=$LDFLAGS

	AC_MSG_CHECKING(for location of mSQL include files)
	AC_CACHE_VAL(pike_cv_msql_include_dir, [
		for pike_cv_msql_include_dir in $pike_msql_reasonable_include_searchpath no
		do
			if test -f $pike_cv_msql_include_dir/msql.h; then
				break
			fi
		done ])
	if test x$pike_cv_msql_include_dir != xno; then
		AC_MSG_RESULT(found.)
	else
		AC_MSG_RESULT(not found.)
	fi
dnl	AC_MSG_RESULT($pike_cv_msql_include_dir)

	if test x$pike_cv_msql_include_dir != xno; then
		CPPFLAGS="$CPPFLAGS -I$pike_cv_msql_include_dir"
	fi

	AC_CHECK_HEADERS(msql.h)
	
	if test "$ac_cv_header_msql_h" != "no"; then
		AC_MSG_CHECKING(for location of mSQL library)
		AC_CACHE_VAL(pike_cv_msql_lib_dir, [ 
			for pike_cv_msql_lib_dir in $pike_msql_reasonable_lib_searchpath no
			do
				if test -f $pike_cv_msql_lib_dir/libmsql.a; then
					break
				fi
			done
		] )
		if test x$pike_cv_msql_lib_dir != xno; then
			AC_MSG_RESULT(found.)
		else
			AC_MSG_RESULT(not found.)
		fi
dnl		AC_MSG_RESULT($pike_cv_msql_lib_dir)
	fi

	if test "$pike_cv_msql_lib_dir" != "no" ; then
		LDFLAGS="$LDFLAGS -L$pike_cv_msql_lib_dir"
		# On some OS's (Solaris 2) these are requiered
		AC_CHECK_LIB(socket, socket, [], [])
		AC_CHECK_LIB(nsl, gethostbyname, [], [])

		AC_CHECK_LIB(msql, msqlClose)
		if test "$ac_cv_lib_msql_msqlClose" != "no"; then
			pike_cv_found_msql="yes"
			MSQL_SUPPORTED="yes"
		fi
	fi

	if test x$pike_cv_found_msql = xyes; then
		AC_CHECK_FUNCS(msqlListIndex)
		if test "$ac_cv_func_msqlListIndex" = "yes"; then
			echo "We're supporting mSQL version 2.0, good..."
		else
			echo "We're supporting mSQL version 1.0"
		fi
	fi
fi

if test "x$pike_cv_found_msql" != "xyes"; then
	CPPFLAGS=$OLD_CPPFLAGS
	LDFLAGS=$OLD_LDFLAGS
	LIBS=$OLD_LIBS
fi

AC_SUBST(LIBS)
AC_SUBST(MSQL_SUPPORTED)

AC_OUTPUT(./Makefile)
