timer-time: link explicitly with pthreads on glibc
authorPádraig Brady <P@draigBrady.com>
Tue, 6 Mar 2012 15:02:40 +0000 (15:02 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 10 Mar 2012 13:51:47 +0000 (13:51 +0000)
To support static linking we need to explicitly
specify the pthreads library which is referenced
(but not used on modern Linux kernels at least).

* m4/timer_time.m4 (LIB_TIMER_TIME): Add -lpthread
when newer GLIBC is detected as that contains
the pthread emulation.
* modules/timer-time: Depend on threadlib to
pull in the appropriate library to link

ChangeLog
m4/timer_time.m4
modules/timer-time

index e873f36..d470b30 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-03-10  Pádraig Brady  <P@draigBrady.com>
+
+       timer-time: link explicitly with pthreads on glibc
+       * m4/timer_time.m4 (LIB_TIMER_TIME): Add -lpthread
+       to support static linking, when newer glibc is
+       detected, as that contains pthread emulation of
+       POSIX timer functions where required.
+       * modules/timer-time: Depend on threadlib to
+       pull in the appropriate library to link.
+
 2012-03-10  Bruno Haible  <bruno@clisp.org>
 
        log* tests: More tests.
index 6276759..d6e0efe 100644 (file)
@@ -11,6 +11,7 @@ AC_DEFUN([gl_TIMER_TIME],
   dnl Based on clock_time.m4. See details there.
 
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  AC_REQUIRE([gl_THREADLIB])
 
   LIB_TIMER_TIME=
   AC_SUBST([LIB_TIMER_TIME])
@@ -18,6 +19,21 @@ AC_DEFUN([gl_TIMER_TIME],
     AC_SEARCH_LIBS([timer_settime], [rt posix4],
                    [test "$ac_cv_search_timer_settime" = "none required" ||
                     LIB_TIMER_TIME=$ac_cv_search_timer_settime])
+    dnl GLIBC uses threads to emulate posix timers when kernel support
+    dnl is not available (like Linux < 2.6 or when used with kFreeBSD)
+    dnl Now the pthread lib is linked automatically in the normal case,
+    dnl but when linking statically, it needs to be explicitly specified.
+    AC_EGREP_CPP([Thread],
+      [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || (__GLIBC__ > 2)) \
+     && !defined __UCLIBC__
+  Thread emulation available
+ #endif
+#endif
+      ],
+      [LIB_TIMER_TIME="$LIBMULTITHREAD $LIB_TIMER_TIME"])
     AC_CHECK_FUNCS([timer_settime])
   LIBS=$gl_saved_libs
 ])
index 07b439b..7bf8079 100644 (file)
@@ -7,6 +7,7 @@ m4/timer_time.m4
 
 Depends-on:
 extensions
+threadlib
 
 configure.ac:
 gl_TIMER_TIME