dnl
dnl Configuration script for client
dnl
dnl $Id: configure.in,v 1.1 2001-07-11 15:17:40 legros Exp $
dnl 

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

AC_INIT(src/client.cpp)

MAJOR_VERSION=0
MINOR_VERSION=2
PICO_VERSION=0

AM_INIT_AUTOMAKE(client, $MAJOR_VERSION.$MINOR_VERSION.$PICO_VERSION)

AM_CONFIG_HEADER(config.h)


dnl The following hack should ensure that configure doesn't add optimizing
dnl or debugging flags to CFLAGS or CXXFLAGS
CFLAGS="$CFLAGS "
CXXFLAGS="$CXXFLAGS "


dnl ====================================================================
dnl Checks for programs.

AC_PROG_MAKE_SET

AC_PROG_CC
AC_PROG_CXX

AM_SANITY_CHECK

AC_PROG_INSTALL


dnl ====================================================================
dnl Configure Settings

AC_LANG_CPLUSPLUS


dnl ====================================================================
dnl Checks for typedefs, structures, and compiler characteristics.


dnl ====================================================================
dnl Checks for header files.

AC_STDC_HEADERS
AC_CHECK_HEADERS(fcntl.h unistd.h)


dnl ==========
dnl X11
dnl ==========

AC_PATH_X

if test ! "$no_x" = "yes" ; then
    if test ! X"$x_libraries" = X ; then
        LIBS="$LIBS -L$x_libraries"
    fi
    if test ! X"$x_includes" = X ; then
        CXXFLAGS="$CXXFLAGS -I$x_includes"
    fi
else
    AC_MSG_ERROR(X11 must be installed.)
fi


dnl ==========
dnl STLPort
dnl ==========

dnl Ask user for path to the STLport header files
AC_ARG_WITH( stlport,
    [  --with-stlport=<path>   path to the STLPort header files directory.
                          e.g. /usr/local/include/stlport],
    [STLPORT_DIR=$with_stlport
      AC_MSG_RESULT(using STLPort header files located in $with_stlport)],
    AC_MSG_ERROR([You must call configure with the --with-stlport option.
    This tells configure where to find the STLPort header files.
    e.g. --with-stlport=/usr/local/include/stlport])
)

if test X"$STLPORT_DIR" != X"";
then
    CXXFLAGS="-I$STLPORT_DIR $CXXFLAGS"
fi

dnl Ask user for path to the STLPort library files
AC_ARG_WITH( stllib,
    [  --with-stllib=<path>    path to the STLPort installation directory.
                          e.g. /usr/local/lib/stlport],
    [STLLIB_DIR=$with_stllib
      AC_MSG_RESULT(using STLPort library located in $with_stllib)]
)

if test X"$STLLIB_DIR" != X"";
then
    LIBS="-L$STLLIB_DIR $LIBS"
fi

LIBS="$LIBS -lstlport_gcc"

_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CXXFLAGS"

AC_MSG_CHECKING(for STLPort)
AC_EGREP_CPP( yo_stlport,
[#include <algorithm>
#ifdef __SGI_STL_PORT
   yo_stlport
#endif],
[AC_MSG_RESULT(yes)],
AC_MSG_ERROR([STLPort is needed to compile the client (www.stlport.org)])
)

CPPFLAGS="$_CPPFLAGS"


dnl ==========
dnl NeL
dnl ==========

dnl Ask user for path to the NeL header files
AC_ARG_WITH( nel,
    [  --with-nel=<prefix>     prefix to the NeL files installation.
                          e.g. /usr/local/include],
    [NEL_DIR=$with_nel
      AC_MSG_RESULT(using NeL header files located in $with_nel)]
)

if test X"$NEL_DIR" != X"";
then
    CXXFLAGS="-I$NEL_DIR/include $CXXFLAGS"
    LIBS="-L$NEL_DIR/lib $LIBS"
fi

_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CXXFLAGS"

AC_MSG_CHECKING(for NeL)
AC_EGREP_CPP( yo_nel,
[#include <nel/net.h>
#ifdef NL_NET_H
   yo_nel
#endif],
[AC_MSG_RESULT(yes)],
AC_MSG_ERROR([NeL is needed to compile the client (www.nevrax.org)])
)


dnl ==========
dnl FreeType 2
dnl ==========

dnl Check for the FreeType 2 library files
AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, no)

if test "$FREETYPE_CONFIG" = "no"; then
    AC_MSG_ERROR([Cannot find freetype-config: check your path.
    FreeType 2 library is needed to compile the client (www.freetype.org).])
else
    FREETYPE_CFLAGS=`freetype-config --cflags`
    FREETYPE_LIBS=`freetype-config --libs`
fi

dnl CXXFLAGS="$CXXFLAGS ${FREETYPE_CFLAGS}"
dnl LIBS="$LIBS ${FREETYPE_LIBS}"
AC_SUBST(FREETYPE_CFLAGS)
AC_SUBST(FREETYPE_LIBS)

dnl Checking the FreeType 2 instalation
_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CXXFLAGS ${FREETYPE_CFLAGS}"

AC_MSG_CHECKING(for FreeType 2 installation)
AC_EGREP_CPP( yo_freetype2,
[#include <freetype/freetype.h>
#if FREETYPE_MAJOR == 2
   yo_freetype2
#endif],
[AC_MSG_RESULT(yes)],
AC_MSG_ERROR([Freetype 2 library is needed to compile the client (www.stlport.org).])
)

CPPFLAGS="$_CPPFLAGS"


dnl ==========
dnl Debug/optimized compilation mode
dnl ==========

MAX_C_OPTIMIZE="-O6"

dnl Build optimized or debug version ?
dnl First check for gcc and g++
if test "$ac_cv_prog_gcc" = "yes"
then
  DEBUG_CFLAGS="-g"
  DEBUG_OPTIMIZE_CC="-O"
  OPTIMIZE_CFLAGS="$MAX_C_OPTIMIZE"
else
  DEBUG_CFLAGS="-g"
  DEBUG_OPTIMIZE_CC=""
  OPTIMIZE_CFLAGS="-O"
fi
if test "$ac_cv_prog_cxx_g" = "yes"
then
  DEBUG_CXXFLAGS="-g"
  DEBUG_OPTIMIZE_CXX="-O"
  OPTIMIZE_CXXFLAGS="-O3"
else
  DEBUG_CXXFLAGS="-g"
  DEBUG_OPTIMIZE_CXX=""
  OPTIMIZE_CXXFLAGS="-O"
fi
AC_ARG_WITH(debug,
    [  --with-debug[=full]     Build a debug version (huge libraries)
  --without-debug         Build withoug debugging code (default)],
    [with_debug=$withval],
    [with_debug=no])
if test "$with_debug" = "yes"
then
  dnl Medium debug.
  CFLAGS="$DEBUG_CFLAGS $DEBUG_OPTIMIZE_CC $CFLAGS"
  CXXFLAGS="$DEBUG_CXXFLAGS $DEBUG_OPTIMIZE_CXX $CXXFLAGS"
elif test "$with_debug" = "full"
then
  dnl Full debug. Very slow in some cases
  CFLAGS="$DEBUG_CFLAGS $CFLAGS"
  CXXFLAGS="$DEBUG_CXXFLAGS $CXXFLAGS"
else
  dnl Optimized version. No debug
  CFLAGS="$OPTIMIZE_CFLAGS $CFLAGS"
  CXXFLAGS="$OPTIMIZE_CXXFLAGS $CXXFLAGS"
fi


dnl ====================================================================
dnl Checks for libraries.


dnl ====================================================================
dnl Checks for library functions.


dnl ====================================================================
dnl Output files to generate.

AC_OUTPUT( Makefile     \
           src/Makefile \
)


dnl End of configure.in