dnl Process this file with autoconf to produce a configure script.
dnl This version of log4cplus requires the follwing autotools versions:
dnl autoconf-2.67
dnl automake-1.11.1
dnl libtool-2.2.10

AC_INIT([log4cplus],[1.0.4])
AC_CANONICAL_TARGET
AC_CONFIG_SRCDIR([src/logger.cxx])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.11.1 no-define nostdinc gnu -Wall])

#
# +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=4:0:0
AC_SUBST([LT_VERSION])

dnl Sane locale?

AH_TEMPLATE([LOG4CPLUS_WORKING_LOCALE],
  [Define for compilers/standard libraries that support more than
   just the "C" locale.])

AC_ARG_WITH([working-locale],
  [AS_HELP_STRING([--with-working-locale],
    [Use std::locale for char->wchar_t conversion.])],
  [],
  [with_working_locale=no])

AS_IF([test "x$with_working_locale" = "xyes"],
  [AC_DEFINE([LOG4CPLUS_WORKING_LOCALE], [1])],
  [])

dnl Debugging or release build?

AC_ARG_ENABLE([debugging],
  [AS_HELP_STRING([--enable-debugging],
    [Turns off optimization and adds switches that generate debugging
    information.])],
  [],
  [enable_debugging=no])

AH_TEMPLATE([LOG4CPLUS_DEBUGGING],
  [Defined for --enable-debugging builds.])

AS_IF([test "x$enable_debugging" = "xyes"],
  [AC_DEFINE([LOG4CPLUS_DEBUGGING])
   LOG4CPLUS_NDEBUG=-UNDEBUG],
  [LOG4CPLUS_NDEBUG=-DNDEBUG])
AC_SUBST([LOG4CPLUS_NDEBUG])

dnl Turn warnings on/off?

AC_ARG_ENABLE([warnings],
  [AC_HELP_STRING([--enable-warnings],
    [Use compiler warnings option, e.g. -Wall. Enabled by default.])],
  [],
  [enable_warnings=yes])

dnl first check for c/c++ compilers
AC_PROG_CXX
AC_PROG_CXXCPP
AC_LANG([C++])

AS_CASE(["$target_os"],
  [mingw*],
  [dnl Undefining __STRICT_ANSI__ is a workaround for MinGW
   dnl compilation problem.  C++ <cwchar> header does not compile in
   dnl GCC 4.4.0 because some functions like swprintf() are not
   dnl visible.
   CPPFLAGS="${CPPFLAGS} -U__STRICT_ANSI__"
   CPPFLAGS="${CPPFLAGS} -DWIN32 -D_WIN32"
   use_winsock_sockets=yes])

AM_CONDITIONAL([WINSOCK_SOCKETS], [test "x$use_winsock_sockets" = "xyes"])

dnl Libtool setup.

LT_PREREQ([2.2.6])
LT_INIT([win32-dll])

dnl Check for compiler specifics.

AC_CXX_COMPILER_VENDOR([ac_cxx_compiler_vendor])

AS_CASE([$ac_cxx_compiler_vendor],
  [gnu],
  [AS_IF([test "x$enable_warnings" = "xyes"],
     [AX_CXXFLAGS_GCC_OPTION([-Wall])
      AX_CXXFLAGS_GCC_OPTION([-Wextra])
      dnl The -ansi flag removes declarations of some useful functions
      dnl from headers.
      dnl AX_CXXFLAGS_GCC_OPTION([-ansi])
      AX_CXXFLAGS_GCC_OPTION([-pedantic])
      AX_CXXFLAGS_GCC_OPTION([-Wshadow])])

   AS_IF([test "x$enable_debugging" = "xyes"],
     [AX_CXXFLAGS_GCC_OPTION([-g3])
      AX_CXXFLAGS_GCC_OPTION([-fkeep-inline-functions])],
     [AX_CXXFLAGS_GCC_OPTION([-O2])])

   dnl The --enable-auto-import and --enable-runtime-pseudo-reloc
   dnl options are required for log4cplus to work when compiled with
   dnl Cygwin's GCC 4.3.x.
   AS_CASE(["$target_os"],
     [cygwin*|mingw*],
     [LDFLAGS="${LDFLAGS} -Wl,--enable-auto-import"
      LDFLAGS="${LDFLAGS} -Wl,--enable-runtime-pseudo-reloc"])],

  [sun],
  [AS_IF([test "x$enable_warnings" = "xyes"],
     [AX_CXXFLAGS_SUN_OPTION([+w])])
   AX_CXXFLAGS_SUN_OPTION([-library=stlport4])
   AX_CXXFLAGS_SUN_OPTION([-library=Crun])])

AX_DECLSPEC([LOG4CPLUS_DECLSPEC])
AS_IF([test "x$ac_cv_declspec" = "xyes" || test "x$ac_cv__attribute__visibility" = "xyes"],
  [AS_CASE([$ac_cxx_compiler_vendor],
    [gnu],
    [AS_IF([test "x$ac_cv_declspec" = "xyes" || test "x$ac_cv__attribute__visibility" = "xyes"],
       [AX_CXXFLAGS_GCC_OPTION([-fvisibility=hidden])])])])

dnl Checks for libraries.

AC_SEARCH_LIBS([strerror], [cposix])
AC_SEARCH_LIBS([clock_gettime], [posix4])
AC_SEARCH_LIBS([nanosleep], [rt])
AC_SEARCH_LIBS([gethostent], [nsl])
AC_SEARCH_LIBS([setsockopt], [socket])

dnl Windows/MinGW specific.

AC_LANG_PUSH([C])
AC_HAVE_LIBRARY([kernel32])
AC_HAVE_LIBRARY([advapi32])
AC_HAVE_LIBRARY([ws2_32])
AC_LANG_POP([C])

dnl Checks for header files.

AC_HEADER_STDC

LOG4CPLUS_CHECK_HEADER([sys/types.h], [LOG4CPLUS_HAVE_SYS_TYPES_H])
LOG4CPLUS_CHECK_HEADER([sys/socket.h], [LOG4CPLUS_HAVE_SYS_SOCKET_H])
LOG4CPLUS_CHECK_HEADER([sys/time.h], [LOG4CPLUS_HAVE_SYS_TIME_H])
LOG4CPLUS_CHECK_HEADER([sys/timeb.h], [LOG4CPLUS_HAVE_SYS_TIMEB_H])
LOG4CPLUS_CHECK_HEADER([sys/stat.h], [LOG4CPLUS_HAVE_SYS_STAT_H])
LOG4CPLUS_CHECK_HEADER([syslog.h], [LOG4CPLUS_HAVE_SYSLOG_H])
LOG4CPLUS_CHECK_HEADER([netinet/in.h], [LOG4CPLUS_HAVE_NETINET_IN_H])
LOG4CPLUS_CHECK_HEADER([netdb.h], [LOG4CPLUS_HAVE_NETDB_H])
LOG4CPLUS_CHECK_HEADER([unistd.h], [LOG4CPLUS_HAVE_UNISTD_H])
LOG4CPLUS_CHECK_HEADER([stdio.h], [LOG4CPLUS_HAVE_STDIO_H])
LOG4CPLUS_CHECK_HEADER([wchar.h], [LOG4CPLUS_HAVE_WCHAR_H])
LOG4CPLUS_CHECK_HEADER([stdarg.h], [LOG4CPLUS_HAVE_STDARG_H])
LOG4CPLUS_CHECK_HEADER([time.h], [LOG4CPLUS_HAVE_TIME_H])
LOG4CPLUS_CHECK_HEADER([errno.h], [LOG4CPLUS_HAVE_ERRNO_H])

dnl Checks for library functions.

LOG4CPLUS_CHECK_FUNCS([gmtime_r], [LOG4CPLUS_HAVE_GMTIME_R])
LOG4CPLUS_CHECK_FUNCS([localtime_r], [LOG4CPLUS_HAVE_LOCALTIME_R])
LOG4CPLUS_CHECK_FUNCS([gettimeofday], [LOG4CPLUS_HAVE_GETTIMEOFDAY])
LOG4CPLUS_CHECK_FUNCS([clock_gettime], [LOG4CPLUS_HAVE_CLOCK_GETTIME])
LOG4CPLUS_CHECK_FUNCS([getpid], [LOG4CPLUS_HAVE_GETPID])
LOG4CPLUS_CHECK_FUNCS([ftime], [LOG4CPLUS_HAVE_FTIME])
LOG4CPLUS_CHECK_FUNCS([stat], [LOG4CPLUS_HAVE_STAT])
LOG4CPLUS_CHECK_FUNCS([lstat], [LOG4CPLUS_HAVE_LSTAT])
LOG4CPLUS_CHECK_FUNCS([htons], [LOG4CPLUS_HAVE_HTONS])
LOG4CPLUS_CHECK_FUNCS([ntohs], [LOG4CPLUS_HAVE_NTOHS])
LOG4CPLUS_CHECK_FUNCS([htonl], [LOG4CPLUS_HAVE_HTONL])
LOG4CPLUS_CHECK_FUNCS([ntohl], [LOG4CPLUS_HAVE_NTOHL])

AH_TEMPLATE([LOG4CPLUS_HAVE_ENAMETOOLONG])
AC_CACHE_CHECK([for ENAMETOOLONG], [ax_cv_have_enametoolong],
  [AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([#include <errno.h>], [int value = ENAMETOOLONG;])],
    [ax_cv_have_enametoolong=yes],
    [ax_cv_have_enametoolong=no])])
AS_IF([test "x$ax_cv_have_enametoolong" = "xyes"],
  [AC_DEFINE([LOG4CPLUS_HAVE_ENAMETOOLONG])])

AH_TEMPLATE([LOG4CPLUS_HAVE_GETADDRINFO])
AX_GETADDRINFO
AS_IF([test "x$ax_cv_have_getaddrinfo" = "xyes"],
  [AC_DEFINE([LOG4CPLUS_HAVE_GETADDRINFO])])

AH_TEMPLATE([LOG4CPLUS_HAVE_GETHOSTBYNAME_R])
AX_GETHOSTBYNAME_R
AS_IF([test "x$ax_cv_have_gethostbyname_r" = "xyes"],
  [AC_DEFINE([LOG4CPLUS_HAVE_GETHOSTBYNAME_R])])

dnl Check for the existance of type socklen_t.
TYPE_SOCKLEN_T


dnl Check for single-threaded compilation

AH_TEMPLATE([LOG4CPLUS_USE_PTHREADS])

AC_ARG_ENABLE([threads],
  [AS_HELP_STRING([--enable-threads=yes/no],
    [Use this option to create a singled-threaded version of this library])],
  [AS_CASE(["${enableval}"],
    [yes], [],
    [no], [],
    [AC_MSG_ERROR([bad value ${enableval} for --enable-threads])])],
  [enable_threads=yes])

AS_IF([test x$enable_threads = xyes],
  [AC_MSG_NOTICE([Creating a multi-threaded library.])

   CPPFLAGS="$CPPFLAGS -D_REENTRANT"

   AS_CASE(["$target_os"],
     [mingw*], [],
     [ACX_PTHREAD([],
       [AC_MSG_ERROR([Requested threads support but no threads were found.])])])

   CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
   CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
   LIBS="$PTHREAD_LIBS $LIBS"],

  [AC_MSG_NOTICE([Creating a single-threaded library])
   AC_DEFINE([LOG4CPLUS_SINGLE_THREADED], [1],
     [Define if this is a single-threaded library.])])

AM_CONDITIONAL([MULTI_THREADED], [test x$enable_threads = xyes])

AH_TOP([#ifndef LOG4CPLUS_CONFIG_H])
AH_TOP([#define LOG4CPLUS_CONFIG_H])
AH_BOTTOM([#endif // LOG4CPLUS_CONFIG_H])

AC_CONFIG_HEADERS([include/log4cplus/config.h])
AC_CONFIG_HEADERS([include/log4cplus/config/defines.hxx])
AC_CONFIG_FILES([Makefile
           include/Makefile
           src/Makefile
           loggingserver/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
           tests/timeformat_test/Makefile])
AC_OUTPUT
