dnl
dnl
dnl     This file is an input file used by the GNU "autoconf" program to
dnl     generate the file "configure", which in turn produces the files
dnl     "Makefile"
dnl	If you don't have autoconf installed, simply use the "configure"
dnl	script.
dnl     Usage: 
dnl	  $ autoconf configure.in
dnl       $ ./configure -with-config=site.config
dnl
dnl     email: Olivier.Arsac@sophia.inria.fr
dnl
dnl
dnl  Some pieces have been borowed from tcl that seems to have
dnl  adressed a lot of uncommon but annoying problems



dnl This is the file that must exist in srcdir
AC_INIT(OM.h)

dnl Set prefix for install
if test "${prefix}" = "NONE"; then
    prefix=/usr/local
fi
if test "${exec_prefix}" = "NONE"; then
    exec_prefix=$prefix
fi

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AC_PROG_RANLIB
AC_PROG_INSTALL

dnl Checks for libraries.
#--------------------------------------------------------------------
#       Check for the existence of the -lsocket and -lnsl libraries.
#       The order here is important, so that they end up in the right
#       order in the command line generated by make.  Here are some
#       special considerations:
#       1. Use "connect" and "accept" to check for -lsocket, and
#          "gethostbyname" to check for -lnsl.
#       2. Use each function name only once:  can't redo a check because
#          autoconf caches the results of the last check and won't redo it.
#       3. Use -lnsl and -lsocket only if they supply procedures that
#          aren't already present in the normal libraries.  This is because
#          IRIX 5.2 has libraries, but they aren't needed and they're
#          bogus:  they goof up name resolution if used.
#       4. On some SVR4 systems, can't use -lsocket without -lnsl too.
#          To get around this problem, check for both libraries together
#          if -lsocket doesn't work by itself.tcl
 #--------------------------------------------------------------------

checkBoth=0
AC_CHECK_FUNC(connect, checkSocket=0, checkSocket=1)
if test "$checkSocket" = 1; then
    AC_CHECK_LIB(socket, main, LIBSSOCK="-lsocket", checkBoth=1)
fi
if test "$checkBoth" = 1; then
    oldLibs=$LIBSSOCK
    LIBSSOCK="$LIBSSOCK -lsocket -lnsl"
    AC_CHECK_FUNC(accept, checkNsl=0, [LIBSSOCK=$oldLibs])
fi
AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBSSOCK="$LIBSSOCK -lnsl"]))
AC_SUBST([LIBSSOCK])


dnl
dnl   Checks for header files.
dnl

AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h strings.h sys/time.h unistd.h)


#--------------------------------------------------------------------
#       Include sys/select.h if it exists and if it supplies things
#       that appear to be useful and aren't already in sys/types.h.
#       This appears to be true only on the RS/6000 under AIX.  Some
#       systems like OSF/1 have a sys/select.h that's of no use, and
#       other systems like SCO UNIX have a sys/select.h that's
#       pernicious.  If "fd_set" isn't defined anywhere then set a
#       special flag.
#--------------------------------------------------------------------

AC_MSG_CHECKING([fd_set and sys/select])
AC_TRY_COMPILE([#include <sys/types.h>],
        [fd_set readMask, writeMask;], ok=yes, ok=no)
if test $ok = no; then
    AC_HEADER_EGREP(fd_mask, sys/select.h, ok=yes)
    if test $ok = yes; then
        AC_DEFINE(HAVE_SYS_SELECT_H)
    fi
fi
AC_MSG_RESULT($ok)
if test $ok = no; then
    AC_DEFINE(NO_FD_SET)
fi


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

dnl Checks for library functions.
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(gethostname select socket strdup strtod strtol)

dnl Misc

ARFLAGS="ruv"
AC_SUBST([ARFLAGS])
test "$CC" = "gcc" && SYS_CFLAGS="$SYS_CFLAGS -pipe -Wall"
AC_SUBST([SYS_CFLAGS])

AC_CONFIG_HEADER(OMconfig.h:OMconfig.hin)
AC_OUTPUT(Makefile, [date > stamp-h])
