]> git.cworth.org Git - tar/blob - m4/time_h.m4
ba2e194608c072b6c0d947d9c6fc537606382626
[tar] / 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_STRING_H_DEFAULTS])
68   GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
69   dnl Define it also as a C macro, for the benefit of the unit tests.
70   gl_MODULE_INDICATOR([$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   dnl If another module says to replace or to not replace, do that.
80   dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
81   dnl this lets maintainers check for portability.
82   REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;  AC_SUBST([REPLACE_LOCALTIME_R])
83   REPLACE_MKTIME=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_MKTIME])
84   REPLACE_NANOSLEEP=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_NANOSLEEP])
85   REPLACE_STRPTIME=GNULIB_PORTCHECK;     AC_SUBST([REPLACE_STRPTIME])
86   REPLACE_TIMEGM=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_TIMEGM])
87 ])