Tiny whitespace cleanup
[sxemacs] / m4 / sxe-datetime.m4
1 dnl sxe-datetime.m4 -- Date and time functions
2 dnl
3 dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
4 dnl
5 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
6 dnl
7 dnl Redistribution and use in source and binary forms, with or without
8 dnl modification, are permitted provided that the following conditions
9 dnl are met:
10 dnl
11 dnl 1. Redistributions of source code must retain the above copyright
12 dnl    notice, this list of conditions and the following disclaimer.
13 dnl
14 dnl 2. Redistributions in binary form must reproduce the above copyright
15 dnl    notice, this list of conditions and the following disclaimer in the
16 dnl    documentation and/or other materials provided with the distribution.
17 dnl
18 dnl 3. Neither the name of the author nor the names of any contributors
19 dnl    may be used to endorse or promote products derived from this
20 dnl    software without specific prior written permission.
21 dnl
22 dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
23 dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 dnl DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 dnl OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 dnl
34 dnl This file is part of SXEmacs.
35
36 AC_DEFUN([SXE_CHECK_TIME_HEADERS], [dnl
37         AC_HEADER_TIME
38         SXE_CHECK_HEADERS([time.h utime.h])
39         SXE_CHECK_HEADERS([sys/time.h sys/timeb.h sys/times.h],
40         [have_time=yes])
41         if test "$have_time" != "yes"; then
42                 SXE_CHECK_HEADERS([linux/time.h])
43         fi
44 ])dnl SXE_CHECK_TIME_HEADERS
45
46 AC_DEFUN([SXE_CHECK_UTIME], [dnl
47         ## ----------------------------------------------------------------
48         ## Checking for utime() or utimes().
49         ## We prefer utime, since it is more standard.
50         ## Some systems have utime.h but do not declare the struct anyplace,
51         ## so we use a more sophisticated test for utime than AC_CHECK_FUNCS.
52         ## ----------------------------------------------------------------
53         SXE_CHECK_HEADERS([utime.h])
54         AC_MSG_CHECKING([for utime])
55         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
56 #if defined HAVE_SYS_TYPES_H
57 #include <sys/types.h>
58 #endif
59 #if defined HAVE_UTIME_H
60 #include <utime.h>
61 #endif
62 ]], [[
63 struct utimbuf x;
64 x.actime = x.modtime = 0;
65 utime ("/", &x);
66 ]])], [dnl
67                 AC_MSG_RESULT(yes)
68                 AC_DEFINE([HAVE_UTIME], [1], [Description here!])
69                 ], [dnl
70                 AC_MSG_RESULT(no)
71                 dnl We don't have utime(); how about utimes()?
72                 AC_CHECK_FUNCS([utimes])])
73 ])dnl SXE_CHECK_UTIME
74
75 AC_DEFUN([SXE_CHECK_TYPE_STRUCT_TIMEVAL], [dnl
76
77         AC_CHECK_TYPES([struct timeval], [], [],
78                 [
79 #ifdef TIME_WITH_SYS_TIME
80 #  include <sys/time.h>
81 #  include <time.h>
82 #else
83 #  if defined(HAVE_SYS_TIME_H)
84 #    include <sys/time.h>
85 #  elif define(HAVE_TIME_H)
86 #    include <time.h>
87 #  endif
88 #endif
89                 ])
90         AC_CHECK_MEMBERS([struct timeval.tv_sec, struct timeval.tv_usec], [], [], [
91 #ifdef TIME_WITH_SYS_TIME
92 #  include <sys/time.h>
93 #  include <time.h>
94 #else
95 #  if defined(HAVE_SYS_TIME_H)
96 #    include <sys/time.h>
97 #  elif define(HAVE_TIME_H)
98 #    include <time.h>
99 #  endif
100 #endif
101                 ])
102 ])dnl SXE_CHECK_TYPE_STRUCT_TIMEVAL
103
104 AC_DEFUN([SXE_CHECK_TYPE_STRUCT_TIMESPEC], [dnl
105
106         AC_CHECK_TYPES([struct timespec], [], [],
107                 [
108 #ifdef TIME_WITH_SYS_TIME
109 #  include <sys/time.h>
110 #  include <time.h>
111 #else
112 #  if defined(HAVE_SYS_TIME_H)
113 #    include <sys/time.h>
114 #  elif define(HAVE_TIME_H)
115 #    include <time.h>
116 #  endif
117 #endif
118                 ])
119 ])dnl SXE_CHECK_TYPE_STRUCT_TIMESPEC
120
121
122 AC_DEFUN([SXE_CHECK_TYPE_TIME_T], [dnl
123
124         AC_CHECK_TYPES([time_t], [], [],
125                 [
126 #ifdef TIME_WITH_SYS_TIME
127 #  include <sys/time.h>
128 #  include <time.h>
129 #else
130 #  if defined(HAVE_SYS_TIME_H)
131 #    include <sys/time.h>
132 #  elif define(HAVE_TIME_H)
133 #    include <time.h>
134 #  endif
135 #endif
136                 ])
137 ])dnl SXE_CHECK_TYPE_TIME_T
138
139 AC_DEFUN([SXE_CHECK_GETTIMEOFDAY], [dnl
140         ## check for the gettimeofday function
141         AC_CHECK_FUNCS([gettimeofday], [], [],
142                 [
143 #ifdef TIME_WITH_SYS_TIME
144 #  include <sys/time.h>
145 #  include <time.h>
146 #else
147 #  if defined(HAVE_SYS_TIME_H)
148 #    include <sys/time.h>
149 #  elif define(HAVE_TIME_H)
150 #    include <time.h>
151 #  endif
152 #endif
153                 ])
154
155         if test "$ac_cv_type_struct_timeval" = "yes" \
156              -a "$ac_cv_func_gettimeofday" = "yes"; then
157                 AC_MSG_CHECKING([whether gettimeofday() accepts one or two arguments])
158                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
159 #ifdef TIME_WITH_SYS_TIME
160 #  include <sys/time.h>
161 #  include <time.h>
162 #else
163 #  if defined(HAVE_SYS_TIME_H)
164 #    include <sys/time.h>
165 #  elif define(HAVE_TIME_H)
166 #    include <time.h>
167 #  endif
168 #endif
169                         ]], [[
170 struct timeval tm; /* we MUST NOT shadow the global time symbol, fuck it */
171 gettimeofday(&tm, 0);
172                         ]])],
173                         [gettimeofday_nargs="2"], [gettimeofday_nargs="1"])
174                 AC_MSG_RESULT([$gettimeofday_nargs])
175                 AC_DEFINE_UNQUOTED([GETTIMEOFDAY_NARGS],
176                         [$gettimeofday_nargs],
177                         [Number of arguments of the gettimeofday() fun])
178
179                 if test "$gettimeofday_nargs" = "1"; then
180                         ## legacy bullshit
181                         AC_DEFINE([GETTIMEOFDAY_ONE_ARGUMENT], [1],
182                                 [Legacy shit! Use GETTIMEOFDAY_NARGS instead!])
183                 fi
184         fi
185
186         if test "$ac_cv_type_struct_timespec" = "yes" \
187              -a "$ac_cv_func_gettimeofday" = "yes"; then
188                 AC_MSG_CHECKING([whether gettimeofday() can cope with timespecs])
189                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
190 #ifdef TIME_WITH_SYS_TIME
191 #  include <sys/time.h>
192 #  include <time.h>
193 #else
194 #  if defined(HAVE_SYS_TIME_H)
195 #    include <sys/time.h>
196 #  elif define(HAVE_TIME_H)
197 #    include <time.h>
198 #  endif
199 #endif
200                         ]], [[
201 struct timespec time;
202 #if GETTIMEOFDAY_NARGS == 1
203 gettimeofday(&time);
204 #elif GETTIMEOFDAY_NARGS == 2
205 gettimeofday(&time, 0);
206 #else
207 !@#$% VERY_UNLIKELY_TO_COMPILE )(*&^
208 #endif
209                         ]])],
210                         [gettimeofday_handles_struct_timespec=yes],
211                         [gettimeofday_handles_struct_timespec=no])
212                 AC_MSG_RESULT([$gettimeofday_handles_struct_timespec])
213                 AC_DEFINE_UNQUOTED([GETTIMEOFDAY_HANDLES_STRUCT_TIMESPEC],
214                         [$gettimeofday_handles_struct_timespec],
215                         [Whether gettimeofday() can be called on a `struct timespec'])
216         fi
217 ])dnl SXE_CHECK_GETTIMEOFDAY
218
219 AC_DEFUN([SXE_CHECK_DO_GETTIMEOFDAY], [dnl
220         AC_CHECK_FUNCS([do_gettimeofday], [], [],
221                 [
222 #ifdef HAVE_LINUX_TIME_H
223 #  include <linux/time.h>
224 #endif
225                 ])
226
227         if test "$ac_cv_type_struct_timeval" = "yes" \
228              -a "$ac_cv_func_do_gettimeofday" = "yes"; then
229                 AC_MSG_CHECKING([whether do_gettimeofday accepts one or two arguments])
230                 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
231 #ifdef HAVE_LINUX_TIME_H
232 #  include <linux/time.h>
233 #endif
234 ]], [[
235 struct timeval time;
236 do_gettimeofday(&time, 0);
237 ]])], [do_gettimeofday_nargs="2"], [do_gettimeofday_nargs="1"])
238                 AC_MSG_RESULT([$do_gettimeofday_nargs])
239                 AC_DEFINE_UNQUOTED([DO_GETTIMEOFDAY_NARGS],
240                         [$do_gettimeofday_nargs],
241                         [Number of arguments of the do_gettimeofday() fun])
242         fi
243 ])dnl SXE_CHECK_DO_GETTIMEOFDAY
244
245 AC_DEFUN([SXE_CHECK_CURRENT_KERNEL_TIME], [dnl
246         AC_CHECK_FUNCS([current_kernel_time], [], [],
247                 [
248 #ifdef HAVE_LINUX_TIME_H
249 #  include <linux/time.h>
250 #endif
251                 ])
252
253         if test "$ac_cv_type_struct_timespec" = "yes" \
254              -a "$ac_cv_func_current_kernel_time" = "yes"; then
255                 :
256         fi
257 ])dnl SXE_CHECK_CURRENT_KERNEL_TIME
258
259 AC_DEFUN([SXE_CHECK_CLOCK_GETTIME], [dnl
260         ## checks for both clock_gettime() and clock_getres()
261         AC_CHECK_LIB([rt], [clock_gettime], [
262                 AC_DEFINE([HAVE_CLOCK_GETTIME], [1],
263                         [Whether clock_gettime() is in librt])])
264         AC_CHECK_LIB([rt], [clock_getres], [
265                 AC_DEFINE([HAVE_CLOCK_GETRES], [1],
266                         [Whether clock_getres() is in librt])])
267 ])dnl SXE_CHECK_CLOCK_GETTIME
268
269
270 dnl recommended interface function, does all the necessary trickery
271 AC_DEFUN([SXE_CHECK_METRONOME], [dnl
272         AC_MSG_CHECKING([for metronome support requisites])
273         AC_MSG_RESULT([])
274
275         ## assume we havent got any of prerequisites
276         have_metronome="no"
277
278         SXE_CHECK_TIME_HEADERS
279
280         ## check for utime
281         SXE_CHECK_UTIME
282         ## checks for structure members
283         AC_STRUCT_TM
284         AC_STRUCT_TIMEZONE
285
286         ## check for struct timeval
287         SXE_CHECK_TYPE_STRUCT_TIMEVAL
288         SXE_CHECK_TYPE_STRUCT_TIMESPEC
289         SXE_CHECK_TYPE_TIME_T
290
291         SXE_CHECK_GETTIMEOFDAY
292         SXE_CHECK_DO_GETTIMEOFDAY
293         SXE_CHECK_CURRENT_KERNEL_TIME
294         SXE_CHECK_CLOCK_GETTIME
295
296         if test "$ac_cv_type_struct_timeval" = "yes" \
297              -a "$ac_cv_func_gettimeofday" = "yes"; then
298                 have_metronome="yes"
299         fi
300
301         if test "$ac_cv_type_struct_timespec" = "yes" \
302              -a "$ac_cv_func_do_gettimeofday" = "yes"; then
303                 have_metronome="yes"
304         fi
305
306         if test "$ac_cv_type_struct_timespec" = "yes" \
307              -a "$ac_cv_func_current_kernel_time" = "yes"; then
308                 have_metronome="yes"
309         fi
310
311         if test "$ac_cv_type_struct_timespec" = "yes" \
312              -a "$ac_cv_lib_rt_clock_gettime" = "yes" \
313              -a "$ac_cv_lib_rt_clock_getres" = "yes"; then
314                 have_metronome="yes"
315         fi
316
317         ## legacy bullshit
318         if test "$ac_cv_type_struct_timeval" = "yes" -a \
319                 "$ac_cv_member_struct_timeval_tv_sec" = "yes" -a \
320                 "$ac_cv_member_struct_timeval_tv_usec" = "yes"; then
321                 AC_DEFINE([HAVE_TIMEVAL], [1],
322                         [Legacy shit! Use HAVE_STRUCT_TIMEVAL instead!])
323         fi
324 ])dnl SXE_CHECK_METRONOME
325
326 dnl sxe-datetime.m4 ends here