]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
Build: Check for clock_gettime() even if not using POSIX threads.
authorLasse Collin <lasse.collin@tukaani.org>
Sat, 23 Sep 2023 00:23:32 +0000 (03:23 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Sun, 22 Oct 2023 15:59:45 +0000 (18:59 +0300)
See the new comment in the code.

This also makes the check for clock_gettime() run with MinGW-w64
with which we don't want to use clock_gettime(). The previous
commit already took care of this situation.

configure.ac

index 19dbf1d74aad97df47ab407ded43fefe840fd8a0..6512f480e318e72d6fc92b27b9109f64919dc0ed 100644 (file)
@@ -622,21 +622,10 @@ AS_CASE([$enable_threads],
                AC_DEFINE([MYTHREAD_POSIX], [1],
                        [Define to 1 when using POSIX threads (pthreads).])
 
-               # These are nice to have but not mandatory.
-               #
-               # FIXME: xz uses clock_gettime if it is available and can do
-               # it even when threading is disabled. Moving this outside
-               # of pthread detection may be undesirable because then
-               # liblzma may get linked against librt even when librt isn't
-               # needed by liblzma.
+               # This is nice to have but not mandatory.
                OLD_CFLAGS=$CFLAGS
                CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-               AC_SEARCH_LIBS([clock_gettime], [rt])
-               AC_CHECK_FUNCS([clock_gettime pthread_condattr_setclock])
-               AC_CHECK_DECL([CLOCK_MONOTONIC], [AC_DEFINE(
-                       [HAVE_CLOCK_MONOTONIC], [1], [Define to 1 if
-                       `CLOCK_MONOTONIC' is declared in <time.h>.])], [],
-                       [[#include <time.h>]])
+               AC_CHECK_FUNCS([pthread_condattr_setclock])
                CFLAGS=$OLD_CFLAGS
        ],
        [win95], [
@@ -916,6 +905,22 @@ fi
 # Gnulib replacements as needed
 gl_GETOPT
 
+# If clock_gettime() is available, liblzma with pthreads may use it, and
+# xz may use it even when threading support is disabled. In XZ Utils 5.4.x
+# and older, configure checked for clock_gettime() only when using pthreads.
+# This way non-threaded builds of liblzma didn't get a useless dependency on
+# librt which further had a dependency on libpthread. Avoiding these was
+# useful when a small build was needed, for example, for initramfs use.
+#
+# The above reasoning is thoroughly obsolete: On GNU/Linux, librt hasn't
+# been needed for clock_gettime() since glibc 2.17 (2012-12-25).
+# Solaris 10 needs librt but Solaris 11 doesn't anymore.
+AC_SEARCH_LIBS([clock_gettime], [rt])
+AC_CHECK_FUNCS([clock_gettime])
+AC_CHECK_DECL([CLOCK_MONOTONIC], [AC_DEFINE([HAVE_CLOCK_MONOTONIC], [1],
+       [Define to 1 if 'CLOCK_MONOTONIC' is declared in <time.h>.])], [],
+       [[#include <time.h>]])
+
 # Find the best function to set timestamps.
 AC_CHECK_FUNCS([futimens futimes futimesat utimes _futime utime], [break])