1 dnl sxe-datetime.m4 -- Date and time functions
3 dnl Copyright (C) 2005, 2006, 2007, 2008 Sebastian Freundt
5 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
7 dnl Redistribution and use in source and binary forms, with or without
8 dnl modification, are permitted provided that the following conditions
11 dnl 1. Redistributions of source code must retain the above copyright
12 dnl notice, this list of conditions and the following disclaimer.
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.
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.
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.
34 dnl This file is part of SXEmacs.
36 AC_DEFUN([SXE_CHECK_TIME_HEADERS], [dnl
38 SXE_CHECK_HEADERS([time.h utime.h])
39 SXE_CHECK_HEADERS([sys/time.h sys/timeb.h sys/times.h],
41 if test "$have_time" != "yes"; then
42 SXE_CHECK_HEADERS([linux/time.h])
44 ])dnl SXE_CHECK_TIME_HEADERS
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>
59 #if defined HAVE_UTIME_H
64 x.actime = x.modtime = 0;
68 AC_DEFINE([HAVE_UTIME], [1], [Description here!])
71 dnl We don't have utime(); how about utimes()?
72 AC_CHECK_FUNCS([utimes])])
75 AC_DEFUN([SXE_CHECK_TYPE_STRUCT_TIMEVAL], [dnl
77 AC_CHECK_TYPES([struct timeval], [], [],
79 #ifdef TIME_WITH_SYS_TIME
80 # include <sys/time.h>
83 # if defined(HAVE_SYS_TIME_H)
84 # include <sys/time.h>
85 # elif define(HAVE_TIME_H)
90 AC_CHECK_MEMBERS([struct timeval.tv_sec, struct timeval.tv_usec], [], [], [
91 #ifdef TIME_WITH_SYS_TIME
92 # include <sys/time.h>
95 # if defined(HAVE_SYS_TIME_H)
96 # include <sys/time.h>
97 # elif define(HAVE_TIME_H)
102 ])dnl SXE_CHECK_TYPE_STRUCT_TIMEVAL
104 AC_DEFUN([SXE_CHECK_TYPE_STRUCT_TIMESPEC], [dnl
106 AC_CHECK_TYPES([struct timespec], [], [],
108 #ifdef TIME_WITH_SYS_TIME
109 # include <sys/time.h>
112 # if defined(HAVE_SYS_TIME_H)
113 # include <sys/time.h>
114 # elif define(HAVE_TIME_H)
119 ])dnl SXE_CHECK_TYPE_STRUCT_TIMESPEC
122 AC_DEFUN([SXE_CHECK_TYPE_TIME_T], [dnl
124 AC_CHECK_TYPES([time_t], [], [],
126 #ifdef TIME_WITH_SYS_TIME
127 # include <sys/time.h>
130 # if defined(HAVE_SYS_TIME_H)
131 # include <sys/time.h>
132 # elif define(HAVE_TIME_H)
137 ])dnl SXE_CHECK_TYPE_TIME_T
139 AC_DEFUN([SXE_CHECK_GETTIMEOFDAY], [dnl
140 ## check for the gettimeofday function
141 AC_CHECK_FUNCS([gettimeofday], [], [],
143 #ifdef TIME_WITH_SYS_TIME
144 # include <sys/time.h>
147 # if defined(HAVE_SYS_TIME_H)
148 # include <sys/time.h>
149 # elif define(HAVE_TIME_H)
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>
163 # if defined(HAVE_SYS_TIME_H)
164 # include <sys/time.h>
165 # elif define(HAVE_TIME_H)
170 struct timeval tm; /* we MUST NOT shadow the global time symbol, fuck it */
171 gettimeofday(&tm, 0);
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])
179 if test "$gettimeofday_nargs" = "1"; then
181 AC_DEFINE([GETTIMEOFDAY_ONE_ARGUMENT], [1],
182 [Legacy shit! Use GETTIMEOFDAY_NARGS instead!])
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>
194 # if defined(HAVE_SYS_TIME_H)
195 # include <sys/time.h>
196 # elif define(HAVE_TIME_H)
201 struct timespec time;
202 #if GETTIMEOFDAY_NARGS == 1
204 #elif GETTIMEOFDAY_NARGS == 2
205 gettimeofday(&time, 0);
207 !@#$% VERY_UNLIKELY_TO_COMPILE )(*&^
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'])
217 ])dnl SXE_CHECK_GETTIMEOFDAY
219 AC_DEFUN([SXE_CHECK_DO_GETTIMEOFDAY], [dnl
220 AC_CHECK_FUNCS([do_gettimeofday], [], [],
222 #ifdef HAVE_LINUX_TIME_H
223 # include <linux/time.h>
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>
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])
243 ])dnl SXE_CHECK_DO_GETTIMEOFDAY
245 AC_DEFUN([SXE_CHECK_CURRENT_KERNEL_TIME], [dnl
246 AC_CHECK_FUNCS([current_kernel_time], [], [],
248 #ifdef HAVE_LINUX_TIME_H
249 # include <linux/time.h>
253 if test "$ac_cv_type_struct_timespec" = "yes" \
254 -a "$ac_cv_func_current_kernel_time" = "yes"; then
257 ])dnl SXE_CHECK_CURRENT_KERNEL_TIME
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
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])
275 ## assume we havent got any of prerequisites
278 SXE_CHECK_TIME_HEADERS
282 ## checks for structure members
286 ## check for struct timeval
287 SXE_CHECK_TYPE_STRUCT_TIMEVAL
288 SXE_CHECK_TYPE_STRUCT_TIMESPEC
289 SXE_CHECK_TYPE_TIME_T
291 SXE_CHECK_GETTIMEOFDAY
292 SXE_CHECK_DO_GETTIMEOFDAY
293 SXE_CHECK_CURRENT_KERNEL_TIME
294 SXE_CHECK_CLOCK_GETTIME
296 if test "$ac_cv_type_struct_timeval" = "yes" \
297 -a "$ac_cv_func_gettimeofday" = "yes"; then
301 if test "$ac_cv_type_struct_timespec" = "yes" \
302 -a "$ac_cv_func_do_gettimeofday" = "yes"; then
306 if test "$ac_cv_type_struct_timespec" = "yes" \
307 -a "$ac_cv_func_current_kernel_time" = "yes"; then
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
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!])
324 ])dnl SXE_CHECK_METRONOME
326 dnl sxe-datetime.m4 ends here