-dnl ------ Threads
-AC_ARG_ENABLE(threads, [ --enable-threads enable threads if available])
-if test "$enable_threads" = "yes"; then
- AC_CHECK_HEADERS(pthread.h threads.h)
- AC_CHECK_FUNC(pthread_mutex_lock)
- if test "$ac_cv_func_pthread_mutex_lock" = "no"; then
- AC_CHECK_LIB(pthread, main)
+AC_SUBST(LIBTHREAD)
+AC_SUBST(CFLAGSTHREADS)
+HAVETHREADS=0
+CFLAGSTHREADS=""
+LIBTHREAD=""
+dnl
+dnl ------ GNU threads
+AC_ARG_ENABLE(pth, [ --enable-pth enable GNU threads],[enable_pth=$enableval],[enable_pth=no])
+AC_SUBST(LIBPTH)
+if test "$enable_pth" = "yes"; then
+ OLIBS=$LIBS
+ AC_CHECK_LIB(pth,main)
+ if test "$ac_cv_lib_pth_main" = "yes"; then
+ AC_CHECK_HEADERS(pth.h)
+ if test "$ac_cv_header_pth_h" = "yes"; then
+ LIBTHREAD="-lpth"
+ CFLAGSTHREADS="-DYAZ_GNU_THREADS=1"
+ HAVETHREADS=1
+ fi
+ fi
+ LIBS=$OLIBS
+fi
+dnl
+dnl ------ POSIX Threads
+AC_ARG_ENABLE(threads, [ --disable-threads disable POSIX threads],[enable_threads=$enableval],[enable_threads=yes])
+if test "$enable_threads" = "yes" -a "$HAVETHREADS" = "0"; then
+ OLIBS=$LIBS
+ OCC=$CC
+ AC_CHECK_LIB(pthread,main)
+ AC_MSG_CHECKING(for working POSIX Threads)
+ AC_TRY_LINK([#include <pthread.h>
+ void *func(void *p) { return 0; }
+ ],[
+ pthread_t pthread_id;
+ pthread_create (&pthread_id, 0, func, 0);],
+ thread_ok=yes,thread_ok=no)
+ if test "$thread_ok" = "yes"; then
+ AC_MSG_RESULT(yes)
+ LIBTHREAD="-lpthread"
+ CFLAGSTHREADS="-DYAZ_POSIX_THREADS=1 -D_REENTRANT"
+ HAVETHREADS=1
+ else
+ CC="$CC -pthread"
+ AC_TRY_LINK([#include <pthread.h>
+ void *func(void *p) { return 0; }
+ ],[
+ pthread_t pthread_id;
+ pthread_create (&pthread_id, 0, func, 0);],
+ thread_ok=yes,thread_ok=no)
+ if test "$thread_ok" = "yes"; then
+ AC_MSG_RESULT([yes,BSD])
+ CFLAGSTHREADS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
+ LIBTHREAD="-pthread"
+ HAVETHREADS=1
+ fi
+ fi
+ if test "$thread_ok" = "no"; then
+ AC_MSG_RESULT(no)