9c16487957bc27ffd4ade8eba9943b1fb138df5d
[debian/gzip] / m4 / sys_time_h.m4
1 # Configure a replacement for <sys/time.h>.
2 # serial 2
3
4 # Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
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 Martin Lambers.
10
11 AC_DEFUN([gl_HEADER_SYS_TIME_H],
12 [
13   dnl Use AC_REQUIRE here, so that the REPLACE_GETTIMEOFDAY=0 statement
14   dnl below is expanded once only, before all REPLACE_GETTIMEOFDAY=1
15   dnl statements that occur in other macros.
16   AC_REQUIRE([gl_HEADER_SYS_TIME_H_BODY])
17 ])
18
19 AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
20 [
21   AC_REQUIRE([AC_C_RESTRICT])
22   AC_CHECK_HEADERS_ONCE([sys/time.h])
23   gl_CHECK_NEXT_HEADERS([sys/time.h])
24
25   if test $ac_cv_header_sys_time_h = yes; then
26     HAVE_SYS_TIME_H=1
27   else
28     HAVE_SYS_TIME_H=0
29   fi
30   AC_SUBST([HAVE_SYS_TIME_H])
31
32   AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
33     [AC_COMPILE_IFELSE(
34        [AC_LANG_PROGRAM(
35           [[#if HAVE_SYS_TIME_H
36              #include <sys/time.h>
37             #endif
38             #include <time.h>
39           ]],
40           [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
41        [gl_cv_sys_struct_timeval=yes],
42        [gl_cv_sys_struct_timeval=no])])
43   if test $gl_cv_sys_struct_timeval = yes; then
44     HAVE_STRUCT_TIMEVAL=1
45   else
46     HAVE_STRUCT_TIMEVAL=0
47   fi
48   AC_SUBST([HAVE_STRUCT_TIMEVAL])
49
50   dnl Assume POSIX behavior unless another module says otherwise.
51   REPLACE_GETTIMEOFDAY=0
52   AC_SUBST([REPLACE_GETTIMEOFDAY])
53   if test $HAVE_SYS_TIME_H = 0 || test $HAVE_STRUCT_TIMEVAL = 0; then
54     SYS_TIME_H=sys/time.h
55   else
56     SYS_TIME_H=
57   fi
58   AC_SUBST([SYS_TIME_H])
59 ])