dnl Configure the zthread library. 

AC_INIT(README)
AC_PREREQ(2.13)

ZT_MAJOR_VERSION=2
ZT_MINOR_VERSION=0
ZT_MICRO_VERSION=5
ZT_INTERFACE_AGE=1
ZT_BINARY_AGE=1
ZT_VERSION=$ZT_MAJOR_VERSION.$ZT_MINOR_VERSION.${ZT_MICRO_VERSION}

AC_SUBST(ZT_MAJOR_VERSION)
AC_SUBST(ZT_MINOR_VERSION)
AC_SUBST(ZT_MICRO_VERSION)
AC_SUBST(ZT_INTERFACE_AGE)
AC_SUBST(ZT_BINARY_AGE)
AC_SUBST(ZT_VERSION)

dnl prepare version info

LT_RELEASE=$ZT_MAJOR_VERSION.$ZT_MINOR_VERSION
LT_CURRENT=`expr $ZT_MICRO_VERSION - $ZT_INTERFACE_AGE`
LT_REVISION=$ZT_INTERFACE_AGE
LT_AGE=`expr $ZT_BINARY_AGE - $ZT_INTERFACE_AGE`

AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)


AM_INIT_AUTOMAKE(ZThread, $ZT_VERSION)
AM_CONFIG_HEADER(src/config.h:src/config.h.in)
AM_ACLOCAL_INCLUDE(share)

dnl Check for debug-mode
CFLAGS="-Wall -DNDEBUG $CFLAGS"
AC_ARG_ENABLE(debug, 
[  --enable-debug          Enable debug symbols [default=no]],CFLAGS="-Wall -g")

dnl Switch to a valid more for checks
AC_PROG_CC

AM_WITH_PTHREAD_INFO
AM_WITH_DOXYGEN


dnl Switch to C++ mode and check for needed C++ headers

AC_ISC_POSIX
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_CXXCPP

AC_LANG_SAVE
AC_LANG_CPLUSPLUS

dnl Header check
AC_HEADER_STDC
AC_CHECK_HEADERS(errno.h unistd.h)

dnl Include examples
SUBDIRS="src include"
AC_ARG_ENABLE(examples, [  --enable-examples       Include examples in the project build. [default=yes]],, SUBDIRS="$SUBDIRS examples")

dnl Enable test suite
dnl AC_ARG_ENABLE(tests, [  --enable-tests      Build and run the testsuite. [default=yes]],, SUBDIRS="$SUBDIRS tests")

dnl Enable stress - for testing
AC_ARG_ENABLE(stress,     [  --enable-stress         Enable random stress [default=no]],AC_DEFINE(USE_STRESS))

dnl Enable priorities
AC_ARG_ENABLE(priorities, [  --enable-priorities     Enable pthreads priorities [default=no]],, AC_DEFINE(DISABLE_THREAD_PRIO))

dnl Disable IO interrupt w/ signal mechanism
AC_ARG_ENABLE(io-interrupts, [  --enable-io-interrupts  Enable I/O interrupts with signals [default=no]],, AC_DEFINE(DISABLE_IO_INTERRUPT))


dnl Check for setsigjmp
AC_MSG_CHECKING(for sigsetjmp())
AC_TRY_LINK( [#include <setjmp.h>], [sigjmp_buf t; sigsetjmp(t, 0);],
[AC_MSG_RESULT(yes)], 
[AC_MSG_RESULT(no)
 AC_DEFINE(DISABLE_IO_INTERRUPT)
])

dnl Check for ftime
AC_MSG_CHECKING(for ftime())
AC_TRY_LINK( [#include <sys/timeb.h>], [struct timeb t; ftime(&t);],
[AC_MSG_RESULT(yes)
 AC_DEFINE(HAVE_FTIME)
], 
[AC_MSG_RESULT(no)])

ZT_LIBS=ZT_LDFLAGS
ZT_LDFLAGS="$PTHREAD_LIBS"
ZT_CXXFLAGS="$PTHREAD_CFLAGS -D_POSIX"

AC_SUBST(ZT_LDFLAGS)
AC_SUBST(ZT_LIBS)
AC_SUBST(ZT_CXXFLAGS)

dnl add some variables users can customize
AC_SUBST(EXTRA_LDFLAGS)
AC_SUBST(EXTRA_CXXFLAGS)

AM_PROG_LIBTOOL


AC_SUBST(SUBDIRS)

AC_OUTPUT(Makefile src/Makefile include/Makefile examples/Makefile share/zthread-config share/zthread.spec)
