Merge changes from emacs-23 branch
[bpt/emacs.git] / m4 / time_h.m4
CommitLineData
1fd182f0
PE
1# Configure a more-standard replacement for <time.h>.
2
3# Copyright (C) 2000-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
4
3f44249e 5# serial 5
1fd182f0
PE
6
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
13AC_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
20AC_DEFUN([gl_HEADER_TIME_H_BODY],
21[
22 AC_REQUIRE([AC_C_RESTRICT])
23 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
b06b1098 24 gl_NEXT_HEADERS([time.h])
1fd182f0 25 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
3f44249e
PE
26
27 dnl Ensure the type pid_t gets defined.
28 AC_REQUIRE([AC_TYPE_PID_T])
1fd182f0
PE
29])
30
31dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
32dnl in time.h, sys/time.h, or pthread.h.
33
34AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
35[
36 AC_CHECK_HEADERS_ONCE([sys/time.h])
37 AC_CACHE_CHECK([for struct timespec in <time.h>],
38 [gl_cv_sys_struct_timespec_in_time_h],
39 [AC_COMPILE_IFELSE(
40 [AC_LANG_PROGRAM(
41 [[#include <time.h>
42 ]],
43 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
44 [gl_cv_sys_struct_timespec_in_time_h=yes],
45 [gl_cv_sys_struct_timespec_in_time_h=no])])
46
47 TIME_H_DEFINES_STRUCT_TIMESPEC=0
48 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
49 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
50 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
51 TIME_H_DEFINES_STRUCT_TIMESPEC=1
52 else
53 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
54 [gl_cv_sys_struct_timespec_in_sys_time_h],
55 [AC_COMPILE_IFELSE(
56 [AC_LANG_PROGRAM(
57 [[#include <sys/time.h>
58 ]],
59 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
60 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
61 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
62 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
63 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
64 else
65 AC_CACHE_CHECK([for struct timespec in <pthread.h>],
66 [gl_cv_sys_struct_timespec_in_pthread_h],
67 [AC_COMPILE_IFELSE(
68 [AC_LANG_PROGRAM(
69 [[#include <pthread.h>
70 ]],
71 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
72 [gl_cv_sys_struct_timespec_in_pthread_h=yes],
73 [gl_cv_sys_struct_timespec_in_pthread_h=no])])
74 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
75 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
76 fi
77 fi
78 fi
79 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
80 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
81 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
82])
83
84AC_DEFUN([gl_TIME_MODULE_INDICATOR],
85[
86 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
87 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
88 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
89 dnl Define it also as a C macro, for the benefit of the unit tests.
90 gl_MODULE_INDICATOR_FOR_TESTS([$1])
91])
92
93AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
94[
95 GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
96 GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
97 GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
98 GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
99 GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
100 dnl Assume proper GNU behavior unless another module says otherwise.
101 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
102 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
103 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
104 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
105 dnl If another module says to replace or to not replace, do that.
106 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
107 dnl this lets maintainers check for portability.
108 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
109 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
110 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
111 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
112])