b88ba94da1cc7b578cc45464035c1a237a62e73b
[bpt/guile.git] / m4 / time_h.m4
1 # Configure a more-standard replacement for <time.h>.
2
3 # Copyright (C) 2000-2001, 2003-2007, 2009-2010 Free Software Foundation, Inc.
4
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 Jim Meyering.
10
11 AC_DEFUN([gl_HEADER_TIME_H],
12 [
13 dnl Use AC_REQUIRE here, so that the default behavior below is expanded
14 dnl once only, before all statements that occur in other macros.
15 AC_REQUIRE([gl_HEADER_TIME_H_BODY])
16 ])
17
18 AC_DEFUN([gl_HEADER_TIME_H_BODY],
19 [
20 AC_REQUIRE([AC_C_RESTRICT])
21 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
22 gl_CHECK_NEXT_HEADERS([time.h])
23 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
24 ])
25
26 dnl Define HAVE_STRUCT_TIMESPEC if `struct timespec' is declared
27 dnl in time.h or sys/time.h.
28
29 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
30 [
31 AC_CHECK_HEADERS_ONCE([sys/time.h])
32 AC_CACHE_CHECK([for struct timespec in <time.h>],
33 [gl_cv_sys_struct_timespec_in_time_h],
34 [AC_COMPILE_IFELSE(
35 [AC_LANG_PROGRAM(
36 [[#include <time.h>
37 ]],
38 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
39 [gl_cv_sys_struct_timespec_in_time_h=yes],
40 [gl_cv_sys_struct_timespec_in_time_h=no])])
41
42 TIME_H_DEFINES_STRUCT_TIMESPEC=0
43 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
44 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
45 TIME_H_DEFINES_STRUCT_TIMESPEC=1
46 else
47 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
48 [gl_cv_sys_struct_timespec_in_sys_time_h],
49 [AC_COMPILE_IFELSE(
50 [AC_LANG_PROGRAM(
51 [[#include <sys/time.h>
52 ]],
53 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
54 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
55 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
56 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
57 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
58 fi
59 fi
60 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
61 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
62 ])
63
64 AC_DEFUN([gl_TIME_MODULE_INDICATOR],
65 [
66 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
67 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
68 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
69 dnl Define it also as a C macro, for the benefit of the unit tests.
70 gl_MODULE_INDICATOR_FOR_TESTS([$1])
71 ])
72
73 AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
74 [
75 GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
76 GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
77 GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
78 GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
79 GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
80 dnl Assume proper GNU behavior unless another module says otherwise.
81 HAVE_LOCALTIME_R=1; AC_SUBST([HAVE_LOCALTIME_R])
82 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
83 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
84 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
85 dnl If another module says to replace or to not replace, do that.
86 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
87 dnl this lets maintainers check for portability.
88 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
89 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
90 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
91 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
92 ])