AC_INIT([log4cpp],[1.1.6])

# autoconf 2.50 minimum required until 2025 to rebuild aclocal.m4, because the
# AC_CREATE_PREFIX_CONFIG_H macro needs the AS_DIRNAME macro; since then only
# few uses of modern macros are added
AC_PREREQ([2.59])

#
# +1 : ? : +1  == new interface that does not break old one
# +1 : ? : 0   == new interface 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=5:6:0

AC_SUBST(LT_VERSION)

#AC_CONFIG_SRCDIR(configure.in)
AC_CONFIG_AUX_DIR(config)
AM_CONFIG_HEADER(include/config.h)
# Autotools 2.63+ automatically handle the m4 directory, earlier fallback to AC_SUBST
m4_ifdef([AC_CONFIG_MACRO_DIR],
  [AC_CONFIG_MACRO_DIR([m4])],
  [AC_SUBST([ACLOCAL_AMFLAGS], ["-I m4"])]
)

AM_INIT_AUTOMAKE

# General "with" options
# ----------------------------------------------------------------------------
AC_ARG_WITH(idsa, [  --with-idsa             include idsa support])

# Checks for programs
# ----------------------------------------------------------------------------
AC_CANONICAL_HOST

AC_ARG_ENABLE(debug,
    AS_HELP_STRING([--enable-debug],[Have GCC compile with symbols (Default = no)]),
                   enable_debug=$enableval, enable_debug=no)

if test "$enable_debug" = "yes" ; then
    GCC_CFLAGS="$CFLAGS -g -D_DEBUG"
    GCC_CXXFLAGS="$CXXFLAGS -g -D_DEBUG"
else
    GCC_CFLAGS="$CFLAGS"
    GCC_CXXFLAGS="$CXXFLAGS"
fi

m4_ifdef([LT_INIT],
  [LT_INIT],
  [AM_PROG_LIBTOOL]
)
AC_PROG_INSTALL
AC_PROG_MAKE_SET

AC_PROG_CXX([g++ c++ gpp aCC CC cxx cc++ cl FCC KCC RCC xlC_r xlC QCC])

if test "$GCC" = "yes" ; then
    CFLAGS="$GCC_CFLAGS"
    CXXFLAGS="$GCC_CXXFLAGS"
fi 

AC_PROG_CXXCPP
AC_LANG(C)

# Checks header files
# ----------------------------------------------------------------------------
AC_CHECK_HEADERS([unistd.h])
AC_CHECK_HEADERS([io.h])

# Checks local idioms
# ----------------------------------------------------------------------------
AC_C_INT64_T
AC_FUNC_SNPRINTF

# syslog_test
AC_CHECK_FUNCS([syslog])
AC_CHECK_FUNCS([gettimeofday])
AC_CHECK_FUNCS([ftime])
AC_CHECK_FUNCS([localtime_r])

# Checks for libraries
# ----------------------------------------------------------------------------

# checks for pthreads
ACX_PTHREAD([enable_threads="pthread"],[enable_threads="no"])
if test $enable_threads != "pthread"; then
    AC_MSG_ERROR([unable to find pthreads, currently this is required])
else
    AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
    AC_DEFINE(HAVE_THREADING,1,[define if threading is enabled])
    AC_DEFINE(USE_PTHREADS,1,[define if pthread library is available])
    LIBS="$PTHREAD_LIBS $LIBS"
    CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
    CXXFLAGS="$PTHREAD_CFLAGS $CXXFLAGS"
fi

AC_LANG(C++)
AC_CXX_HAVE_SSTREAM

# idsa_test
if test "x$with_idsa" = xyes; then
    AC_CHECK_LIB([idsa], [idsa_open])
    if test "$ac_cv_lib_idsa_idsa_open" = no; then
        AC_MSG_ERROR([could not locate idsa library])
    fi
fi

# check for doxygen
# ----------------------------------------------------------------------------
BB_ENABLE_DOXYGEN

# check for omnithreads
#BB_CHECK_OMNITHREADS
#BB_CHECK_PTHREADS

LOG4CPP_CFLAGS="$CXXFLAGS"
LOG4CPP_LIBS="-llog4cpp"
LOG4CPP_LIBDEPS="$LIBS"
LOG4CPP_VERSION="$VERSION"

# CXX fine tuning
case "$host" in
    *-dec-osf*)	  
	CXXFLAGS="$CXXFLAGS -std strict_ansi_errors" 
	;;
    *)	
	;;
esac

PETI_PEDANTIC_GCC
BB_ENABLE_REMOTE_SYSLOG
BB_ENABLE_SMTP

# Create files
# ----------------------------------------------------------------------------

AC_CONFIG_LIBCONFIG_IN([log4cpp])
AC_CONFIG_PKGCONFIG_IN([log4cpp], [C++ library for flexible logging, modeled after Log4j])

AC_CONFIG_FILES([
Makefile
log4cpp.spec
log4cpp.pc
log4cpp-config
config/Makefile
doc/Makefile
doc/Doxyfile
doc/html/Makefile
src/Makefile
include/Makefile
include/log4cpp/Makefile
include/log4cpp/threading/Makefile
tests/Makefile
])
AC_OUTPUT

AC_CREATE_PREFIX_CONFIG_H([include/log4cpp/config.h], 
        $PACKAGE_TARNAME, [include/config.h])
