AC_INIT(src/rateup.c)

dnl Check for programs.
AC_PROG_CC
AC_PREFIX_DEFAULT( /usr/local/mrtg-2 )

AC_PROG_CPP
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PATH_PROG(PERL, perl, no, $PATH:/usr/bin:/usr/local/bin)
if test $PERL = no; then 
   echo
   echo "** No Perl found in the PATH. A recent copy of Perl"
   echo "   is required for mrtg to work. Check www.perl.com"
   echo 
   exit 1
fi

AC_PATH_PROGS(NROFF, groff nroff)

dnl Checks for libraries.
AC_CHECK_LIB(m, acos)

dnl AC_ARG_WITH(RRDs,[  --with-RRDs=DIR         location RRDtool perl module],
dnl 		[PERL5LIB="${withval}";export PERL5LIB])
dnl AC_MSG_CHECKING(availability of RRDtool / RRDs.pm)
dnl if $PERL -e 'use RRDs' >/dev/null 2>&1; then
dnl   AC_MSG_RESULT(found)
dnl  RRD_PERL=$PERL5LIB
dnl else
dnl  AC_MSG_RESULT(no)
dnl fi

AC_ARG_WITH(gd,[  --with-gd=DIR           location of the gd lib/inc],
		[LDFLAGS="${LDFLAGS} -L${withval}"
		CFLAGS="${CFLAGS} -I${withval}"
		LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"])

AC_ARG_WITH(gd-lib,[  --with-gd-lib=DIR       location of the gd library],
		[LDFLAGS="${LDFLAGS} -L${withval}"
		LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"])

AC_ARG_WITH(gd-inc,[  --with-gd-inc=DIR       location of the gd include files],
		[CFLAGS="${CFLAGS} -I${withval}"])

LDFLAGS="${LDFLAGS} -lgd"

AC_ARG_WITH(z,[  --with-z=DIR            location of zlib lib/inc],
		[LDFLAGS="${LDFLAGS} -L${withval}"
		CFLAGS="${CFLAGS} -I${withval}"
		LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"])

AC_ARG_WITH(z-lib,[  --with-z-lib=DIR        location of zlib library],
		[LDFLAGS="${LDFLAGS} -L${withval}"
		LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"])

AC_ARG_WITH(z-inc,[  --with-z-inc=DIR        location of the zlib include files],
		[CFLAGS="${CFLAGS} -I${withval}"])

AC_ARG_WITH(png,[  --with-png=DIR          location of png lib/inc],
		[LDFLAGS="${LDFLAGS} -L${withval}"
		CFLAGS="${CFLAGS} -I${withval}"
		LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"])

AC_ARG_WITH(png-lib,[  --with-png-lib=DIR      location of png library],
		[LDFLAGS="${LDFLAGS} -L${withval}"
		LD_RUN_PATH="${withval}${LD_RUN_PATH:+:}${LD_RUN_PATH}"])

AC_ARG_WITH(png-inc,[  --with-png-inc=DIR      location of the libpng include files],
		[CFLAGS="${CFLAGS} -I${withval}"])

LDFLAGS="${LDFLAGS} -lm"

dnl which version of gd do we have here ?
AC_CHECK_LIB(gd,gdImageGif,[
  CFLAGS="$CFLAGS -DGFORM_GD=gdImageGif"
  GDFORM_EXT=gif
                           ])
AC_CHECK_LIB(gd,gdImagePng,[
  CFLAGS="$CFLAGS -DGFORM_GD=gdImagePng"
  LDFLAGS="$LDFLAGS -lpng -lz -lm"
  GDFORM_EXT=png
        ],:,[-lpng -lz -lm])

if test x$GDFORM_EXT = x; then
echo
	echo "** The GD library is required for rateup to compile."
	echo "   Get it from http://www.boutell.com, compile it and"
	echo "   use either --with-gd-lib=DIR and --with-gd-inc=DIR to specify"
	echo "   its location. You might also have to use --with-z-inc, --with-z-lib"
	echo "   and --with-png-inc, --with-png-lib for gd versions 1.6 and higher."
	echo "   Check config.log for more information on the problem."
	exit 1
fi

AC_MSG_CHECKING(the weather)
AC_MSG_RESULT((cached) its fine)

dnl Add GCC-specific compile-time options
if test "x$GCC" = "yes"; then
  CFLAGS="$CFLAGS -Wall -pedantic"
fi


AC_SUBST(PERL)
AC_SUBST(RRD_PERL)
AC_SUBST(GDFORM_EXT)
AC_SUBST(LD_RUN_PATH)

AC_OUTPUT(Makefile)

echo $ac_n "ordering CD from http://ee-staff.ethz.ch/~oetiker/wish $ac_c" 1>&6
$PERL -e '$|=1;for (0..2){print ".\a";sleep 1}'
AC_MSG_RESULT([ just kidding ;-)])
sleep 2
echo
echo "----------------------------------------------------------------"
echo "Config is DONE!"
echo
echo "Type 'make' to compile the software"
echo 
echo "       ... that wishlist mentioned above does really exist. So if"
echo "you feel like showing your appreciation for MRTG, this is the"
echo "place to go. I just love CDs and DVDs"
echo 
echo "                            -- Tobi Oetiker <oetiker@ee.ethz.ch>"
echo "----------------------------------------------------------------"
