Avoid compiler warnings in decode_env_path.
[emacs.git] / m4 / time_h.m4
blob03579a3ae373de4400e74179ff64fca580a45057
1 # Configure a more-standard replacement for <time.h>.
3 # Copyright (C) 2000-2001, 2003-2007, 2009-2015 Free Software
4 # Foundation, Inc.
6 # serial 8
8 # This file is free software; the Free Software Foundation
9 # gives unlimited permission to copy and/or distribute it,
10 # with or without modifications, as long as this notice is preserved.
12 # Written by Paul Eggert and Jim Meyering.
14 AC_DEFUN([gl_HEADER_TIME_H],
16   dnl Use AC_REQUIRE here, so that the default behavior below is expanded
17   dnl once only, before all statements that occur in other macros.
18   AC_REQUIRE([gl_HEADER_TIME_H_BODY])
21 AC_DEFUN([gl_HEADER_TIME_H_BODY],
23   AC_REQUIRE([AC_C_RESTRICT])
24   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
25   gl_NEXT_HEADERS([time.h])
26   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
29 dnl Check whether 'struct timespec' is declared
30 dnl in time.h, sys/time.h, or pthread.h.
32 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
34   AC_CHECK_HEADERS_ONCE([sys/time.h])
35   AC_CACHE_CHECK([for struct timespec in <time.h>],
36     [gl_cv_sys_struct_timespec_in_time_h],
37     [AC_COMPILE_IFELSE(
38        [AC_LANG_PROGRAM(
39           [[#include <time.h>
40           ]],
41           [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
42        [gl_cv_sys_struct_timespec_in_time_h=yes],
43        [gl_cv_sys_struct_timespec_in_time_h=no])])
45   TIME_H_DEFINES_STRUCT_TIMESPEC=0
46   SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
47   PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
48   if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
49     TIME_H_DEFINES_STRUCT_TIMESPEC=1
50   else
51     AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
52       [gl_cv_sys_struct_timespec_in_sys_time_h],
53       [AC_COMPILE_IFELSE(
54          [AC_LANG_PROGRAM(
55             [[#include <sys/time.h>
56             ]],
57             [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
58          [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
59          [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
60     if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
61       SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
62     else
63       AC_CACHE_CHECK([for struct timespec in <pthread.h>],
64         [gl_cv_sys_struct_timespec_in_pthread_h],
65         [AC_COMPILE_IFELSE(
66            [AC_LANG_PROGRAM(
67               [[#include <pthread.h>
68               ]],
69               [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
70            [gl_cv_sys_struct_timespec_in_pthread_h=yes],
71            [gl_cv_sys_struct_timespec_in_pthread_h=no])])
72       if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
73         PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
74       fi
75     fi
76   fi
77   AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
78   AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
79   AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
82 AC_DEFUN([gl_TIME_MODULE_INDICATOR],
84   dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
85   AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
86   gl_MODULE_INDICATOR_SET_VARIABLE([$1])
87   dnl Define it also as a C macro, for the benefit of the unit tests.
88   gl_MODULE_INDICATOR_FOR_TESTS([$1])
91 AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
93   GNULIB_MKTIME=0;                       AC_SUBST([GNULIB_MKTIME])
94   GNULIB_NANOSLEEP=0;                    AC_SUBST([GNULIB_NANOSLEEP])
95   GNULIB_STRPTIME=0;                     AC_SUBST([GNULIB_STRPTIME])
96   GNULIB_TIMEGM=0;                       AC_SUBST([GNULIB_TIMEGM])
97   GNULIB_TIME_R=0;                       AC_SUBST([GNULIB_TIME_R])
98   dnl Assume proper GNU behavior unless another module says otherwise.
99   HAVE_DECL_LOCALTIME_R=1;               AC_SUBST([HAVE_DECL_LOCALTIME_R])
100   HAVE_NANOSLEEP=1;                      AC_SUBST([HAVE_NANOSLEEP])
101   HAVE_STRPTIME=1;                       AC_SUBST([HAVE_STRPTIME])
102   HAVE_TIMEGM=1;                         AC_SUBST([HAVE_TIMEGM])
103   dnl If another module says to replace or to not replace, do that.
104   dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
105   dnl this lets maintainers check for portability.
106   REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;  AC_SUBST([REPLACE_LOCALTIME_R])
107   REPLACE_MKTIME=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_MKTIME])
108   REPLACE_NANOSLEEP=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_NANOSLEEP])
109   REPLACE_TIMEGM=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_TIMEGM])
111   dnl Hack so that the time module doesn't depend on the sys_time module.
112   dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
113   : ${GNULIB_GETTIMEOFDAY=0};            AC_SUBST([GNULIB_GETTIMEOFDAY])
114   dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
115   dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
116   dnl is no longer a big deal.
117   REPLACE_GMTIME=0;                      AC_SUBST([REPLACE_GMTIME])
118   REPLACE_LOCALTIME=0;                   AC_SUBST([REPLACE_LOCALTIME])