- 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"
- THREAD_CFLAGS="-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])
- THREAD_CFLAGS="-pthread -DYAZ_POSIX_THREADS=1 -D_REENTRANT"
- LIBTHREAD="-pthread"
- HAVETHREADS=1
- fi
- fi
- if test "$thread_ok" = "no"; then
- AC_MSG_RESULT(no)
- fi
- CC=$OCC
- LIBS="$OLIBS $LIBTHREAD"
+ ACX_PTHREAD([
+ OCFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ dnl unfortunately empty thread lib spec is problematic because
+ dnl 'yaz-config --cflags' is not always passed to linker in
+ dnl applications using YAZ (such as Zebra).
+ if test "x$PTHREAD_LIBS" = "x"; then
+ OLIBS=$LIBS
+ for lib in -lpthread -lpthreads -lc_r; do
+ LIBS="$lib $OLIBS"
+ AC_TRY_LINK([ #include <pthread.h> ],
+ [ pthread_t id; pthread_join(id, 0); ],
+ [ PTHREAD_LIBS=$lib; break ]
+ )
+ done
+ LIBS=$OLIBS
+ fi
+ LIBS="$LIBS $PTHREAD_LIBS"
+ AC_DEFINE(YAZ_POSIX_THREADS,1,[Define to 1 if POSIX threads is present])
+ YAZ_CONFIG_CFLAGS="$YAZ_CONFIG_CFLAGS -DYAZ_POSIX_THREADS=1"
+ ])