blob: 16ec3edb3be4f1ca9ee356f66ada085d435a3a1e [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001Discover monotonic clock using compile-time check
2
3monotonic clock check does not work when cross-compiling.
4
5Upstream-Status: Denied [Does not work on OpenBSD]
6Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
7
8
9
10Original patch follows:
11
12When xorg-xserver is being cross-compiled, there is currently no way
13for us to detect whether the monotonic clock is available on the
14target system, because we aren't able to run a test program on the host
15system. Currently, in this situation, we default to not use the
16monotonic clock. One problem with this situation is that the user will
17be treated as idle when the date is updated.
18
19To fix this situation, we now use a compile-time check to detect whether the
20monotonic clock is available. This check can run just fine when we are
21cross-compiling.
22
23Signed-off-by: David James <davidjames at google.com>
24---
25 configure.ac | 17 +++++++----------
26 1 file changed, 7 insertions(+), 10 deletions(-)
27
28diff --git a/configure.ac b/configure.ac
29index f7ab48c..26e85cd 100644
30--- a/configure.ac
31+++ b/configure.ac
32@@ -1048,19 +1048,16 @@ if ! test "x$have_clock_gettime" = xno; then
33 CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200112L"
34 fi
35
36- AC_RUN_IFELSE([AC_LANG_SOURCE([
37+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
38 #include <time.h>
39-
40-int main(int argc, char *argv[[]]) {
41- struct timespec tp;
42-
43- if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
44+#include <unistd.h>
45+int main() {
46+#if !(defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && defined(CLOCK_MONOTONIC))
47+ #error No monotonic clock
48+#endif
49 return 0;
50- else
51- return 1;
52 }
53- ])], [MONOTONIC_CLOCK=yes], [MONOTONIC_CLOCK=no],
54- [MONOTONIC_CLOCK="cross compiling"])
55+]])],[MONOTONIC_CLOCK=yes], [MONOTONIC_CLOCK=no])
56
57 LIBS="$LIBS_SAVE"
58 CPPFLAGS="$CPPFLAGS_SAVE"
59--
602.1.4
61