dnl Process this file with autoconf to produce a configure script.
AC_INIT(Dict.cc)
AC_CONFIG_AUX_DIR(./configaux)

AC_CONFIG_HEADER(utils_config.h)

AC_PREFIX_DEFAULT($INSTALL_DIR)

AC_PROG_INSTALL
AC_CANONICAL_SYSTEM
AC_VALIDATE_CACHED_SYSTEM_TUPLE

AC_SUBST(MACHDEP)
MACHDEP=$target

#
# SGI compilers allow the specification of the both the ABI and the
# ISA on the command line.  Depending on the values of these switches,
# different and often incompatable code will be generated.
#
# The SGI_ABI variable can be used to modify the CC and LDFLAGS and
# thus supply support for various ABI/ISA combinations.  The MACHDEP
# variable is also adjusted.
#
AC_SUBST(SGI_ABI)
if test ! -z "$SGI_ABI"
then
        CC="cc $SGI_ABI"
        CXX="CC $SGI_ABI"
        LDFLAGS="$SGI_ABI $LDFLAGS"
        MACHDEP=`echo "${MACHDEP}${SGI_ABI}" | sed 's/ *//g'`
fi

AC_C_BIGENDIAN

dnl When I feel smarter, implement a test to figure alignment out
AC_MSG_CHECKING(structure alignment)
case "$target" in
ia64-* | mips-* | sparc-* | alpha-*) ac_structure_align=ALIGN_LONGEST;;
m68k-*) ac_structure_align=ALIGN_WORD;;
powerpc-* | i386-* | i686-* | i586-* | x86-* | x86_* ) ac_structure_align=ALIGN_INT;;
esac
AC_DEFINE_UNQUOTED(STRUCTURE_ALIGN, ${ac_structure_align})
AC_MSG_RESULT(${ac_structure_align})

AC_PROG_CC
if test "$target_os" = "vxworks"
then
  if test -z "$CXXFLAGS"
  then
    CXXFLAGS="-g -O2"
  fi
else
  AC_PROG_CXX
fi
# icc masquerades as gcc (defines __GNUC__).  Boneheads
if test "$CC" = "icc"
then
  GCC="no"
fi

AC_LANG_CPLUSPLUS

AC_CACHE_CHECK("whether we have bool", ac_cv_has_bool, AC_TRY_COMPILE(, [bool dummy;], ac_cv_has_bool="yes", ac_cv_has_bool="no"))

if test $ac_cv_has_bool = "yes";
then
AC_DEFINE(HAVE_BOOL)
fi

AC_CACHE_CHECK("whether we have namespaces",
               ac_cv_has_namespaces, 
               AC_TRY_COMPILE([namespace foo { class bar {}; }; ],
                              [ foo::bar b(); ], 
                              ac_cv_has_namespaces="yes", 
                              ac_cv_has_namespaces="no"))

if test $ac_cv_has_namespaces = "yes";
then
AC_DEFINE(HAVE_NAMESPACES)
fi

AC_SUBST(CXXLD)
CXXLD=${CXX}
AC_SUBST(CXXITSELF)
CXXITSELF=${CXX}

AC_PROG_RANLIB

AC_SUBST(AR)
AC_CHECK_PROGS(AR, ar aal, ar)
AC_SUBST(INSTALL)
AC_SUBST(INSTALL_PROGRAM)
AC_SUBST(INSTALL_DATA)
# Install just never works :-(
if test -z "$INSTALL"
then
	INSTALL=cp
	INSTALL_PROGRAM=cp
	INSTALL_DATA=cp
else
	INSTALL_PROGRAM="$INSTALL"
	INSTALL_DATA="$INSTALL -m 644"
fi

AC_SUBST(BISONPP)
AC_CHECK_PROG(BISONPP, bison++, bison++, ./fakebison)

# Optimizer/debugger flags passed between Makefiles
AC_SUBST(OPT)
if test -z "$OPT"
then
	case $GCC in
	yes)
		case $ac_cv_prog_cc_g in
		yes)	OPT="-g -O2 -Wall";;
		*)	OPT="-O2 -Wall";;
		esac
		;;
	*)	OPT="-g -w1";;     # was  "-O -Wall";; changed for icc -per Chris
	esac
fi

if test "$ac_arch_flags"
then
	OPT="$OPT $ac_arch_flags"
fi

AC_SUBST(CLIBS)
if test $ac_cv_prog_gcc = "yes";
then
CLIBS=
else
CLIBS=-lC
fi

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(time.h unistd.h bstring.h vxWorks.h stream.h pthread.h)


AC_CACHE_CHECK("struct timeval in time.h", ac_cv_timeval_in_time_h,
               AC_TRY_COMPILE([#include <time.h>], [struct timeval dummy;],
                              ac_cv_timeval_in_time_h="yes",
                              ac_cv_timeval_in_time_h="no"))
if test $ac_cv_timeval_in_time_h = "yes";
then
AC_DEFINE(TIMEVAL_IN_TIME_H)
fi

AC_CACHE_CHECK("struct timeval in sys/time.h", ac_cv_timeval_in_sys_time_h,
               AC_TRY_COMPILE([#include <sys/time.h>], [struct timeval dummy;],
                              ac_cv_timeval_in_sys_time_h="yes",
                              ac_cv_timeval_in_sys_time_h="no"))
if test $ac_cv_timeval_in_sys_time_h = "yes";
then
AC_DEFINE(TIMEVAL_IN_SYS_TIME_H)
fi

AC_CACHE_CHECK("for usleep", ac_cv_usleep_defined,
               AC_TRY_COMPILE([#include <unistd.h>], [usleep(500); ],
                              ac_cv_usleep_defined="yes",
                              ac_cv_usleep_defined="no"))
if test $ac_cv_usleep_defined = "yes";
then
AC_DEFINE(USLEEP_DEFINED)
fi

if test ! -d ${srcdir}/include/$MACHDEP
then
  mkdir -p ${srcdir}/include/$MACHDEP
fi

dnl Checks for libraries.
dnl Replace `main' with a function in -lm:
AC_CHECK_LIB(m, sin)

AC_SUBST(LIB_DEST_DIR)
if test "$srcdir" = "."
then
LIB_DEST_DIR=lib
else
LIB_DEST_DIR=lib/${MACHDEP}
fi

AC_SUBST(LIB_INSTALL)
LIB_INSTALL=libutils.a

AC_OUTPUT(Makefile)
