Commit ed80eb5b authored by Yang Tse's avatar Yang Tse
Browse files

configure script will now define HAVE_CLOCK_GETTIME_MONOTONIC symbol only

when function clock_gettime() is available and the monotonic timer is
also available. Otherwise, in some cases, librt or libposix4 could be used
for linking even when finally not using the clock_gettime() function due
to lack of the monotonic clock.
parent 60dd765b
Loading
Loading
Loading
Loading
+93 −51
Original line number Diff line number Diff line
@@ -1814,14 +1814,53 @@ AC_DEFUN([TYPE_IN_ADDR_T],
  ]) dnl AC_CHECK_TYPE
]) dnl AC_DEFUN

dnl CURL_CHECK_LIBS_CLOCK_GETTIME
dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
dnl -------------------------------------------------
dnl Check for libraries needed for clock_gettime,
dnl and prepended to LIBS any needed libraries.
dnl Check if monotonic clock_gettime is available.

AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
  AC_REQUIRE([AC_HEADER_TIME])dnl
  AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
  AC_MSG_CHECKING([for monotonic clock_gettime])
  AC_COMPILE_IFELSE([
    AC_LANG_PROGRAM([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#else
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#endif
    ],[
      struct timespec ts;
      (void)clock_gettime(CLOCK_MONOTONIC, &ts);
    ])
  ],[
    AC_MSG_RESULT([yes])
    ac_cv_func_clock_gettime="yes"
  ],[
    AC_MSG_RESULT([no])
    ac_cv_func_clock_gettime="no"
  ])
  dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally
  dnl postponed until library linking checks for clock_gettime pass.
]) dnl AC_DEFUN

dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
dnl -------------------------------------------------
dnl If monotonic clock_gettime is available then,
dnl check and prepended to LIBS any needed libraries.

AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
  AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
  #
  if test "$ac_cv_func_clock_gettime" = "yes"; then
    #
    AC_MSG_CHECKING([for clock_gettime in libraries])
    #
@@ -1836,7 +1875,6 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
      fi
      AC_LINK_IFELSE([
        AC_LANG_PROGRAM([
#undef inline
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -1851,7 +1889,8 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
#endif
#endif
        ],[
        (void)clock_gettime(0, 0);
          struct timespec ts;
          (void)clock_gettime(CLOCK_MONOTONIC, &ts);
        ])
      ],[
         curl_cv_gclk_LIBS="$x_xlibs"
@@ -1864,6 +1903,7 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
    case X-"$curl_cv_gclk_LIBS" in
      X-unknown)
        AC_MSG_RESULT([cannot find clock_gettime])
        AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
        ac_cv_func_clock_gettime="no"
        ;;
      X-)
@@ -1883,11 +1923,13 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
    #
    case "$ac_cv_func_clock_gettime" in
      yes)
      AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME, 1,
        [Define to 1 if you have the clock_gettime function.])
        AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
          [Define to 1 if you have the clock_gettime function and monotonic timer.])
        ;;
    esac
    #
  fi
  #
]) dnl AC_DEFUN

dnl ************************************************************
+93 −51
Original line number Diff line number Diff line
@@ -1283,14 +1283,53 @@ AC_DEFUN([TYPE_IN_ADDR_T],
  ]) dnl AC_CHECK_TYPE
]) dnl AC_DEFUN

dnl CURL_CHECK_LIBS_CLOCK_GETTIME
dnl CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC
dnl -------------------------------------------------
dnl Check for libraries needed for clock_gettime,
dnl and prepended to LIBS any needed libraries.
dnl Check if monotonic clock_gettime is available.

AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
AC_DEFUN([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC], [
  AC_REQUIRE([AC_HEADER_TIME])dnl
  AC_CHECK_HEADERS(sys/types.h sys/time.h time.h)
  AC_MSG_CHECKING([for monotonic clock_gettime])
  AC_COMPILE_IFELSE([
    AC_LANG_PROGRAM([
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#ifdef TIME_WITH_SYS_TIME
#include <time.h>
#endif
#else
#ifdef HAVE_TIME_H
#include <time.h>
#endif
#endif
    ],[
      struct timespec ts;
      (void)clock_gettime(CLOCK_MONOTONIC, &ts);
    ])
  ],[
    AC_MSG_RESULT([yes])
    ac_cv_func_clock_gettime="yes"
  ],[
    AC_MSG_RESULT([no])
    ac_cv_func_clock_gettime="no"
  ])
  dnl Definition of HAVE_CLOCK_GETTIME_MONOTONIC is intentionally
  dnl postponed until library linking checks for clock_gettime pass.
]) dnl AC_DEFUN

dnl CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
dnl -------------------------------------------------
dnl If monotonic clock_gettime is available then,
dnl check and prepended to LIBS any needed libraries.

AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
  AC_REQUIRE([CURL_CHECK_FUNC_CLOCK_GETTIME_MONOTONIC])dnl
  #
  if test "$ac_cv_func_clock_gettime" = "yes"; then
    #
    AC_MSG_CHECKING([for clock_gettime in libraries])
    #
@@ -1305,7 +1344,6 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
      fi
      AC_LINK_IFELSE([
        AC_LANG_PROGRAM([
#undef inline
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
@@ -1320,7 +1358,8 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
#endif
#endif
        ],[
        (void)clock_gettime(0, 0);
          struct timespec ts;
          (void)clock_gettime(CLOCK_MONOTONIC, &ts);
        ])
      ],[
         curl_cv_gclk_LIBS="$x_xlibs"
@@ -1333,6 +1372,7 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
    case X-"$curl_cv_gclk_LIBS" in
      X-unknown)
        AC_MSG_RESULT([cannot find clock_gettime])
        AC_MSG_WARN([HAVE_CLOCK_GETTIME_MONOTONIC will not be defined])
        ac_cv_func_clock_gettime="no"
        ;;
      X-)
@@ -1352,11 +1392,13 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
    #
    case "$ac_cv_func_clock_gettime" in
      yes)
      AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME, 1,
        [Define to 1 if you have the clock_gettime function.])
        AC_DEFINE_UNQUOTED(HAVE_CLOCK_GETTIME_MONOTONIC, 1,
          [Define to 1 if you have the clock_gettime function and monotonic timer.])
        ;;
    esac
    #
  fi
  #
]) dnl AC_DEFUN

dnl **********************************************************************
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ struct timeval ares__tvnow(void)
  return now;
}

#elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
#elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)

struct timeval ares__tvnow(void)
{
+3 −2
Original line number Diff line number Diff line
@@ -261,9 +261,10 @@ dnl socket lib?
AC_CHECK_FUNC(connect, , [ AC_CHECK_LIB(socket, connect) ])

dnl **********************************************************************
dnl Check for libraries needed for function clock_gettime
dnl In case that function clock_gettime with monotonic timer is available,
dnl check for additional required libraries.
dnl **********************************************************************
CURL_CHECK_LIBS_CLOCK_GETTIME
CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC

AC_MSG_CHECKING([whether to use libgcc])
AC_ARG_ENABLE(libgcc,
+3 −2
Original line number Diff line number Diff line
@@ -568,9 +568,10 @@ dnl socket lib?
AC_CHECK_FUNC(connect, , [ AC_CHECK_LIB(socket, connect) ])

dnl **********************************************************************
dnl Check for libraries needed for function clock_gettime
dnl In case that function clock_gettime with monotonic timer is available,
dnl check for additional required libraries.
dnl **********************************************************************
CURL_CHECK_LIBS_CLOCK_GETTIME
CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC

dnl **********************************************************************
dnl The preceding library checks are all potentially useful for test
Loading