| 1 |
# clock_time.m4 |
| 2 |
# serial 14 |
| 3 |
dnl Copyright (C) 2002-2006, 2009-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
# Check for clock_getres, clock_gettime and clock_settime, |
| 10 |
# and set CLOCK_TIME_LIB. |
| 11 |
# For a program named, say foo, you should add a line like the following |
| 12 |
# in the corresponding Makefile.am file: |
| 13 |
# foo_LDADD = $(LDADD) $(CLOCK_TIME_LIB) |
| 14 |
|
| 15 |
AC_DEFUN([gl_CLOCK_TIME], |
| 16 |
[ |
| 17 |
AC_REQUIRE([AC_CANONICAL_HOST]) |
| 18 |
|
| 19 |
dnl Persuade glibc and Solaris <time.h> to declare these functions. |
| 20 |
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) |
| 21 |
|
| 22 |
# On mingw, these functions are defined in the libwinpthread library, |
| 23 |
# which is better avoided. In fact, the clock_gettime function is buggy |
| 24 |
# in 32-bit mingw, when -D__MINGW_USE_VC2005_COMPAT is used (which Gnulib's |
| 25 |
# year2038 module does): It leaves the upper 32 bits of the tv_sec field |
| 26 |
# of the result uninitialized. |
| 27 |
|
| 28 |
# Solaris 2.5.1 needs -lposix4 to get the clock_gettime function. |
| 29 |
# Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4. |
| 30 |
|
| 31 |
# Save and restore LIBS so e.g., -lrt, isn't added to it. Otherwise, *all* |
| 32 |
# programs in the package would end up linked with that potentially-shared |
| 33 |
# library, inducing unnecessary run-time overhead. |
| 34 |
CLOCK_TIME_LIB= |
| 35 |
AC_SUBST([CLOCK_TIME_LIB]) |
| 36 |
case "$host_os" in |
| 37 |
mingw* | windows*) |
| 38 |
ac_cv_func_clock_getres=no |
| 39 |
ac_cv_func_clock_gettime=no |
| 40 |
ac_cv_func_clock_settime=no |
| 41 |
;; |
| 42 |
*) |
| 43 |
gl_saved_libs=$LIBS |
| 44 |
AC_SEARCH_LIBS([clock_gettime], [rt posix4], |
| 45 |
[test "$ac_cv_search_clock_gettime" = "none required" || |
| 46 |
CLOCK_TIME_LIB=$ac_cv_search_clock_gettime]) |
| 47 |
AC_CHECK_FUNCS([clock_getres clock_gettime clock_settime]) |
| 48 |
LIBS=$gl_saved_libs |
| 49 |
;; |
| 50 |
esac |
| 51 |
|
| 52 |
# For backward compatibility. |
| 53 |
LIB_CLOCK_GETTIME="$CLOCK_TIME_LIB" |
| 54 |
AC_SUBST([LIB_CLOCK_GETTIME]) |
| 55 |
]) |