* modules/gethrxtime (Depends-on): Add gettime.
[gnulib.git] / m4 / gethrxtime.m4
1 # gethrxtime.m4 serial 3
2 dnl Copyright (C) 2005 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 dnl Written by Paul Eggert.
8
9 AC_DEFUN([gl_GETHRXTIME],
10 [
11   AC_LIBSOURCES([gethrxtime.c, gethrxtime.h, xtime.h])
12   AC_REQUIRE([gl_ARITHMETIC_HRTIME_T])
13   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
14   AC_REQUIRE([gl_XTIME])
15   AC_CHECK_DECLS([gethrtime], [], [], [#include <time.h>])
16   case $ac_cv_have_decl_gethrtime,$gl_cv_arithmetic_hrtime_t in
17   yes,yes) ;;
18   *)
19     AC_LIBOBJ([gethrxtime])
20     gl_PREREQ_GETHRXTIME;;
21   esac
22 ])
23
24 # Test whether hrtime_t is an arithmetic type.
25 # It is not arithmetic in older Solaris c89 (which insists on
26 # not having a long long int type).
27 AC_DEFUN([gl_ARITHMETIC_HRTIME_T],
28 [
29   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
30   AC_CACHE_CHECK([for arithmetic hrtime_t], gl_cv_arithmetic_hrtime_t,
31     [AC_COMPILE_IFELSE(
32        [AC_LANG_PROGRAM([#include <time.h>],
33           [hrtime_t x = 0; return x/x;])],
34        [gl_cv_arithmetic_hrtime_t=yes],
35        [gl_cv_arithmetic_hrtime_t=no])])
36   if test $gl_cv_arithmetic_hrtime_t = yes; then
37     AC_DEFINE([HAVE_ARITHMETIC_HRTIME_T], 1,
38       [Define if you have an arithmetic hrtime_t type.])
39   fi
40 ])
41
42 # Prerequisites of lib/xtime.h.
43 AC_DEFUN([gl_XTIME],
44 [
45   AC_REQUIRE([AC_C_INLINE])
46   AC_REQUIRE([gl_AC_TYPE_LONG_LONG])
47   :
48 ])
49
50 # Prerequisites of lib/gethrxtime.c.
51 AC_DEFUN([gl_PREREQ_GETHRXTIME],
52 [
53   AC_REQUIRE([gl_CLOCK_TIME])
54   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
55   AC_CHECK_FUNCS_ONCE(microuptime nanouptime)
56
57   if test $ac_cv_func_nanouptime != yes; then
58     LIB_GETHRXTIME=
59     AC_CACHE_CHECK([whether CLOCK_MONOTONIC is defined],
60       gl_cv_have_CLOCK_MONOTONIC,
61       [AC_EGREP_CPP([have_CLOCK_MONOTONIC],
62         [
63 #        include <time.h>
64 #        ifdef CLOCK_MONOTONIC
65           have_CLOCK_MONOTONIC
66 #        endif
67         ],
68         gl_cv_have_CLOCK_MONOTONIC=yes,
69         gl_cv_have_CLOCK_MONOTONIC=no)])
70     if test $gl_cv_have_CLOCK_MONOTONIC = yes; then
71       LIB_GETHRXTIME=$LIB_CLOCK_GETTIME
72     fi
73     AC_SUBST([LIB_GETHRXTIME])
74   fi
75 ])