dnl Process this file with autoconf to produce a configure script.

dnl Prolog
AC_INIT(main.C)
AC_PREREQ(2.54)
AC_CONFIG_HEADERS(dxpcconf.h)
AC_CONFIG_FILES(Makefile)

dnl Allow user to specify the location of the LZO library
AC_ARG_WITH(lzo-lib,
[  --with-lzo-lib=DIR	  specify location of LZO library ],
[CXXFLAGS="$CXXFLAGS -I$withval/include"
 CPPFLAGS="$CPPFLAGS -I$withval/include"
 LDFLAGS="$LDFLAGS -L$withval/lib -R$withval/lib"])

dnl Checks for programs.
AC_PROG_CXX
AC_LANG_CPLUSPLUS
AC_PROG_INSTALL

dnl MingW hackery: we need the winsock library, and
dnl for some reason the compiler detection macro of doom
dnl doesn't set -O2 on MingW.
AC_CANONICAL_HOST
HOST=$host_os

dnl hack: if we are using a Mingw cross-compiler, we pretend the host is
dnl mingw.
$CC -v 2>&1 | grep -q -e mingw-special
if test "$?" -eq "0"; then
	HOST=mingw
fi

case $HOST in
  *mingw* ) LIBS="$LIBS -lwsock32";CXXFLAGS="$CXXFLAGS -O2";MINGW32="true";;
  * ) MINGW32="false";;
esac
AC_SUBST(MINGW32)

dnl Checks for header files.
AC_PATH_XTRA

dnl The version 2 LZO library puts its include files in a path prefixed with
dnl lzo/ just for added convienience.
AC_CHECK_LIB(lzo2, lzo_version,
             [LIBS="$LIBS -llzo2"; LZO_INCLUDE_PREFIX="lzo/"; CXXFLAGS="$CXXFLAGS -DLZO2"],
             [AC_CHECK_LIB(lzo, lzo_version,
                           [LIBS="$LIBS -llzo"; LZO_INCLUDE_PREFIX=""],
                           AC_MSG_ERROR(
[lzo library required: you may need to use the --with-lzo-lib
option to specify path to LZO if it is installed in a non-standard
directory.]))])

# The LZO installer likes to put headers in /usr/local/include, even on
# systems where that is not searched. Try to be nice and detect this case...
AC_CHECK_HEADER(${LZO_INCLUDE_PREFIX}lzoconf.h, ,
 [AC_CHECK_HEADER(/usr/local/include/${LZO_INCLUDE_PREFIX}lzoconf.h,
		   [CXXFLAGS="$CXXFLAGS -I/usr/local/include"],
		   AC_MSG_ERROR([lzoconf.h required (part of LZO library)]))])

AC_DEFUN(dxpc_ACCEPT_LENGTH_T,
 [AC_CACHE_CHECK([for type of accept's length pointer parameter],
   dxpc_cv_accept_length_type,
   [dxpc_cv_accept_length_type=no
    for ac_val in int size_t socklen_t; do
      AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>],
        [struct sockaddr a; $ac_val len; accept (0, &a, &len);],
        [dxpc_cv_accept_length_type=$ac_val; break])
    done])

  if test $dxpc_cv_accept_length_type != no; then
    AC_DEFINE_UNQUOTED(ACCEPT_SOCKLEN_T, $dxpc_cv_accept_length_type,
      [Define to be the type of accept's length parameter (without the \*').])
  fi
 ]
)

dxpc_ACCEPT_LENGTH_T

# Check to see if we have <iostream> or <iostream.h>. We'd better have one
# or the other.
AC_CHECK_HEADER(iostream, AC_DEFINE(HAVE_IOSTREAM),
		[AC_CHECK_HEADER(iostream.h, AC_DEFINE(HAVE_IOSTREAM_H),
		AC_MSG_ERROR([Cannot find iostream or iostream.h]))])

AC_OUTPUT
