annotate m4/time_h.m4 @ 17581:1a0eb4e01632

gettimeofday: fix C++ crosscompilation Never replace gmtime and localtime by macros when compiling with C++, this prevents <ctime> from being included. * m4/gettimeofday.m4 (gl_GETTIMEOFDAY_REPLACE_LOCALTIME): Do not define gmtime and localtime as preprocessor macros. Instead define some HAVE_GMTIME, HAVE_LOCALTIME, REPLACE_GMTIME, and REPLACE_LOCALTIME substitutions. * lib/time.in.h: Declare gmtime and localtime when needed. * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): AC_SUBST HAVE_GMTIME, HAVE_LOCALTIME, REPLACE_GMTIME, and REPLACE_LOCALTIME. * modules/time: Depend on gettimeofday, and substitute the above variables in time.h.
author John W. Eaton <jwe@gnu.org>
date Tue, 17 Dec 2013 11:04:37 -0800
parents e542fd46ad6f
children 630472a8cafd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
1 # Configure a more-standard replacement for <time.h>.
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
2
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16938
diff changeset
3 # Copyright (C) 2000-2001, 2003-2007, 2009-2013 Free Software Foundation, Inc.
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
4
16938
7bd21b317d8e time: fix obsolete comment
Paul Eggert <eggert@cs.ucla.edu>
parents: 16235
diff changeset
5 # serial 7
13382
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
6
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
7 # This file is free software; the Free Software Foundation
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
8 # gives unlimited permission to copy and/or distribute it,
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9 # with or without modifications, as long as this notice is preserved.
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 # Written by Paul Eggert and Jim Meyering.
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13 AC_DEFUN([gl_HEADER_TIME_H],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14 [
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15 dnl Use AC_REQUIRE here, so that the default behavior below is expanded
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
16 dnl once only, before all statements that occur in other macros.
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
17 AC_REQUIRE([gl_HEADER_TIME_H_BODY])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
18 ])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
20 AC_DEFUN([gl_HEADER_TIME_H_BODY],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
21 [
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
22 AC_REQUIRE([AC_C_RESTRICT])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
23 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
14186
cd4635d4dbe6 assume <ctype.h>, ..., <time.h> exist
Paul Eggert <eggert@cs.ucla.edu>
parents: 14079
diff changeset
24 gl_NEXT_HEADERS([time.h])
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
25 AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
26 ])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
27
16938
7bd21b317d8e time: fix obsolete comment
Paul Eggert <eggert@cs.ucla.edu>
parents: 16235
diff changeset
28 dnl Check whether 'struct timespec' is declared
13382
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
29 dnl in time.h, sys/time.h, or pthread.h.
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
30
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
31 AC_DEFUN([gl_CHECK_TYPE_STRUCT_TIMESPEC],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
32 [
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
33 AC_CHECK_HEADERS_ONCE([sys/time.h])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
34 AC_CACHE_CHECK([for struct timespec in <time.h>],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
35 [gl_cv_sys_struct_timespec_in_time_h],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
36 [AC_COMPILE_IFELSE(
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
37 [AC_LANG_PROGRAM(
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
38 [[#include <time.h>
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
39 ]],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
40 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
41 [gl_cv_sys_struct_timespec_in_time_h=yes],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
42 [gl_cv_sys_struct_timespec_in_time_h=no])])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
43
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
44 TIME_H_DEFINES_STRUCT_TIMESPEC=0
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
45 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=0
13382
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
46 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=0
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
47 if test $gl_cv_sys_struct_timespec_in_time_h = yes; then
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
48 TIME_H_DEFINES_STRUCT_TIMESPEC=1
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
49 else
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
50 AC_CACHE_CHECK([for struct timespec in <sys/time.h>],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
51 [gl_cv_sys_struct_timespec_in_sys_time_h],
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
52 [AC_COMPILE_IFELSE(
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
53 [AC_LANG_PROGRAM(
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
54 [[#include <sys/time.h>
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
55 ]],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
56 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
57 [gl_cv_sys_struct_timespec_in_sys_time_h=yes],
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11742
diff changeset
58 [gl_cv_sys_struct_timespec_in_sys_time_h=no])])
9179
b6825d8a63e8 * m4/time_h.m4 (gl_CHECK_TYPE_STRUCT_TIMESPEC): Fix misspelling
Paul Eggert <eggert@cs.ucla.edu>
parents: 8995
diff changeset
59 if test $gl_cv_sys_struct_timespec_in_sys_time_h = yes; then
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
60 SYS_TIME_H_DEFINES_STRUCT_TIMESPEC=1
13382
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
61 else
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
62 AC_CACHE_CHECK([for struct timespec in <pthread.h>],
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
63 [gl_cv_sys_struct_timespec_in_pthread_h],
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
64 [AC_COMPILE_IFELSE(
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
65 [AC_LANG_PROGRAM(
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
66 [[#include <pthread.h>
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
67 ]],
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
68 [[static struct timespec x; x.tv_sec = x.tv_nsec;]])],
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
69 [gl_cv_sys_struct_timespec_in_pthread_h=yes],
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
70 [gl_cv_sys_struct_timespec_in_pthread_h=no])])
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
71 if test $gl_cv_sys_struct_timespec_in_pthread_h = yes; then
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
72 PTHREAD_H_DEFINES_STRUCT_TIMESPEC=1
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
73 fi
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
74 fi
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
75 fi
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
76 AC_SUBST([TIME_H_DEFINES_STRUCT_TIMESPEC])
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
77 AC_SUBST([SYS_TIME_H_DEFINES_STRUCT_TIMESPEC])
13382
64c19ce2ffa0 time: work with mingw + pthreads-win32 library
Eric Blake <eblake@redhat.com>
parents: 13134
diff changeset
78 AC_SUBST([PTHREAD_H_DEFINES_STRUCT_TIMESPEC])
8146
b31580167c2b New module 'time', so that apps can include <time.h> as per
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
79 ])
12948
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
80
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
81 AC_DEFUN([gl_TIME_MODULE_INDICATOR],
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
82 [
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
83 dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
13127
a7fa4750421d time: Fix regression introduced on 2010-03-08.
Bruno Haible <bruno@clisp.org>
parents: 13071
diff changeset
84 AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS])
13066
fc8c984b0733 Factorize common .m4 code.
Bruno Haible <bruno@clisp.org>
parents: 12992
diff changeset
85 gl_MODULE_INDICATOR_SET_VARIABLE([$1])
12972
ad47f1c31ded Tests of module 'time' in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12948
diff changeset
86 dnl Define it also as a C macro, for the benefit of the unit tests.
13071
b2385e7b332e Distinguish two kinds of module indicators.
Bruno Haible <bruno@clisp.org>
parents: 13066
diff changeset
87 gl_MODULE_INDICATOR_FOR_TESTS([$1])
12948
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
88 ])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
89
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
90 AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS],
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
91 [
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
92 GNULIB_MKTIME=0; AC_SUBST([GNULIB_MKTIME])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
93 GNULIB_NANOSLEEP=0; AC_SUBST([GNULIB_NANOSLEEP])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
94 GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
95 GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM])
12992
4ca54426154c Fix compilation error on mingw when module 'time_r' is not used.
Bruno Haible <bruno@clisp.org>
parents: 12972
diff changeset
96 GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R])
13129
3a2049062a71 time_r: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 13127
diff changeset
97 dnl Assume proper GNU behavior unless another module says otherwise.
14057
f00add3c323d time_r: Add missing declarations on HP-UX 11.
Bruno Haible <bruno@clisp.org>
parents: 13382
diff changeset
98 HAVE_DECL_LOCALTIME_R=1; AC_SUBST([HAVE_DECL_LOCALTIME_R])
17581
1a0eb4e01632 gettimeofday: fix C++ crosscompilation
John W. Eaton <jwe@gnu.org>
parents: 17249
diff changeset
99 HAVE_GMTIME=1; AC_SUBST([HAVE_GMTIME])
1a0eb4e01632 gettimeofday: fix C++ crosscompilation
John W. Eaton <jwe@gnu.org>
parents: 17249
diff changeset
100 HAVE_LOCALTIME=1; AC_SUBST([HAVE_LOCALTIME])
13134
080377ada58c nanosleep: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 13133
diff changeset
101 HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP])
13133
72abbb959390 strptime: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 13132
diff changeset
102 HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME])
13132
eeb9ce788354 Oops, fix default value in the last commits.
Bruno Haible <bruno@clisp.org>
parents: 13131
diff changeset
103 HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM])
12948
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
104 dnl If another module says to replace or to not replace, do that.
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
105 dnl Otherwise, replace only if someone compiles with -DGNULIB_PORTCHECK;
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
106 dnl this lets maintainers check for portability.
17581
1a0eb4e01632 gettimeofday: fix C++ crosscompilation
John W. Eaton <jwe@gnu.org>
parents: 17249
diff changeset
107 REPLACE_GMTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_GMTIME])
1a0eb4e01632 gettimeofday: fix C++ crosscompilation
John W. Eaton <jwe@gnu.org>
parents: 17249
diff changeset
108 REPLACE_LOCALTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME])
12948
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
109 REPLACE_LOCALTIME_R=GNULIB_PORTCHECK; AC_SUBST([REPLACE_LOCALTIME_R])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
110 REPLACE_MKTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_MKTIME])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
111 REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
112 REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM])
ea38eeab7d0f time: Avoid #define replacements in C++ mode.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
113 ])