diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2022-08-18 00:31:05 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2022-08-18 00:40:14 +0300 |
commit | ab1bfc33c87726dc1fd85c351191380c6c463143 (patch) | |
tree | 731d03872f73628a9444c6007bf6dab0f742f7a7 /configure.ac | |
parent | 454e8410e03b8a141296ec4c3c2bf876d78b4ea8 (diff) | |
download | bdwgc-ab1bfc33c87726dc1fd85c351191380c6c463143.tar.gz |
Link with rt library to get clock_gettime where necessary
Issue #450 (bdwgc).
This patch adds the logic to CMake and configure scripts to pass -lrt
option during linking to avoid unresolved clock_gettime on some hosts.
* CMakeLists.txt [!NEED_LIB_RT] (HAVE_CLOCK_GETTIME_DIRECTLY): Set
variable by check_function_exists(clock_gettime).
* CMakeLists.txt [!NEED_LIB_RT && !HAVE_CLOCK_GETTIME_DIRECTLY]
(NEED_LIB_RT): Set to ON.
* CMakeLists.txt (LIBRT): Refine comment.
* CMakeLists.txt (gc): Specify target_link_libraries regardless of
enable_threads.
* Makefile.am (libgc_la_LIBADD): Update comment.
* configure.ac (need_lib_rt): Define variable (and set to false).
* configure.ac [$THREADS==pthreads && ($host==*-*-hpux11*
|| $host==*-*-netbsd* || $host== *-*-solaris* || $host==*-*-osf*)]
(THREADDLLIBS): Do not add "-lrt" directly.
* configure.ac [$THREADS==pthreads && ($host==*-*-hpux11*
|| $host==*-*-netbsd* || $host== *-*-solaris* || $host==*-*-osf*)]
(need_lib_rt): Set to true.
* configure.ac [!need_lib_rt && !AC_LINK_IFELSE(clock_gettime)
&& AC_CHECK_LIB(rt,clock_gettime)] (need_lib_rt): Set to true.
* configure.ac [need_lib_rt] (THREADDLLIBS): Append "-lrt".
Diffstat (limited to 'configure.ac')
-rw-r--r-- | configure.ac | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac index 2a9e3898..1293b037 100644 --- a/configure.ac +++ b/configure.ac @@ -190,6 +190,7 @@ CFLAGS="$old_CFLAGS" THREADDLLIBS= need_atomic_ops_asm=false +need_lib_rt=false compile_asm=false use_parallel_mark=no use_thread_local_alloc=no @@ -221,8 +222,9 @@ case "$THREADS" in *-*-hpux11*) AC_MSG_WARN("Only HP/UX 11 POSIX threads are supported.") AC_DEFINE(_POSIX_C_SOURCE,199506L) - THREADDLLIBS="-lpthread -lrt" + THREADDLLIBS="-lpthread" # HPUX needs REENTRANT for the _r calls. + need_lib_rt=true ;; *-*-openbsd*) AM_CFLAGS="$AM_CFLAGS -pthread" @@ -241,10 +243,12 @@ case "$THREADS" in *-*-netbsd*) AC_MSG_WARN("Only on NetBSD 2.0 or later.") AC_DEFINE(_PTHREADS) - THREADDLLIBS="-lpthread -lrt" + THREADDLLIBS="-lpthread" + need_lib_rt=true ;; *-*-solaris*) - THREADDLLIBS="-lpthread -lrt" + THREADDLLIBS="-lpthread" + need_lib_rt=true ;; *-*-cygwin* | *-*-msys*) # Cygwin doesn't have a real libpthread, so Libtool can't link @@ -265,7 +269,8 @@ case "$THREADS" in ;; *-*-osf*) AM_CFLAGS="$AM_CFLAGS -pthread" - THREADDLLIBS="-lpthread -lrt" + THREADDLLIBS="-lpthread" + need_lib_rt=true ;; *) AS_IF([test x$default_threadlibs != xtrue], @@ -328,7 +333,22 @@ case "$THREADS" in AC_MSG_ERROR($THREADS is an unknown thread package) ;; esac + +# Check whether -lrt linker option is needed to use clock_gettime. +if test "x$need_lib_rt" != xtrue; then + AC_MSG_CHECKING(for clock_gettime without additional libraries) + AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>], + [struct timespec t; clock_gettime(CLOCK_REALTIME, &t)])], + [AC_MSG_RESULT(yes)], + [AC_MSG_RESULT(no) + AC_CHECK_LIB(rt, clock_gettime, [need_lib_rt=true])]) +fi + +if test "x$need_lib_rt" = xtrue; then + THREADDLLIBS="$THREADDLLIBS -lrt" +fi AC_SUBST(THREADDLLIBS) + AM_CONDITIONAL(THREADS, test x$THREADS != xnone) AM_CONDITIONAL(PTHREADS, test x$THREADS = xposix) AM_CONDITIONAL(DARWIN_THREADS, test x$darwin_threads = xtrue) |