dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/allheaders.h)
AM_INIT_AUTOMAKE(tcptrack, 1.0.1)

AM_CONFIG_HEADER(config.h:config.in)

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_CC

dnl See if the compiler accepts -pthread... needed for BSDs
AC_PTHREAD_FREEBSD

dnl Checks for libraries.
AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(socket,gethostbyname)
AC_CHECK_LIB(nsl,gethostbyname)
AC_CHECK_LIB(nsl,inet_addr)
AC_CHECK_LIB(ncurses, initscr)
AC_CHECK_LIB(pcap, pcap_open_live)
AC_CHECK_LIB(pthread, pthread_create)

dnl Checks for header files.
AC_CHECK_HEADERS(unistd.h pcap.h pcap/pcap.h pthread.h curses.h)

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

dnl Checks for library functions.
AC_HEADER_STDC

for hdr in unistd.h pthread.h curses.h
do
	safe=`echo "$hdr" | sed 'y%./+-%__p_%'`
	eval "v=\$ac_cv_header_$safe"
	#echo "HDR: $hdr"
	#echo "VEE: $v"
	if test "$v" = "no" ; then
		AC_MSG_ERROR([Cannot find $hdr header file])
	fi
done

for lib in ncurses_initscr pcap_pcap_open_live ncurses_initscr
do
	eval "v=\$ac_cv_lib_$lib"
	l=`echo $lib|awk -F '_' '{print $1}'`
	if test "$v" = "no" ; then
		AC_MSG_ERROR([Connot find $l library])
	fi
done

if test "$ac_cv_header_pcap_h" = "no" -a "$ac_cv_header_pcap_pcap_h" = "no"; then
	AC_MSG_ERROR([Cannot find either pcap/pcap.h or pcap.h. You may have
to install your operating system's libpcap development packages or install
libpcap from source. Also see README.])
fi


AC_OUTPUT(Makefile src/Makefile)
