+
+dnl Check for pthreads (pieces of code from Bert Driehuis)
+
+AC_SUBST(MULTITHREAD_CFLAGS)
+AC_SUBST(MULTITHREAD_LDFLAGS)
+
+AC_DEFUN(AC_CHECK_PTHREAD, [
+ AC_MSG_CHECKING([pthreads: trying no flags])
+ AC_CACHE_VAL(ac_cv_flag_pthread,[
+ AC_TRY_LINK([
+ #include <pthread.h>
+ ],
+ [pthread_exit(0);],
+ eval "ac_cv_flag_pthread=no",
+ [
+ AC_MSG_RESULT([didn't work])
+ AC_MSG_CHECKING([pthreads: trying to add -pthread])
+ ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS -pthread"
+ AC_TRY_LINK([
+ #include <pthread.h>
+ ],
+ [pthread_exit(0);],
+ eval "ac_cv_flag_pthread=yes",
+ AC_MSG_ERROR([Can't figure out pthreads])
+ )
+ CFLAGS="$ac_save_CFLAGS"
+ ])
+ ])
+
+ if test "$ac_cv_flag_pthread" = "no"; then
+ AC_MSG_RESULT([good, -pthread flag not necessary])
+ else
+ AC_MSG_RESULT([adding -pthread flag])
+ MULTITHREAD_CFLAGS="-pthread"
+ fi
+
+ AC_MSG_CHECKING([for libpthread])
+ AC_CACHE_VAL(ac_cv_lib_pthread,[
+ ac_save_LIBS="$LIBS"
+ LIBS="-lpthread"
+ AC_TRY_LINK([
+ #include <pthread.h>
+ ],
+ [pthread_exit(0);],
+ eval "ac_cv_lib_pthread=-lphtread",
+ eval "ac_cv_lib_pthread=no"
+ )
+ LIBS="$ac_save_LIBS"
+ ])
+ if test "$ac_cv_lib_pthread" = "no"; then
+ AC_MSG_RESULT([no -lpthread necessary])
+ else
+ AC_MSG_RESULT([adding -lpthread to LIBS])
+ MULTITHREAD_LDFLAGS="-lpthread"
+ fi
+])
+
+AC_ARG_ENABLE(pthread,[ --disable-pthread disable multithread support],
+[],[enable_pthread=yes])
+
+if test $enable_pthread != no; then
+ AC_CHECK_PTHREAD
+fi
+
+AM_CONDITIONAL(BUILD_MULTITHREAD,[test $enable_pthread != no])
+