Blame m4/time_h.m4

Packit 8f70b4
# Configure a more-standard replacement for <time.h>.
Packit 8f70b4
Packit 8f70b4
# Copyright (C) 2000-2001, 2003-2007, 2009-2018 Free Software Foundation, Inc.
Packit 8f70b4
Packit 8f70b4
# serial 11
Packit 8f70b4
Packit 8f70b4
# This file is free software; the Free Software Foundation
Packit 8f70b4
# gives unlimited permission to copy and/or distribute it,
Packit 8f70b4
# with or without modifications, as long as this notice is preserved.
Packit 8f70b4
Packit 8f70b4
# Written by Paul Eggert and Jim Meyering.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_HEADER_TIME_H],
Packit 8f70b4
[
Packit 8f70b4
  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
Packit 8f70b4
  dnl once only, before all statements that occur in other macros.
Packit 8f70b4
  AC_REQUIRE([gl_HEADER_TIME_H_BODY])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_HEADER_TIME_H_BODY],
Packit 8f70b4
[
Packit 8f70b4
  AC_REQUIRE([AC_C_RESTRICT])
Packit 8f70b4
  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
Packit 8f70b4
  gl_NEXT_HEADERS([time.h])
Packit 8f70b4
  AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
dnl Check whether 'struct timespec' is declared
Packit 8f70b4
dnl in time.h, sys/time.h, pthread.h, or unistd.h.
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
Packit 8f70b4
[
Packit 8f70b4
  AC_CHECK_HEADERS_ONCE([sys/time.h])
Packit 8f70b4
  AC_CACHE_CHECK([for struct timespec in <time.h>],
Packit 8f70b4
    [gl_cv_sys_struct_timespec_in_time_h],
Packit 8f70b4
    [AC_COMPILE_IFELSE(
Packit 8f70b4
       [AC_LANG_PROGRAM(
Packit 8f70b4
          [[#include <time.h>
Packit 8f70b4
          ]],
Packit 8f70b4
          [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
Packit 8f70b4
       [gl_cv_sys_struct_timespec_in_time_h=yes],
Packit 8f70b4
       [gl_cv_sys_struct_timespec_in_time_h=no])])
Packit 8f70b4
Packit 8f70b4
  TIME_H_DEFINES_STRUCT_TIMESPEC=0
Packit 8f70b4
  SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
Packit 8f70b4
  PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
Packit 8f70b4
  UNISTD_H_DEFINES_STRUCT_TIMESPEC=0
Packit 8f70b4
  if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
Packit 8f70b4
    TIME_H_DEFINES_STRUCT_TIMESPEC=1
Packit 8f70b4
  else
Packit 8f70b4
    AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
Packit 8f70b4
      [gl_cv_sys_struct_timespec_in_sys_time_h],
Packit 8f70b4
      [AC_COMPILE_IFELSE(
Packit 8f70b4
         [AC_LANG_PROGRAM(
Packit 8f70b4
            [[#include <sys/time.h>
Packit 8f70b4
            ]],
Packit 8f70b4
            [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
Packit 8f70b4
         [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
Packit 8f70b4
         [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
Packit 8f70b4
    if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
Packit 8f70b4
      SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
Packit 8f70b4
    else
Packit 8f70b4
      AC_CACHE_CHECK([for struct timespec in <pthread.h>],
Packit 8f70b4
        [gl_cv_sys_struct_timespec_in_pthread_h],
Packit 8f70b4
        [AC_COMPILE_IFELSE(
Packit 8f70b4
           [AC_LANG_PROGRAM(
Packit 8f70b4
              [[#include <pthread.h>
Packit 8f70b4
              ]],
Packit 8f70b4
              [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
Packit 8f70b4
           [gl_cv_sys_struct_timespec_in_pthread_h=yes],
Packit 8f70b4
           [gl_cv_sys_struct_timespec_in_pthread_h=no])])
Packit 8f70b4
      if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
Packit 8f70b4
        PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
Packit 8f70b4
      else
Packit 8f70b4
        AC_CACHE_CHECK([for struct timespec in <unistd.h>],
Packit 8f70b4
          [gl_cv_sys_struct_timespec_in_unistd_h],
Packit 8f70b4
          [AC_COMPILE_IFELSE(
Packit 8f70b4
             [AC_LANG_PROGRAM(
Packit 8f70b4
                [[#include <unistd.h>
Packit 8f70b4
                ]],
Packit 8f70b4
                [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
Packit 8f70b4
             [gl_cv_sys_struct_timespec_in_unistd_h=yes],
Packit 8f70b4
             [gl_cv_sys_struct_timespec_in_unistd_h=no])])
Packit 8f70b4
        if test $gl_cv_sys_struct_timespec_in_unistd_h = yes; then
Packit 8f70b4
          UNISTD_H_DEFINES_STRUCT_TIMESPEC=1
Packit 8f70b4
        fi
Packit 8f70b4
      fi
Packit 8f70b4
    fi
Packit 8f70b4
  fi
Packit 8f70b4
  AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
Packit 8f70b4
  AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
Packit 8f70b4
  AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
Packit 8f70b4
  AC_SUBST([UNISTD_H_DEFINES_STRUCT_TIMESPEC])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_TIME_MODULE_INDICATOR],
Packit 8f70b4
[
Packit 8f70b4
  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
Packit 8f70b4
  AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
Packit 8f70b4
  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
Packit 8f70b4
  dnl Define it also as a C macro, for the benefit of the unit tests.
Packit 8f70b4
  gl_MODULE_INDICATOR_FOR_TESTS([$1])
Packit 8f70b4
])
Packit 8f70b4
Packit 8f70b4
AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
Packit 8f70b4
[
Packit 8f70b4
  GNULIB_CTIME=0;                        AC_SUBST([GNULIB_CTIME])
Packit 8f70b4
  GNULIB_MKTIME=0;                       AC_SUBST([GNULIB_MKTIME])
Packit 8f70b4
  GNULIB_LOCALTIME=0;                    AC_SUBST([GNULIB_LOCALTIME])
Packit 8f70b4
  GNULIB_NANOSLEEP=0;                    AC_SUBST([GNULIB_NANOSLEEP])
Packit 8f70b4
  GNULIB_STRFTIME=0;                     AC_SUBST([GNULIB_STRFTIME])
Packit 8f70b4
  GNULIB_STRPTIME=0;                     AC_SUBST([GNULIB_STRPTIME])
Packit 8f70b4
  GNULIB_TIMEGM=0;                       AC_SUBST([GNULIB_TIMEGM])
Packit 8f70b4
  GNULIB_TIME_R=0;                       AC_SUBST([GNULIB_TIME_R])
Packit 8f70b4
  GNULIB_TIME_RZ=0;                      AC_SUBST([GNULIB_TIME_RZ])
Packit 8f70b4
  GNULIB_TZSET=0;                        AC_SUBST([GNULIB_TZSET])
Packit 8f70b4
  dnl Assume proper GNU behavior unless another module says otherwise.
Packit 8f70b4
  HAVE_DECL_LOCALTIME_R=1;               AC_SUBST([HAVE_DECL_LOCALTIME_R])
Packit 8f70b4
  HAVE_NANOSLEEP=1;                      AC_SUBST([HAVE_NANOSLEEP])
Packit 8f70b4
  HAVE_STRPTIME=1;                       AC_SUBST([HAVE_STRPTIME])
Packit 8f70b4
  HAVE_TIMEGM=1;                         AC_SUBST([HAVE_TIMEGM])
Packit 8f70b4
  HAVE_TZSET=1;                          AC_SUBST([HAVE_TZSET])
Packit 8f70b4
  dnl Even GNU libc does not have timezone_t yet.
Packit 8f70b4
  HAVE_TIMEZONE_T=0;                     AC_SUBST([HAVE_TIMEZONE_T])
Packit 8f70b4
  dnl If another module says to replace or to not replace, do that.
Packit 8f70b4
  dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
Packit 8f70b4
  dnl this lets maintainers check for portability.
Packit 8f70b4
  REPLACE_CTIME=GNULIB_PORTCHECK;        AC_SUBST([REPLACE_CTIME])
Packit 8f70b4
  REPLACE_LOCALTIME_R=GNULIB_PORTCHECK;  AC_SUBST([REPLACE_LOCALTIME_R])
Packit 8f70b4
  REPLACE_MKTIME=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_MKTIME])
Packit 8f70b4
  REPLACE_NANOSLEEP=GNULIB_PORTCHECK;    AC_SUBST([REPLACE_NANOSLEEP])
Packit 8f70b4
  REPLACE_STRFTIME=GNULIB_PORTCHECK;     AC_SUBST([REPLACE_STRFTIME])
Packit 8f70b4
  REPLACE_TIMEGM=GNULIB_PORTCHECK;       AC_SUBST([REPLACE_TIMEGM])
Packit 8f70b4
  REPLACE_TZSET=GNULIB_PORTCHECK;        AC_SUBST([REPLACE_TZSET])
Packit 8f70b4
Packit 8f70b4
  dnl Hack so that the time module doesn't depend on the sys_time module.
Packit 8f70b4
  dnl First, default GNULIB_GETTIMEOFDAY to 0 if sys_time is absent.
Packit 8f70b4
  : ${GNULIB_GETTIMEOFDAY=0};            AC_SUBST([GNULIB_GETTIMEOFDAY])
Packit 8f70b4
  dnl Second, it's OK to not use GNULIB_PORTCHECK for REPLACE_GMTIME
Packit 8f70b4
  dnl and REPLACE_LOCALTIME, as portability to Solaris 2.6 and earlier
Packit 8f70b4
  dnl is no longer a big deal.
Packit 8f70b4
  REPLACE_GMTIME=0;                      AC_SUBST([REPLACE_GMTIME])
Packit 8f70b4
  REPLACE_LOCALTIME=0;                   AC_SUBST([REPLACE_LOCALTIME])
Packit 8f70b4
])