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

AC_INIT(include/prothon/prothon.h)
AC_CONFIG_HEADER(include/config.h)

dnl Grab some of our macros
sinclude(ac-macros/find_apr.m4)
sinclude(ac-macros/find_apu.m4)
sinclude(ac-macros/libtool.m4)
sinclude(ac-macros/pkg.m4)

PACKAGE_VERSION="0.0"

AC_PROG_CC
AC_PROG_LIBTOOL
AC_PROG_INSTALL
AC_PROG_YACC

CFLAGS="$CFLAGS -Wall"

PROTHON_DEFAULT_MODDIR="${libdir}/prothon-${PACKAGE_VERSION}"
AC_SUBST(PROTHON_DEFAULT_MODDIR)

HAVE_BOOST_REGEX=no
BOOST_REGEX_LIBS=

AC_CHECK_HEADER(boost/regex.h,
  [AC_CHECK_LIB(boost_regex, regexecA, [
    HAVE_BOOST_REGEX=yes
    BOOST_REGEX_LIBS=-lboost_regex
  ])])

AC_SUBST(HAVE_BOOST_REGEX)
AC_SUBST(BOOST_REGEX_LIBS)

PKG_CHECK_MODULES(SQLITE, sqlite, [HAVE_SQLITE=yes], [HAVE_SQLITE=no])

AC_SUBST(HAVE_SQLITE)

AC_CHECK_HEADER(sys/utsname.h, [
  AC_DEFINE([HAVE_SYS_UTSNAME_H], [], [Define this to 1 if you have sys/utsname.h])
])

APR_FIND_APR("$srcdir/apr", "./apr", 1)
APR_FIND_APU("$srcdir/apr-util", "./apr-util", 1)

if test $apr_found = "no"; then
	AC_MSG_ERROR([no suitable apr found])
fi

if test $apu_found = "no"; then
	AC_MSG_ERROR([no suitable aprutil found])
fi

CPPFLAGS="$CPPFLAGS `$apr_config --cppflags`"
if test $? -ne 0; then
	AC_MSG_ERROR([apr-config --cppflags failed])
fi

CPPFLAGS="$CPPFLAGS `$apr_config --includes`"
if test $? -ne 0; then
	AC_MSG_ERROR([apr-config --includes])
fi

CFLAGS="$CFLAGS `$apr_config --cflags`"
if test $? -ne 0; then
	AC_MSG_ERROR([apr-config --cflags failed])
fi

LDFLAGS="$LDFLAGS `$apr_config --ldflags`"
if test $? -ne 0; then
	AC_MSG_ERROR([apr-config --ldflags failed])
fi

LINK_LD="$LINK_LD `$apr_config --link-ld --libs`"
if test $? -ne 0; then
	AC_MSG_ERROR([apr-config --link-ld --libs failed])
fi

LINK_LIBTOOL="$LINK_LIBTOOL `$apr_config --link-libtool --libs`"
if test $? -ne 0; then
	AC_MSG_ERROR([apr-config --link-libtool --libs failed])
fi

dnl APU

CPPFLAGS="$CPPFLAGS `$apu_config --includes`"
if test $? -ne 0; then
        AC_MSG_ERROR([apu-config --includes])
fi

LDFLAGS="$LDFLAGS `$apu_config --ldflags`"
if test $? -ne 0; then
        AC_MSG_ERROR([apu-config --ldflags failed])
fi

LINK_LD="$LINK_LD `$apu_config --link-ld --libs`"
if test $? -ne 0; then
        AC_MSG_ERROR([apu-config --link-ld --libs failed])
fi

LINK_LIBTOOL="$LINK_LIBTOOL `$apu_config --link-libtool --libs`"
if test $? -ne 0; then
        AC_MSG_ERROR([apu-config --link-libtool --libs failed])
fi


AC_SUBST(LINK_LD)
AC_SUBST(LINK_LIBTOOL)

AC_OUTPUT(Rules.mk Makefile src/Makefile modules/Makefile
	  modules/Re/Makefile
	  modules/Prosist/Makefile modules/SQLite/Makefile
	  modules/OS/Makefile modules/DBM/Makefile)