dnl Process this file with autoconf to produce a configure script.
AC_INIT(parser3mysql.C)
AC_PREREQ(2.57)

AM_INIT_AUTOMAKE(parser3mysql, 10.3, nodefine)

AM_CONFIG_HEADER(config_auto.h)


AC_DEFUN([MYSQL_INC_CHK],[
	if test -r "$1/mysql.h"; then
		MYSQL_INC=$1
	fi
])
	

dnl Arguments

AC_ARG_WITH(mysql-inc,[  --with-mysql-inc=DIR        DIR is the MySQL includes directory],
	MYSQL_INC_CHK($withval)

	if test -z "$MYSQL_INC"; then
		AC_MSG_ERROR($MYSQL_INC does not seem to be valid MySQL includes directory)
	fi
,
	AC_MSG_CHECKING(for MYSQL_INC directory)
	for d in \
		/usr/local/include/mysql \
		/usr/include/mysql ; do
		MYSQL_INC_CHK($d)
	done

	if test -z "$MYSQL_INC"; then
		AC_MSG_ERROR(use --with-mysql-inc=DIR to specify MySQL includes directory)
	fi

	AC_MSG_RESULT($MYSQL_INC)
)

AC_SUBST(MYSQL_INC)



AC_ARG_WITH(dynamic-stdcpp, [  --with-dynamic-stdcpp   link libstdc++ dynamically
                          by default, libstdc++ is linked statically],[
		LDFLAGS="-lstdc++"
],[
		LDFLAGS="-Wl,-Bstatic -Wl,-lstdc++ -Wl,-Bdynamic"
])

AC_SUBST(LDFLAGS)


dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_AWK
AC_PROG_CXX
AC_PROG_CC

dnl most tests should be compiled with C compiler [especially qsort test]
AC_LANG_C 

dnl Enable building of the convenience library
dnl and set LIBLTDL accordingly
AC_LIBLTDL_CONVENIENCE
dnl Substitute INCLTDL and LIBLTDL in the Makefiles
AC_SUBST(INCLTDL)
AC_SUBST(LIBLTDL)
AC_SUBST(LIBADD_DL)
dnl Configure libtool
AC_DISABLE_STATIC
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
dnl Configure libltdl
AC_CONFIG_SUBDIRS(libltdl)

dnl Checks for libraries.

dnl FreeBSD4 requires workaround with destructor
case "$host" in
	*-freebsd4*)
		AC_DEFINE(FREEBSD4,,FreeBSD4X target platform)
esac

dnl Checks for header files.

AC_CHECK_HEADERS(
stdio.h \
stdlib.h \
string.h \
setjmp.h \
ctype.h
)

dnl Checks for typedefs, structures, and compiler characteristics.

AC_TYPE_SIZE_T

dnl Checks for library functions.

dnl Output makefiles

AC_OUTPUT(Makefile)
