dnl -*-Fundamental-*-
dnl $Id: configure.in,v 1.13 2001/01/02 19:14:33 ste Exp $
dnl Process this file with autoconf to produce a configure script.

dnl Aggiunge il numero di revisione.
AC_REVISION($Revision: 1.13 $)

AC_INIT(asp.c)

dnl Crea il file config.h che contiene i #define.
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(	\
	arpa/inet.h	\
	errno.h		\
	libc.h		\
	limits.h	\
	netdb.h		\
	netinet/in.h	\
	pwd.h		\
	string.h	\
	strings.h	\
	sys/ddi.h	\
	sys/select.h	\
	sys/socket.h	\
	sys/socketvar.h \
	sys/syslog.h	\
	sys/time.h 	\
	sys/utsname.h	\
	syslog.h	\
	unistd.h	\
)

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

ASP_CHECK_DECL(errno,
	[#ifdef HAVE_ERRNO_H
	#include <errno.h>
	#endif]
)

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(		\
	inet_aton	\
	select		\
	strchr		\
	uname		\
)

AC_REPLACE_FUNCS(strtol)

if test $ac_cv_func_inet_aton = yes; then
	ASP_CHECK_DECL(inet_aton,
		[#ifdef HAVE_ARPA_INET_H
		#include <arpa/inet.h>
		#endif]
	)
fi

AC_CHECK_FUNC(gethostname,
	AC_DEFINE(HAVE_GETHOSTNAME),
	[for lib in nsl resolv; do
		AC_CHECK_LIB($lib,
			gethostname,
			[AC_DEFINE(HAVE_GETHOSTNAME)
			LIBS="$LIBS -l$lib"
			break]
		)
	done]
)

AC_CHECK_FUNC(socket,
	AC_DEFINE(HAVE_SOCKET),
	[for lib in bsd socket; do
		AC_CHECK_LIB($lib,
			socket,
			[AC_DEFINE(HAVE_SOCKET)
			LIBS="$LIBS -l$lib"
			break]
		)
	done]
)

dnl Controlla la funzione strerror. In caso negativo controlla
dnl la dichiarazione di sys_errlist.
AC_CHECK_FUNC(strerror,
	AC_DEFINE(HAVE_STRERROR),
	ASP_CHECK_DECL(sys_errlist,
		[#include <stdio.h>
		#ifdef HAVE_ERRNO_H
		#   include <errno.h>
		#endif]
	)
)

dnl Controlla la funzione strsignal. In caso negativo controlla
dnl la dichiarazione di sys_siglist.
AC_CHECK_FUNC(strsignal,
	[AC_DEFINE(HAVE_STRSIGNAL)
	ASP_CHECK_DECL(strsignal,
		[#ifdef HAVE_STRING_H
		#   include <string.h>
		#else
		#   ifdef HAVE_STRINGS_H
		#      include <strings.h>
		#   endif
		#endif]
	)],
	AC_DECL_SYS_SIGLIST
)

dnl Controlla le features passate a configure tramite --enamble=FEATURE.
dnl Indica che sta controllando se vogliamo il debug.
AC_MSG_CHECKING(if you want to compile-in debug support)
AC_ARG_ENABLE(debug,
	[  --enable-debug          print some debugging information],
	[if test "$enableval" = "yes"; then
		ENABLE_DEBUG=-DENABLE_DEBUG
	else
		ENABLE_DEBUG=''
		# Toglie -g da $CFLAGS
		CFLAGS=`echo $CFLAGS | sed -e 's/-g //' -e 's/-g$//'`
		# Forza enableval a no
		enableval=no
	fi],
	[CFLAGS=`echo $CFLAGS | sed -e 's/-g //' -e 's/-g$//'`
	enableval=no]
)
dnl Scrive yes/no.
AC_MSG_RESULT($enableval)
dnl Sostituisce @ENABLE_DEBUG@ nel Makefile.in.
AC_SUBST(ENABLE_DEBUG)

dnl Controlla se e` stato passato un path alternativo per /etc/hosts.
AC_MSG_CHECKING(for hosts data base path)
AC_ARG_WITH(hosts-path,
	[  --with-hosts-path=PATH  hosts data base (default: /etc/hosts)],
	[if ! test -f "$withval"; then
		AC_MSG_ERROR(File $withval not found)
	fi],
	withval=/etc/hosts
)
dnl Scrive il PATH.
AC_MSG_RESULT($withval)
dnl Definisce su config.h HOSTS_PATH.
AC_DEFINE_UNQUOTED(HOSTS_PATH, "$withval")


AC_OUTPUT(Makefile)
