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

AC_INIT(install-sh)
AC_PREREQ([2.50])
AC_CONFIG_HEADER(config.h)

AC_SUBST(TARGETS)
AC_SUBST(PLTARGETS)
AC_SUBST(ODBC_CFLAGS)
AC_SUBST(ODBC_LDFLAGS)

m4_include([../ac_swi_c.m4])

AC_ARG_WITH(odbc,[  --with-odbc=<dir>	  Location of ODBC include/lib],
	[case $withval in
		no|yes)	echo 'Specify dir for XPM please';
			exit 1 ;;
		*)	ODBC_DIR=${withval}
	esac])

if test ! -z "$ODBC_DIR"; then
  ODBC_CFLAGS="-I${ODBC_DIR}/include"
  ODBC_LDFLAGS="-L${ODBC_DIR}/lib"
  CFLAGS="-I${ODBC_DIR}/include ${CFLAGS}"
  CPPFLAGS="-I${ODBC_DIR}/include ${CPPFLAGS}"
  CIFLAGS="-I${ODBC_DIR}/include ${CIFLAGS}"
  LDFLAGS="-L${ODBC_DIR}/lib ${LDFLAGS}"
fi

havelib=no
case "$PLARCH" in
    *-win32|*-win64)
        AC_CHECK_LIB(odbc32, main,
                     LIBS="-lodbc32 $LIBS"
                     havelib=yes)
        ;;
    *)
        if test $havelib = no; then
          AC_CHECK_LIB(odbc, SQLAllocEnv,
                       LIBS="-lodbc $LIBS"
                       havelib=yes)
          if test $havelib = no; then
            AC_CHECK_LIB(iodbc, SQLAllocEnv,
                         LIBS="-liodbc $LIBS"
                         havelib=yes)
          fi
        fi
esac

AC_C_BIGENDIAN

AC_CHECK_HEADERS(malloc.h time.h)
AC_CHECK_HEADERS(sql.h, [], [],
[[
#ifdef __WINDOWS__
#include <windef.h>
#endif
]])
AC_CHECK_FUNCS(localtime mktime gmtime timegm)
AC_CHECK_TYPES([long long])
AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(SQLWCHAR, 2,
[[
#ifdef __WINDOWS__
#include <windef.h>
#endif
#include <sql.h>
]])
AC_CHECK_SIZEOF(wchar_t, 4)
AC_CHECK_TYPES([SQLLEN, SQLULEN],,,
[[
#ifdef __WINDOWS__
#include <windef.h>
#endif
#include <sql.h>
]])

if test "$havelib" = yes &&
   test "$ac_cv_header_sql_h" = yes; then
  TARGETS="odbc4pl.$SO"
else
  echo "ERROR:   Cannot find odbc library or the header sql.h"
  echo "WARNING: ODBC interface will not be built"
  TARGETS=""
fi

PLTARGETS=`echo $TARGETS | sed "s/4pl\.$SO/.pl/g"`

AC_OUTPUT(Makefile)




