AC_INIT(src/Rgraphviz.c)
AC_PREREQ(2.13)
AC_REVISION($Revision: 1.12 $)
# AC_CONFIG_SRCDIR(src/Rgraphviz.c)

AC_DEFUN([CHECK_GRAPHVIZ],
[AC_MSG_CHECKING(for graphviz)
AC_ARG_WITH(graphviz,
[ --with-graphviz=DIR root directory of graphviz installation
[defaults to /usr/local]],
[if test x"$withval" != no ; then
	DOTNEATO_CONFIG="$withval/bin/dotneato-config"
 else
	DOTNEATO_CONFIG="not found"
 fi],
[AC_PATH_PROG(DOTNEATO_CONFIG, dotneato-config, [not found])])

if test "${DOTNEATO_CONFIG}" != "not found"; then
	AC_MSG_RESULT(${DOTNEATO_CONFIG})
	PKG_CPPFLAGS="`${DOTNEATO_CONFIG} --cflags`"

	MAJOR=`${DOTNEATO_CONFIG} --version`
	MAJOR=`echo [${MAJOR}] | cut -f1 -d"."`
	
	MINOR=`${DOTNEATO_CONFIG} --version`
	MINOR=`echo [${MINOR}] | cut -f2 -d"."`

	if test ${MAJOR} -eq "1"; then
	   if test ${MINOR} -lt "12"; then
		AC_MSG_RESULT(failed)
		AC_MSG_ERROR(please specify a valid path to 'dotneato-config' version >= 1.12 using --with-graphviz=DIR)
	   fi
	   if test ${MINOR} -eq "12"; then
		GVIZ_DEFS="-DGRAPHVIZ_1_12"
	   fi
	   if test ${MINOR} -lt "16"; then
		PKG_LIBS="-Wl `${DOTNEATO_CONFIG} --libs` -lm"
           else
		GVIZ_DEFS="-DGRAPHVIZGT_1_16"
		PKG_LIBS="`${DOTNEATO_CONFIG} --ldflags` `${DOTNEATO_CONFIG} --libs` -lm"
	   fi
	else
	   if test ${MAJOR} -eq "2"; then
                GVIZ_DEFS="-DGRAPHVIZGT_1_16"
		PKG_LIBS="`${DOTNEATO_CONFIG} --ldflags` `${DOTNEATO_CONFIG} --libs` -lm"
		   
           else
              AC_MSG_RESULT(failed)
              AC_MSG_ERROR(please specify a valid path to
	      'dotneato-config' version >= 1.12 using
	      --with-graphviz=DIR)   
           fi        
	fi
else
     AC_MSG_RESULT(failed)
     AC_MSG_ERROR(please specify a valid path to 'dotneato-config' version >= 1.12 using --with-graphviz=DIR)
fi])

CHECK_GRAPHVIZ

AC_SUBST(GVIZ_DEFS)
AC_SUBST(PKG_CPPFLAGS)
AC_SUBST(PKG_LIBS)
AC_OUTPUT(src/Makevars)