AC_INIT([Arts++], [1.1.a12])
AC_PREREQ(2.53)
AC_CONFIG_SRCDIR(classes/include/Arts.hh)
AC_CONFIG_HEADER(classes/include/caida_t.h classes/include/artslocal.h include/aclocal.h classes/include/Ipv4PrefixPatricia.hh)

dnl  @(#) $Name: arts++-1-1-a12 $
dnl  @(#) $Id: configure.in,v 1.6 2006/09/08 22:30:05 youngh Exp $

dnl  ###  override prefix if not set

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

AC_LANG(C++)

dnl  ###  Checks for programs.

AC_PROG_CC
AC_PROG_CXX
AC_AIX
AC_PROG_RANLIB
AC_PATH_XTRA
AC_CANONICAL_SYSTEM
AM_DISABLE_SHARED
AM_PROG_LIBTOOL

inttypes=no
AC_CHECK_HEADERS(inttypes.h,[inttypes=yes])
case $inttypes in
  yes)
    AC_MSG_CHECKING([for int8_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[int8_t  bar;],
        [AC_DEFINE(HAVE_INT8_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int16_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[int16_t  bar;],
        [AC_DEFINE(HAVE_INT16_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int32_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[int32_t  bar;],
        [AC_DEFINE(HAVE_INT32_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int64_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[int64_t  bar;],
        [AC_DEFINE(HAVE_INT64_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint8_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[uint8_t  bar;],
        [AC_DEFINE(HAVE_UINT8_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint16_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[uint16_t  bar;],
        [AC_DEFINE(HAVE_UINT16_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint32_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[uint32_t  bar;],
        [AC_DEFINE(HAVE_UINT32_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint64_t in <inttypes.h>])
    AC_TRY_COMPILE([#include <inttypes.h>],
	[uint64_t  bar;],
        [AC_DEFINE(HAVE_UINT64_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    ;;
esac

dnl ---------------------------------------------------------------------------
dnl   Check for <machine/types.h>, then check to see if it's got definitions
dnl   for the types in the ISO C working draft <inttypes.h> or includes
dnl   some other header files that defines them.
dnl ---------------------------------------------------------------------------

machine_types=no
AC_CHECK_HEADERS(machine/types.h,[machine_types=yes])

case $machine_types in
  yes)
    AC_MSG_CHECKING([for int8_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[int8_t  bar;],
        [AC_DEFINE(HAVE_INT8_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int16_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[int16_t  bar;],
        [AC_DEFINE(HAVE_INT16_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int32_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[int32_t  bar;],
        [AC_DEFINE(HAVE_INT32_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int64_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[int64_t  bar;],
        [AC_DEFINE(HAVE_INT64_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint8_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[uint8_t  bar;],
        [AC_DEFINE(HAVE_UINT8_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint16_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[uint16_t  bar;],
        [AC_DEFINE(HAVE_UINT16_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint32_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[uint32_t  bar;],
        [AC_DEFINE(HAVE_UINT32_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint64_t in <machine/types.h>])
    AC_TRY_COMPILE([#include <machine/types.h>],
	[uint64_t  bar;],
        [AC_DEFINE(HAVE_UINT64_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    ;;
esac

dnl ---------------------------------------------------------------------------
dnl   Check for <sys/types.h>, then check to see if it's got definitions
dnl   for the types in the ISO C working draft <inttypes.h> or includes
dnl   some other header file which defines them.
dnl ---------------------------------------------------------------------------
sys_types=no
AC_CHECK_HEADERS(sys/types.h,[sys_types=yes])

case $sys_types in
  yes)
    AC_MSG_CHECKING([for int8_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[int8_t  bar;],
        [AC_DEFINE(HAVE_INT8_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int16_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[int16_t  bar;],
        [AC_DEFINE(HAVE_INT16_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int32_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[int32_t  bar;],
        [AC_DEFINE(HAVE_INT32_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for int64_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[int64_t  bar;],
        [AC_DEFINE(HAVE_INT64_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint8_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[uint8_t  bar;],
        [AC_DEFINE(HAVE_UINT8_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint16_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[uint16_t  bar;],
        [AC_DEFINE(HAVE_UINT16_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint32_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[uint32_t  bar;],
        [AC_DEFINE(HAVE_UINT32_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    AC_MSG_CHECKING([for uint64_t in <sys/types.h>])
    AC_TRY_COMPILE([#include <sys/types.h>],
	[uint64_t  bar;],
        [AC_DEFINE(HAVE_UINT64_T)
	 AC_MSG_RESULT(yes)
	],
	AC_MSG_RESULT(no))
    ;;
esac

AC_CHECK_SIZEOF(unsigned short,2)
AC_CHECK_SIZEOF(short,2)
AC_CHECK_SIZEOF(unsigned int,4)
AC_CHECK_SIZEOF(int,4)
AC_CHECK_SIZEOF(unsigned long,4)
AC_CHECK_SIZEOF(long,4)
AC_CHECK_SIZEOF(unsigned long long,8)
AC_CHECK_SIZEOF(long long,8)

AC_C_BIGENDIAN

AC_TRY_CPP([#include <fstream>],AC_DEFINE(HAVE_FSTREAM))
AC_TRY_CPP([#include <iostream>],AC_DEFINE(HAVE_IOSTREAM))
AC_TRY_CPP([#include <iomanip>],AC_DEFINE(HAVE_IOMANIP))
AC_TRY_CPP([#include <sstream>],AC_DEFINE(HAVE_SSTREAM))
AC_TRY_CPP([#include <strstream>],AC_DEFINE(HAVE_STRSTREAM))

AC_CHECK_LIB(nsl, inet_ntoa)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(rpc, xdr_float)
AC_CHECK_LIB(rpcsvc, xdr_float)

dnl  ###  Read some useful macros.

builtin(include, ./xrt.m4)      dnl  check for XRT libraries
builtin(include, ./dwm.m4)      dnl

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 DWM_PREREQ_PATH(krb4,/usr/kerberos,[Kerberos 4 top-level directory])
DWM_PREREQ_PATH(XINCDIR,$x_includes,[X11 include directory])
DWM_PREREQ_PATH(XLIBDIR,$x_libraries,[X11 library directory])
DWM_PREREQ_PATH(MOTIFINCDIR,/usr/include)
DWM_PREREQ_PATH(MOTIFLIBDIR,/usr/lib)
DWM_PREREQ_PATH(artspptop,`pwd`,[arts++ top-level source directory])
DWM_PREREQ_PATH(docurl,/caida/powertools/arts,[top-level documentation URL])

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

DWM_PRESET_PATH(includedir,$prefix/include)
DWM_PRESET_PATH(libdir,$prefix/lib)
DWM_PRESET_PATH(bindir,$prefix/bin)
DWM_PRESET_PATH(mandir,$prefix/man)

DWM_DISABLE(debug,[disable debugging])
case $debug in
  no)
    CXXFLAGS="${CXXFLAGS} -DNDEBUG"
    ;;
  yes)
    ;;
esac

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

echo "OSNAME set to $OSNAME"
dnl OSRELEASE=`uname -r | sed 's/\//\_/g'`
dnl AC_SUBST(OSRELEASE)
dnl echo "OSRELEASE set to $OSRELEASE"

case $host_os in
  bsdi*)
    TAR="tar"
    ;;
  freebsd2*)
    DWM_XDR_DESTROY_MACRO_DONT_PASS_POINTER()
    TAR="/usr/bin/tar -P"
    ;;
  freebsd3*)
    TAR="/usr/bin/tar -P"
    ;;
  linux*)
    TAR="/bin/tar -P"
    ;;
  solaris*)
    DWM_PREREQ_PATH(MOTIFINCDIR,/usr/dt/include)
    DWM_PREREQ_PATH(MOTIFLIBDIR,/usr/dt/lib)
    X_EXTRA_LIBS="-lICE -lSM"
    TAR="/usr/bin/tar"
    ;;
  sunos*)
    dnl  this is a guess, I don't have a sunos 4.x machine
    DWM_PREREQ_PATH(MOTIFINCDIR,/usr/dt/include)
    DWM_PREREQ_PATH(MOTIFLIBDIR,/usr/dt/lib)
    X_EXTRA_LIBS="-lICE -lSM"
    TAR="/usr/bin/tar"
    ;;
  *)
    TAR="tar"
    ;;
esac

AC_SUBST(TAR)

DWM_SET_VERSION(PKG_VERSION,$Name: arts++-1-1-a12 $,[arts++-1-1-a12])

dnl   C_R_A is the 'Current', 'Revision', 'Age' triplet for shared
dnl   library versioning using libtool.  Here are a set of rules 
dnl   in updating library version information:
dnl
dnl   1. Start with version information of `0:0:0' for each libtool
dnl      library.
dnl
dnl   2. Update the version information only immediately before a 
dnl      public release.  More frequent updates are unnecessary, and
dnl      only guarantee that the current interface number gets larger
dnl      faster.
dnl
dnl   3. If the arts++ library source code has changed at all since 
dnl      the last update, then increment REVISION (`C:R:A' becomes 
dnl      `C:r+1:A').
dnl
dnl   4. If any interfaces have been added, removed, or changed since 
dnl      the last update, increment CURRENT, and set REVISION to 0.
dnl
dnl   5. If any interfaces have been added since the last public 
dnl      release, then increment AGE.
dnl
dnl   6. If any interfaces have been removed since the last public 
dnl      release, then set AGE to 0.

DWM_SET_VERSION(C_R_A,[0:0:0],[0:0:0])

DWM_LIST_PREREQ_PATHS()
DWM_LIST_INSTALL_PATHS()

AC_CONFIG_FILES(Makefile \
	  classes/src/Makefile \
	  classes/include/Makefile \
	  doc/Makefile \
	  doc/libArts/Makefile \
	  doc/installHtml.sh \
	  doc/libArts/installHtml.sh \
	  apps/artsagg/Makefile \
	  apps/artsases/Makefile \
	  apps/artsasagg/Makefile \
	  apps/artsdump/Makefile \
	  apps/artsintfms/Makefile \
	  apps/artsintfmagg/Makefile \
	  apps/artsnets/Makefile \
	  apps/artsnexthops/Makefile \
	  apps/artsnexthopagg/Makefile \
	  apps/artsnetagg/Makefile \
	  apps/artsportagg/Makefile \
	  apps/artsportmagg/Makefile \
	  apps/artsportms/Makefile \
	  apps/artsports/Makefile \
	  apps/artsprotoagg/Makefile \
	  apps/artsprotos/Makefile \
	  apps/artstoc/Makefile \
	  apps/artstos/Makefile \
	  apps/artstrunc/Makefile)
AC_OUTPUT

