dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/logger.cxx)
AM_INIT_AUTOMAKE(log4cplus, 1.0)
AM_CONFIG_HEADER(include/log4cplus/config.h)

#
# +1 : ? : +1  == new interface that does not break old one
# +1 : ? : 0   == new interfac that breaks old one
#  ? : ? : 0   == no new interfaces, but breaks apps
#  ? :+1 : ?   == just some internal changes, nothing breaks but might work
#                 better
# CURRENT : REVISION : AGE
LT_VERSION=2:0:0
AC_SUBST(LT_VERSION)

AC_PROG_LIBTOOL

dnl Checks for programs.
AC_ISC_POSIX

dnl first check for c/c++ compilers
AC_PROG_CXX
AC_PROG_CXXCPP
AC_LANG_CPLUSPLUS

dnl Checks for libraries.
AC_PROG_RANLIB 
AC_CHECK_LIB(rt, nanosleep)
dnl AC_CHECK_LIB(socket, accept)
dnl AC_CHECK_LIB(nsl, gethostent)
AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))

dnl Checks for header files.
AC_STDC_HEADERS
AC_HAVE_HEADERS(strstream.h strstream sstream syslog.h)

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_STRFTIME
AC_STRUCT_TM
AC_CHECK_FUNCS(gmtime_r)
AC_CHECK_FUNCS(localtime_r)
AC_CHECK_FUNCS(gettimeofday)
AC_CHECK_FUNCS(ftime)
AC_CHECK_FUNCS(stat)
AC_CHECK_FUNCS(lstat)

dnl Check for the existance of type socklen_t.
AC_DEFUN([TYPE_SOCKLEN_T],
[AC_CACHE_CHECK([for socklen_t], ac_cv_type_socklen_t,
[
  AC_TRY_COMPILE(
  [#include <sys/types.h>
   #include <sys/socket.h>],
  [socklen_t len = 42; return 0;],
   ac_cv_type_socklen_t=yes,
   ac_cv_type_socklen_t=no)
])
  if test $ac_cv_type_socklen_t != yes; then
    AC_DEFINE(socklen_t, int)
  fi
])
TYPE_SOCKLEN_T
		

dnl Check for single-threaded compilation
AC_ARG_ENABLE(threads,
 [ --enable-threads=[yes/no]  Use this option to create a singled-threaded \
  version of this library],
[case "${enableval}" in
  yes) multi_threaded=true ;;
  no)  multi_threaded=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-threads) ;;
 esac],[multi_threaded=true])

if test x$multi_threaded = xtrue ; then
    echo "****************************************"
    echo "Creating a multi-threaded library"
    echo "****************************************"
    CPPFLAGS="$CPPFLAGS -D_REENTRANT"
    AC_CHECK_LIB(pthread, pthread_create)
    AC_CHECK_LIB(pthreads, pthread_create)
    AC_CHECK_LIB(rt, nanosleep)
else
    echo "****************************************"
    echo "Creating a single-threaded library"
    echo "****************************************"
    AC_DEFINE(LOG4CPLUS_SINGLE_THREADED, 1,
              [Define if this is a single-threaded library.])
fi
AM_CONDITIONAL(MULTI_THREADED, test x$multi_threaded = xtrue)

AC_OUTPUT([Makefile 
           src/Makefile 
           tests/Makefile 
           tests/appender_test/Makefile 
           tests/configandwatch_test/Makefile 
           tests/customloglevel_test/Makefile 
           tests/fileappender_test/Makefile 
           tests/filter_test/Makefile 
           tests/hierarchy_test/Makefile 
           tests/loglog_test/Makefile 
           tests/ndc_test/Makefile 
           tests/ostream_test/Makefile
           tests/patternlayout_test/Makefile 
           tests/performance_test/Makefile 
           tests/priority_test/Makefile 
	   tests/propertyconfig_test/Makefile
	   tests/socket_test/Makefile
           tests/thread_test/Makefile ])

