1 | # Configure a replacement for <sys/time.h>.
|
---|
2 | # serial 12
|
---|
3 |
|
---|
4 | # Copyright (C) 2007, 2009-2021 Free Software Foundation, Inc.
|
---|
5 | # This file is free software; the Free Software Foundation
|
---|
6 | # gives unlimited permission to copy and/or distribute it,
|
---|
7 | # with or without modifications, as long as this notice is preserved.
|
---|
8 |
|
---|
9 | # Written by Paul Eggert and Martin Lambers.
|
---|
10 |
|
---|
11 | AC_DEFUN_ONCE([gl_SYS_TIME_H],
|
---|
12 | [
|
---|
13 | dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
|
---|
14 | dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
|
---|
15 | dnl statements that occur in other macros.
|
---|
16 | AC_REQUIRE([gl_SYS_TIME_H_DEFAULTS])
|
---|
17 | AC_REQUIRE([AC_C_RESTRICT])
|
---|
18 | AC_CHECK_HEADERS_ONCE([sys/time.h])
|
---|
19 | gl_CHECK_NEXT_HEADERS([sys/time.h])
|
---|
20 |
|
---|
21 | if test $ac_cv_header_sys_time_h != yes; then
|
---|
22 | HAVE_SYS_TIME_H=0
|
---|
23 | fi
|
---|
24 |
|
---|
25 | dnl On native Windows with MSVC, 'struct timeval' is defined in <winsock2.h>
|
---|
26 | dnl only. So include that header in the list.
|
---|
27 | gl_PREREQ_SYS_H_WINSOCK2
|
---|
28 | AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
|
---|
29 | [AC_COMPILE_IFELSE(
|
---|
30 | [AC_LANG_PROGRAM(
|
---|
31 | [[#if HAVE_SYS_TIME_H
|
---|
32 | #include <sys/time.h>
|
---|
33 | #endif
|
---|
34 | #include <time.h>
|
---|
35 | #if HAVE_WINSOCK2_H
|
---|
36 | # include <winsock2.h>
|
---|
37 | #endif
|
---|
38 | ]],
|
---|
39 | [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
|
---|
40 | [gl_cv_sys_struct_timeval=yes],
|
---|
41 | [gl_cv_sys_struct_timeval=no])
|
---|
42 | ])
|
---|
43 | if test $gl_cv_sys_struct_timeval != yes; then
|
---|
44 | HAVE_STRUCT_TIMEVAL=0
|
---|
45 | else
|
---|
46 | dnl On native Windows with a 64-bit 'time_t', 'struct timeval' is defined
|
---|
47 | dnl (in <sys/time.h> and <winsock2.h> for mingw64, in <winsock2.h> only
|
---|
48 | dnl for MSVC) with a tv_sec field of type 'long' (32-bit!), which is
|
---|
49 | dnl smaller than the 'time_t' type mandated by POSIX.
|
---|
50 | dnl On OpenBSD 5.1 amd64, tv_sec is 64 bits and time_t 32 bits, but
|
---|
51 | dnl that is good enough.
|
---|
52 | AC_CACHE_CHECK([for wide-enough struct timeval.tv_sec member],
|
---|
53 | [gl_cv_sys_struct_timeval_tv_sec],
|
---|
54 | [AC_COMPILE_IFELSE(
|
---|
55 | [AC_LANG_PROGRAM(
|
---|
56 | [[#if HAVE_SYS_TIME_H
|
---|
57 | #include <sys/time.h>
|
---|
58 | #endif
|
---|
59 | #include <time.h>
|
---|
60 | #if HAVE_WINSOCK2_H
|
---|
61 | # include <winsock2.h>
|
---|
62 | #endif
|
---|
63 | ]],
|
---|
64 | [[static struct timeval x;
|
---|
65 | typedef int verify_tv_sec_type[
|
---|
66 | sizeof (time_t) <= sizeof x.tv_sec ? 1 : -1
|
---|
67 | ];
|
---|
68 | ]])],
|
---|
69 | [gl_cv_sys_struct_timeval_tv_sec=yes],
|
---|
70 | [gl_cv_sys_struct_timeval_tv_sec=no])
|
---|
71 | ])
|
---|
72 | if test $gl_cv_sys_struct_timeval_tv_sec != yes; then
|
---|
73 | REPLACE_STRUCT_TIMEVAL=1
|
---|
74 | fi
|
---|
75 | fi
|
---|
76 |
|
---|
77 | dnl Check for declarations of anything we want to poison if the
|
---|
78 | dnl corresponding gnulib module is not in use.
|
---|
79 | gl_WARN_ON_USE_PREPARE([[
|
---|
80 | #if HAVE_SYS_TIME_H
|
---|
81 | # include <sys/time.h>
|
---|
82 | #endif
|
---|
83 | #include <time.h>
|
---|
84 | ]], [gettimeofday])
|
---|
85 | ])
|
---|
86 |
|
---|
87 | # gl_SYS_TIME_MODULE_INDICATOR([modulename])
|
---|
88 | # sets the shell variable that indicates the presence of the given module
|
---|
89 | # to a C preprocessor expression that will evaluate to 1.
|
---|
90 | # This macro invocation must not occur in macros that are AC_REQUIREd.
|
---|
91 | AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
|
---|
92 | [
|
---|
93 | dnl Ensure to expand the default settings once only.
|
---|
94 | gl_SYS_TIME_H_REQUIRE_DEFAULTS
|
---|
95 | gl_MODULE_INDICATOR_SET_VARIABLE([$1])
|
---|
96 | dnl Define it also as a C macro, for the benefit of the unit tests.
|
---|
97 | gl_MODULE_INDICATOR_FOR_TESTS([$1])
|
---|
98 | ])
|
---|
99 |
|
---|
100 | # Initializes the default values for AC_SUBSTed shell variables.
|
---|
101 | # This macro must not be AC_REQUIREd. It must only be invoked, and only
|
---|
102 | # outside of macros or in macros that are not AC_REQUIREd.
|
---|
103 | AC_DEFUN([gl_SYS_TIME_H_REQUIRE_DEFAULTS],
|
---|
104 | [
|
---|
105 | m4_defun(GL_MODULE_INDICATOR_PREFIX[_SYS_TIME_H_MODULE_INDICATOR_DEFAULTS], [
|
---|
106 | gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETTIMEOFDAY])
|
---|
107 | ])
|
---|
108 | m4_require(GL_MODULE_INDICATOR_PREFIX[_SYS_TIME_H_MODULE_INDICATOR_DEFAULTS])
|
---|
109 | AC_REQUIRE([gl_SYS_TIME_H_DEFAULTS])
|
---|
110 | ])
|
---|
111 |
|
---|
112 | AC_DEFUN([gl_SYS_TIME_H_DEFAULTS],
|
---|
113 | [
|
---|
114 | dnl Assume POSIX behavior unless another module says otherwise.
|
---|
115 | HAVE_GETTIMEOFDAY=1; AC_SUBST([HAVE_GETTIMEOFDAY])
|
---|
116 | HAVE_STRUCT_TIMEVAL=1; AC_SUBST([HAVE_STRUCT_TIMEVAL])
|
---|
117 | HAVE_SYS_TIME_H=1; AC_SUBST([HAVE_SYS_TIME_H])
|
---|
118 | REPLACE_GETTIMEOFDAY=0; AC_SUBST([REPLACE_GETTIMEOFDAY])
|
---|
119 | REPLACE_STRUCT_TIMEVAL=0; AC_SUBST([REPLACE_STRUCT_TIMEVAL])
|
---|
120 | ])
|
---|