Commit | Line | Data |
---|---|---|
e65fc94b LC |
1 | # Configure a more-standard replacement for <time.h>. |
2 | ||
f0007cad | 3 | # Copyright (C) 2000-2001, 2003-2007, 2009-2012 Free Software Foundation, Inc. |
e65fc94b | 4 | |
35428fb6 | 5 | # serial 6 |
6f32e5c7 | 6 | |
e65fc94b LC |
7 | # This file is free software; the Free Software Foundation |
8 | # gives unlimited permission to copy and/or distribute it, | |
9 | # with or without modifications, as long as this notice is preserved. | |
10 | ||
11 | # Written by Paul Eggert and Jim Meyering. | |
12 | ||
13 | AC_DEFUN([gl_HEADER_TIME_H], | |
14 | [ | |
15 | dnl Use AC_REQUIRE here, so that the default behavior below is expanded | |
16 | dnl once only, before all statements that occur in other macros. | |
17 | AC_REQUIRE([gl_HEADER_TIME_H_BODY]) | |
18 | ]) | |
19 | ||
20 | AC_DEFUN([gl_HEADER_TIME_H_BODY], | |
21 | [ | |
22 | AC_REQUIRE([AC_C_RESTRICT]) | |
23 | AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) | |
49114fd4 | 24 | gl_NEXT_HEADERS([time.h]) |
e65fc94b LC |
25 | AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) |
26 | ]) | |
27 | ||
f0007cad | 28 | dnl Define HAVE_STRUCT_TIMESPEC if 'struct timespec' is declared |
6f32e5c7 | 29 | dnl in time.h, sys/time.h, or pthread.h. |
e65fc94b LC |
30 | |
31 | AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC], | |
32 | [ | |
33 | AC_CHECK_HEADERS_ONCE([sys/time.h]) | |
34 | AC_CACHE_CHECK([for struct timespec in <time.h>], | |
35 | [gl_cv_sys_struct_timespec_in_time_h], | |
36 | [AC_COMPILE_IFELSE( | |
37 | [AC_LANG_PROGRAM( | |
1cd4fffc LC |
38 | [[#include <time.h> |
39 | ]], | |
40 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | |
e65fc94b LC |
41 | [gl_cv_sys_struct_timespec_in_time_h=yes], |
42 | [gl_cv_sys_struct_timespec_in_time_h=no])]) | |
43 | ||
44 | TIME_H_DEFINES_STRUCT_TIMESPEC=0 | |
45 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0 | |
6f32e5c7 | 46 | PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0 |
e65fc94b LC |
47 | if test $gl_cv_sys_struct_timespec_in_time_h = yes; then |
48 | TIME_H_DEFINES_STRUCT_TIMESPEC=1 | |
49 | else | |
50 | AC_CACHE_CHECK([for struct timespec in <sys/time.h>], | |
51 | [gl_cv_sys_struct_timespec_in_sys_time_h], | |
52 | [AC_COMPILE_IFELSE( | |
1cd4fffc LC |
53 | [AC_LANG_PROGRAM( |
54 | [[#include <sys/time.h> | |
55 | ]], | |
56 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | |
57 | [gl_cv_sys_struct_timespec_in_sys_time_h=yes], | |
58 | [gl_cv_sys_struct_timespec_in_sys_time_h=no])]) | |
e65fc94b LC |
59 | if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then |
60 | SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1 | |
6f32e5c7 LC |
61 | else |
62 | AC_CACHE_CHECK([for struct timespec in <pthread.h>], | |
63 | [gl_cv_sys_struct_timespec_in_pthread_h], | |
64 | [AC_COMPILE_IFELSE( | |
65 | [AC_LANG_PROGRAM( | |
66 | [[#include <pthread.h> | |
67 | ]], | |
68 | [[static struct timespec x; x.tv_sec = x.tv_nsec;]])], | |
69 | [gl_cv_sys_struct_timespec_in_pthread_h=yes], | |
70 | [gl_cv_sys_struct_timespec_in_pthread_h=no])]) | |
71 | if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then | |
72 | PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1 | |
73 | fi | |
e65fc94b LC |
74 | fi |
75 | fi | |
76 | AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC]) | |
77 | AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC]) | |
6f32e5c7 | 78 | AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC]) |
e65fc94b | 79 | ]) |
f4c79b3c LC |
80 | |
81 | AC_DEFUN([gl_TIME_MODULE_INDICATOR], | |
82 | [ | |
83 | dnl Use AC_REQUIRE here, so that the default settings are expanded once only. | |
a927b6c1 LC |
84 | AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) |
85 | gl_MODULE_INDICATOR_SET_VARIABLE([$1]) | |
f4c79b3c | 86 | dnl Define it also as a C macro, for the benefit of the unit tests. |
a927b6c1 | 87 | gl_MODULE_INDICATOR_FOR_TESTS([$1]) |
f4c79b3c LC |
88 | ]) |
89 | ||
90 | AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], | |
91 | [ | |
92 | GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME]) | |
93 | GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP]) | |
94 | GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) | |
95 | GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM]) | |
96 | GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R]) | |
a927b6c1 | 97 | dnl Assume proper GNU behavior unless another module says otherwise. |
49114fd4 | 98 | HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R]) |
a927b6c1 LC |
99 | HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) |
100 | HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) | |
101 | HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) | |
f4c79b3c LC |
102 | dnl If another module says to replace or to not replace, do that. |
103 | dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK; | |
104 | dnl this lets maintainers check for portability. | |
105 | REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R]) | |
106 | REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME]) | |
107 | REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) | |
f4c79b3c LC |
108 | REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) |
109 | ]) |