# -*-sh-*-
AC_INIT(libpcre++/pcre++.h)
AM_CONFIG_HEADER(libpcre++/config.h)
AM_INIT_AUTOMAKE(libpcre++, `cat VERSION`)

AC_PROG_CXX
AC_PROG_CXXCPP
AC_LANG_CPLUSPLUS
AC_CANONICAL_HOST
AC_PROG_INSTALL
AM_PROG_LIBTOOL

AC_CHECK_HEADERS(string sstream vector stdexcept)

AC_HEADER_STDC

dnl provide flag --enable-debug
AC_ARG_ENABLE(debug,
[  --enable-debug          enable debugging output],
[if test "$enableval" = "yes"; then 
    DEBUG="yes"
    CPPFLAGS="$CPPFLAGS -DDEBUG"
fi]
)


AC_ARG_WITH(pcre_include,
   [  --with-pcre-include=<path> where the PCRE header files are installed],
   [if test "x$with_pcre_include" != "x"; then
       CPPFLAGS="$CPPFLAGS -I$with_pcre_include"
    fi],
)

AC_ARG_WITH(pcre_lib,
   [  --with-pcre-lib=<path> where the PCRE library is installed],
   [if test "x$with_pcre_lib" != "x"; then
       LIBS="$LIBS -L$with_pcre_lib -lpcre"
    fi],
)

case "$host" in
    powerpc-apple-darwin*)
    CC=g++
    ;;
esac

if test "x$with_pcre_include" = "x"; then
   # hm, not defined, so, try these defaults:
   case "$host" in
	*-*-cygwin*)
			# pcre.h in    x:/cygwin/include/
			CPPFLAGS="$CPPFLAGS -I/include"
			;;
	*-*-linux*)
			CPPFLAGS="$CPPFLAGS `pcre-config --cflags` -I/usr/include -I/usr/local/include"
			;;
	*-*-freebsd*)
			CPPFLAGS="$CPPFLAGS `pcre-config --cflags` -I/usr/local/include"
			;;
	*-*-solaris*)
			CPPFLAGS="$CPPFLAGS `pcre-config --cflags` -I$prefix/include -I/usr/local/include"
			;;
	*)
			CPPFLAGS="-I/usr/include -I/usr/local/include"
			;;
   esac
fi


if test "x$with_pcre_lib" = "x"; then
   # hm, not defined, so, try these defaults:
   case "$host" in
	*-*-cygwin*)
			# pcre.dll in  x:/cygwin/lib/
			LIBS="$LIBS -L/lib -lpcre"
			;;
	*-*-linux*)
			LIBS="$LIBS `pcre-config --libs`"
			;;
	*-*-freebsd*)
			LIBS="$LIBS `pcre-config --libs`"
			;;
        *-*-solaris*)
			LIBS="$LIBS -L$prefix/lib -L/usr/local/lib `pcre-config --libs`"
			;;
	*)
			LIBS="$LIBS -lpcre"
			;;
   esac
fi

AC_CHECK_LIB(pcre, pcre_exec)

AC_PREFIX_DEFAULT(/usr/local)

if test "$ac_cv_lib_pcre_pcre_exec" != "yes"; then
    echo
    echo "*** Warning: the PCRE library could not be found!"
    echo "*** You will not be able to compile libpcre++."
    echo "*** Please get a copy from http://www.pcre.org,"
    echo "*** install it and then retry!"
    echo
    exit 1
fi

PCREPP_VERSION=`cat VERSION`
AC_SUBST(PCREPP_VERSION)

AC_OUTPUT(Makefile libpcre++/Makefile examples/Makefile test/Makefile doc/Makefile pcre++-config ,[chmod a+x pcre++-config])

echo
echo " ***"
echo " *** Hosttype is: $host. Using the following compiler flags:"
echo " *** CPPFLAGS: $CPPFLAGS"
echo " ***     LIBS: $LIBS"
echo " ***"
echo " *** You are now ready to build libpcre++:"
echo " *** Enter the following command: make && make install"
echo " *** To read the documentation enter: man 3 Pcre"
echo " ***"
echo " *** Thanks for using GNU software."
echo " ***"









