AC_INIT(classes/include/CflowdAsMatrix.hh)
AC_CONFIG_HEADER(include/aclocal.h)

dnl  @(#) $Name: cflowd-2-1-b1 $
dnl  @(#) $Id: configure.in,v 1.68 2000/05/23 19:50:36 dwm Exp $

dnl  ###  override prefix if not set

if test "$prefix" = "NONE"; then
  prefix="/usr/local/arts"
fi

dnl  ###  Checks for programs.

AC_PROG_CC
AC_PROG_CXX
AC_AIX
AC_PROG_RANLIB
AC_CANONICAL_SYSTEM
AM_DISABLE_SHARED
AM_PROG_LIBTOOL

AC_CHECK_LIB(nsl, inet_ntoa)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(compat, ftok)

AC_CHECK_HEADERS(sys/filio.h sys/termios.h sys/select.h sys/time.h)
AC_CHECK_FUNCS(strcasecmp)

dnl Trying to check for valid msync()
AC_CHECKING(how to call msync)
msync=no
AC_EGREP_CPP(yes,
[#include <sys/mman.h>
 #if defined(MS_ASYNC)
 yes
 #endif
], msync=MS_ASYNC)
AC_EGREP_CPP(yes,
[#include <sys/mman.h>
 #if defined(MS_SYNC)
 yes
 #endif
], msync=MS_SYNC)

case $msync in
  MS_ASYNC)
        AC_DEFINE(MSYNC_HAS_FLAGS)
        ;;
  MS_SYNC)
        AC_DEFINE(MSYNC_HAS_FLAGS)
        AC_DEFINE(HAVE_MS_SYNC)
        ;;
esac

dnl  ###  Read some useful macros.

builtin(include, ./dwm.m4)      dnl

DWM_PREREQ_PATH(artspp,/usr/local/arts,[arts++ installation directory])
DWM_PREREQ_PATH(cflowdtop,`pwd`,[cflowd top-level source directory])
DWM_PREREQ_PATH(docurl,/caida/powertools/cflowd,[top-level documentation URL])
AC_CHECK_LIB(fl,yywrap,
             [flexdirguess=system],
	     [flexguess=`which flex`
	      flexdirguess=`echo $flexguess | awk -F/ '{for (i = 2; i < NF-1; i++) {printf "/%s",$i;} printf "\n";}'`])

DWM_PREREQ_PATH(flexdir,$flexdirguess,[flex directory])

case $flexdirguess in
  system)
    FLEXINC=""
    FLEXLIB="-lfl"
    ;;
  *)
    FLEXINC="-I ${flexdir}/include"
    FLEXLIB="-L ${flexdir}/lib -lfl"
    ;;
esac

AC_SUBST(FLEXINC)
AC_SUBST(FLEXLIB)

dnl  ###  set defaults for paths I'll use if user didn't specify them.

DWM_PRESET_PATH(includedir,$prefix/include/cflowd)
DWM_PRESET_PATH(libdir,$prefix/lib/cflowd)
DWM_PRESET_PATH(bindir,$prefix/bin)
DWM_PRESET_PATH(sbindir,$prefix/sbin)
DWM_PRESET_PATH(mandir,$prefix/man)
DWM_PRESET_PATH(sysconfdir,$prefix/etc)

DWM_SET_VERSION(DOC_VERSION,$Name: cflowd-2-1-b1 $,[cflowd-2-1-a7])
DWM_SET_VERSION(PKG_VERSION,$Name: cflowd-2-1-b1 $,[cflowd-2-1-a7])
DWM_SET_VERSION(C_R_A,[0:0:0],[0:0:0])

AC_MSG_CHECKING([for socklen_t])
AC_TRY_COMPILE([
    #include <sys/types.h>
    #include <sys/socket.h>],
  [socklen_t  bar;],
  [AC_DEFINE(HAVE_SOCKLEN_T)
    AC_MSG_RESULT(yes)],
  AC_MSG_RESULT(no)
)

AC_MSG_CHECKING([for union semun])
AC_TRY_COMPILE([
    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/sem.h>],
  [union semun foo;],
  [AC_DEFINE(SEMCTL_NEEDS_UNION)
    AC_MSG_RESULT(yes)],
  [AC_DEFINE(SEMCTL_NEEDS_UNION)
    AC_DEFINE(SEMCTL_NEEDS_SEMUN_DEFN)
    AC_MSG_RESULT(no)]
)

OSNAME=`echo ${host_cpu}-${host_os} | sed 's/\//\_/g'`
AC_SUBST(OSNAME)
echo "OSNAME set to $OSNAME"

case $host_os in
  solaris*)
    AC_DEFINE(CANT_GATHER_SCATTER_SOCKIO)
    TAR="/usr/bin/tar"
    ;;
  freebsd*)
    TAR="/usr/bin/tar -P"
    ;;
  linux*)
    TAR="/bin/tar -P"
    ;;
  bsdi*)
    TAR="tar"
    ;;
  sunos*)
    dnl sparc-sun-sunos4.1.x
    AC_DEFINE(CANT_GATHER_SCATTER_SOCKIO)
    ;;
  *)
    TAR="tar"
    ;;
esac

AC_SUBST(TAR)

DWM_LIST_PREREQ_PATHS()
DWM_LIST_INSTALL_PATHS()

AC_OUTPUT(Makefile \
	  apps/cfdases/Makefile \
	  apps/cfdases/cfdases.man \
	  apps/cfdcollect/Makefile \
	  apps/cfdifmatrix/Makefile \
	  apps/cfdifmatrix/cfdifmatrix.man \
	  apps/cfdnets/Makefile \
	  apps/cfdnets/cfdnets.man \
	  apps/cfdnexthops/Makefile \
	  apps/cfdnexthops/cfdnexthops.man \
	  apps/cfdportmatrix/Makefile \
	  apps/cfdportmatrix/cfdportmatrix.man \
	  apps/cfdprotos/Makefile \
	  apps/cfdprotos/cfdprotos.man \
	  apps/cfdtos/Makefile \
	  apps/cfdtos/cfdtos.man \
	  apps/cflowd/Makefile \
	  apps/cflowdmux/Makefile \
	  apps/dnswatch/Makefile \
	  apps/flowdump/Makefile \
	  apps/flowdump/flowdump.man \
	  apps/flowwatch/Makefile \
	  apps/flowwatch/flowwatch.man \
	  classes/src/CflowdConfig.cc \
	  classes/src/Makefile \
	  etc/Makefile \
	  doc/configuration/configuration.sgml \
	  doc/libCfd/Makefile \
	  doc/libCfd/installHtml.sh \
	  doc/libCfd/cocoon.conf \
	  bsd.ports/net/cflowd/Makefile \
	  snmp++/classes/include/snmp++/Makefile \
	  snmp++/classes/src/Makefile)

