dnl Helder Correia <helder.correia@netcabo.pt>

dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/main.cpp)
AC_CANONICAL_SYSTEM
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(nload, 0.5.0)

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL

dnl Checks for libraries.
AC_CHECK_LIB(ncurses, initscr)
AC_CHECK_LIB(form, new_form)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([limits.h stdlib.h string.h unistd.h curses.h math.h sys/param.h sys/socket.h sys/time.h sys/ioctl.h arpa/inet.h netinet/in.h])

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME

dnl Use some gcc specific options.
if test "$GCC" = "yes" ; then
     CFLAGS="$CFLAGS -Wall"
     CXXFLAGS="$CXXFLAGS -Wall"
fi

dnl System dependant jobs
case $target in
    *linux*)
        AC_DEFINE(HAVE_LINUX, 1)
        AC_CHECK_FUNCS([memset])
        ;;
    *bsd*)
        AC_DEFINE(HAVE_BSD, 1)
        AC_FUNC_MALLOC
        ;;
    *solaris*)
        AC_CHECK_LIB(rt, main)
        AC_CHECK_LIB(kstat, kstat_open)
        AC_CHECK_LIB(socket, main)
        AC_CHECK_LIB(nsl, main)
        AC_DEFINE(HAVE_SOLARIS, 1)
        ;;
esac

dnl Adds extra arguments to configure script.
AC_ARG_ENABLE(debug,
              AC_HELP_STRING([--enable-debug],[enable runtime debugging [[no]]]),
	      test "$enableval" = "no" && LDFLAGS="$LDFLAGS -s",
	      LDFLAGS="$LDFLAGS -s")

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([gettimeofday pow inet_ntoa socket])

AC_CONFIG_FILES([
Makefile
docs/Makefile
docs/nload.1
nload.spec
src/Makefile
])

AC_OUTPUT
