Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1 | Discover monotonic clock using compile-time check |
| 2 | |
| 3 | monotonic clock check does not work when cross-compiling. |
| 4 | |
| 5 | Upstream-Status: Denied [Does not work on OpenBSD] |
| 6 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
| 7 | |
| 8 | |
| 9 | |
| 10 | Original patch follows: |
| 11 | |
| 12 | When xorg-xserver is being cross-compiled, there is currently no way |
| 13 | for us to detect whether the monotonic clock is available on the |
| 14 | target system, because we aren't able to run a test program on the host |
| 15 | system. Currently, in this situation, we default to not use the |
| 16 | monotonic clock. One problem with this situation is that the user will |
| 17 | be treated as idle when the date is updated. |
| 18 | |
| 19 | To fix this situation, we now use a compile-time check to detect whether the |
| 20 | monotonic clock is available. This check can run just fine when we are |
| 21 | cross-compiling. |
| 22 | |
| 23 | Signed-off-by: David James <davidjames at google.com> |
| 24 | --- |
| 25 | configure.ac | 17 +++++++---------- |
| 26 | 1 file changed, 7 insertions(+), 10 deletions(-) |
| 27 | |
| 28 | diff --git a/configure.ac b/configure.ac |
| 29 | index 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 | -- |
| 60 | 2.1.4 |
| 61 | |