Skip to content

Commit 98bd66f

Browse files
authored
Simplify clock_gettime Autoconf check (#13537)
The clock_gettime() is found in libc on modern systems, except on Solaris <= 10 and possible similar systems, it is in the rt library. This checks if clock_gettime() exists in the libc, then it checks if rt library has clock_gettime, prepends it to LIBS and defines the HAVE_CLOCK_GETTIME symbol with the template from the AC_CHECK_FUNCS. The ac_cv_func_clock_gettime is a cache variable set by AC_CHECK_FUNCS.
1 parent ba401cf commit 98bd66f

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

sapi/fpm/config.m4

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,14 @@ PHP_ARG_ENABLE([fpm],,
77
dnl Configure checks.
88
AC_DEFUN([AC_FPM_CLOCK],
99
[
10-
have_clock_gettime=no
11-
12-
AC_MSG_CHECKING([for clock_gettime])
13-
14-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);]])], [
15-
have_clock_gettime=yes
16-
AC_MSG_RESULT([yes])
17-
], [
18-
AC_MSG_RESULT([no])
19-
])
20-
21-
if test "$have_clock_gettime" = "no"; then
22-
AC_MSG_CHECKING([for clock_gettime in -lrt])
23-
24-
SAVED_LIBS="$LIBS"
25-
LIBS="$LIBS -lrt"
26-
27-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]], [[struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);]])], [
28-
have_clock_gettime=yes
29-
AC_MSG_RESULT([yes])
30-
], [
31-
LIBS="$SAVED_LIBS"
32-
AC_MSG_RESULT([no])
33-
])
34-
fi
35-
36-
if test "$have_clock_gettime" = "yes"; then
37-
AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [do we have clock_gettime?])
38-
fi
10+
AC_CHECK_FUNCS([clock_gettime],,
11+
[AC_SEARCH_LIBS([clock_gettime], [rt],
12+
[ac_cv_func_clock_gettime=yes
13+
AC_DEFINE([HAVE_CLOCK_GETTIME], [1])])])
3914
4015
have_clock_get_time=no
4116
42-
if test "$have_clock_gettime" = "no"; then
17+
if test "$ac_cv_func_clock_gettime" = "no"; then
4318
AC_MSG_CHECKING([for clock_get_time])
4419
4520
AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <mach/mach.h>

0 commit comments

Comments
 (0)