- 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"
-fi
-
-dnl ----- libXSLT/libEXLT/libXML2
-AC_SUBST(XML2_CFLAGS)
-
-xml2dir=default
-AC_ARG_WITH(xml2,[[ --with-xml2[=PREFIX] use libxml2 in PREFIX]],xml2dir=$withval)
-dnl -- if no PREFIX or not specified we just search in default locations
-dnl -- try pkg-config. If not found, use xml2-config
-if test "$xml2dir" = "yes" -o "$xml2dir" = "default"; then
- if test "$pkgconfigpath" != "NONE"; then
- if $pkgconfigpath --exists libxml-2.0; then
- pkgmodule="libxml-2.0"
- fi
- fi
- if test -z "$pkgmodule"; then
- for d in /usr /usr/local; do
- if test -x $d/bin/xml2-config; then
- xml2dir=$d
- fi
+ 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 ]
+ )