AC_INIT(xtide.cc)
AC_LANG_CPLUSPLUS

echo ""
echo "NOTE:  You may embellish the compile and link lines by setting"
echo "extracxxflags and extraldflags before running configure.  For example,"
echo "to search /mumble/foo/include for include files, you could do"
echo "   extracxxflags=\"-I/mumble/foo/include\" ./configure"
echo "under the Bourne shell."
echo ""

AC_PROG_CXX
AC_SUBST(bindir)
AC_SUBST(acceptarg3_t)
AC_SUBST(xroot)
AC_SUBST(extralibs)
AC_SUBST(extraswitches)
AC_SUBST(extracxxflags)
AC_SUBST(extraldflags)

extraswitches=""
extralibs=""

AC_MSG_CHECKING([for HP aCC extra switches and libs])
if test "$CXX" = "aCC"; then
  extraswitches="-Wc,-koenig_lookup,on +DAportable -I/opt/aCC/include/iostream"
  extralibs="-lPW"
  AC_MSG_RESULT("yes")
else
  AC_MSG_RESULT("no")
fi

AC_MSG_CHECKING([location of X11])
xroot="NOT FOUND"
for dir in "/usr/X11R6" "/usr/openwin" "/usr/contrib/X11R6" "/usr"; do
  if test -r "$dir/lib/libXaw.so"; then xroot="$dir"; break; fi
done
AC_MSG_RESULT($xroot)
if test "$xroot" = "NOT FOUND"; then
  AC_MSG_WARN("Type \'make tide\' or \'make xttpd\' to compile without X11.")
  xroot="/usr"
fi

AC_MSG_CHECKING([for extra Solaris libs])
if test -r /usr/lib/libsocket.a; then
  extralibs="-lsocket -lnsl"
  AC_MSG_RESULT($extralibs)
else
  AC_MSG_RESULT("no")
fi

AC_MSG_CHECKING([type of third argument to accept()])
AC_TRY_COMPILE(
  [#include <sys/types.h>
#include <sys/socket.h>],
  [socklen_t length;
   struct sockaddr addr;
   int listen_socket;
   accept (listen_socket, &addr, &length);],
  [AC_DEFINE(acceptarg3_t, socklen_t)
   AC_MSG_RESULT(socklen_t)
  ],
  [
    AC_TRY_COMPILE(
      [#include <sys/types.h>
#include <sys/socket.h>],
      [int length;
       struct sockaddr addr;
       int listen_socket;
       accept (listen_socket, &addr, &length);],
      [AC_DEFINE(acceptarg3_t, int)
       AC_MSG_RESULT(int)
      ],
      [AC_DEFINE(acceptarg3_t, size_t)
       AC_MSG_RESULT(size_t)
      ]
    )
])

AC_OUTPUT(Makefile)
