From 0f685bdef5cee7b9ba8cf6d4049510424a0c8a4b Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 12 Mar 2012 15:59:09 +0000 Subject: [PATCH 2/2] configure: redo pthread check to check for more things It seems pthread_mutexattr_init and pthread_mutexattr_settype are in libpthread, not libc, on Linux. In principle, anything in the pthread namespace might be in the platform-specific thread library (libpthread or libpthreads or libthreads or ...) on any platform. Previously, a faulty configure check for pthread_cond_timedwait worked around this on Linux by checking for -lpthread and adding it to THREAD_LIBS if pthread_cond_timedwait *was* found in libc... but let's not rely on that. So far I've only added checks for the new symbols introduced by using recursive pthreads mutexes. If we get reports of compilation failures on weird platforms, we can check for more symbols. Also clarify the indentation, which was turning into quite a mess. --- configure.ac | 61 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 45 insertions(+), 16 deletions(-) diff --git a/configure.ac b/configure.ac index aed8654..499170c 100644 --- a/configure.ac +++ b/configure.ac @@ -944,15 +944,42 @@ AC_SUBST([XML_CFLAGS]) AC_SUBST([XML_LIBS]) # Thread lib detection -AC_CHECK_FUNC(pthread_cond_timedwait,[AC_CHECK_LIB(pthread,pthread_cond_timedwait, - [THREAD_LIBS="-lpthread"])]) save_libs="$LIBS" LIBS="$LIBS $THREAD_LIBS" -AC_CHECK_FUNC(pthread_condattr_setclock,have_pthread_condattr_setclock=true,have_pthread_condattr_setclock=false) -if test x$have_pthread_condattr_setclock = xtrue; then - AC_SEARCH_LIBS([clock_getres],[rt],[THREAD_LIBS="$THREAD_LIBS -lrt"]) - AC_MSG_CHECKING([for CLOCK_MONOTONIC]) - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include + +is_missing_pthread_function="is required when compiling D-Bus on Unix platforms, but is not in your libc or libpthread. Please open a bug on https://bugs.freedesktop.org/enter_bug.cgi?product=dbus with details of your platform." + +if test "x$dbus_unix" = xyes; then + # Mandatory pthread functions. In principle, some of these could be made + # optional if there are platforms that don't have them. + # + # Currently, we only look in -lpthread. + # In principle we might need to look in -lpthreads, -lthreads, ... + # as well - please file a bug if your platform needs this. + AC_SEARCH_LIBS([pthread_cond_timedwait], + [pthread], + [THREAD_LIBS="$LIBS"], + [AC_MSG_ERROR([pthread_cond_timedwait $is_missing_pthread_function])], + []) + AC_SEARCH_LIBS([pthread_mutexattr_init], + [pthread], + [THREAD_LIBS="$LIBS"], + [AC_MSG_ERROR([pthread_mutexattr_init $is_missing_pthread_function])], + []) + AC_SEARCH_LIBS([pthread_mutexattr_settype], + [pthread], + [THREAD_LIBS="$LIBS"], + [AC_MSG_ERROR([pthread_mutexattr_settype $is_missing_pthread_function])], + []) + + # Optional, for monotonic clocks + AC_CHECK_FUNC([pthread_condattr_setclock]) + + if test "x$ac_cv_func_pthread_condattr_setclock" = xyes; then + AC_SEARCH_LIBS([clock_getres], [rt], [THREAD_LIBS="$LIBS"]) + AC_MSG_CHECKING([for CLOCK_MONOTONIC]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM( +[[#include #include ]], [[ struct timespec monotonic_timer; @@ -961,15 +988,17 @@ pthread_condattr_init (&attr); pthread_condattr_setclock (&attr, CLOCK_MONOTONIC); clock_getres (CLOCK_MONOTONIC,&monotonic_timer); ]])], -[have_clock_monotonic=true], -[have_clock_monotonic=false]) -if test x$have_clock_monotonic = xtrue; then - AC_MSG_RESULT([found]) - AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1, [Define if we have CLOCK_MONOTONIC]) -else - AC_MSG_RESULT([not found]) -fi -fi + [have_clock_monotonic=true], + [have_clock_monotonic=false]) + if test x$have_clock_monotonic = xtrue; then + AC_MSG_RESULT([found]) + AC_DEFINE(HAVE_MONOTONIC_CLOCK, 1, [Define if we have CLOCK_MONOTONIC]) + else + AC_MSG_RESULT([not found]) + fi + fi # have pthread_condattr_setclock +fi # Unix + LIBS="$save_libs" AC_SUBST([THREAD_LIBS]) -- 1.7.9.1