configure script will now define HAVE_CLOCK_GETTIME_MONOTONIC symbol only
authorYang Tse <yangsita@gmail.com>
Mon, 12 May 2008 02:04:22 +0000 (02:04 +0000)
committerYang Tse <yangsita@gmail.com>
Mon, 12 May 2008 02:04:22 +0000 (02:04 +0000)
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.

acinclude.m4
ares__timeval.c
configure.ac

index 2a7bc02f6e15838c42b23ef00db8c0981230e56c..fb00d0981e0aebc1027d5fa4984a4b610b3a43e2 100644 (file)
@@ -1283,29 +1283,16 @@ 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 clock_gettime in libraries])
-  #
-  curl_cv_save_LIBS="$LIBS"
-  curl_cv_gclk_LIBS="unknown"
-  #
-  for x_xlibs in '' '-lrt' '-lposix4' ; do
-    if test -z "$x_xlibs"; then
-      LIBS="$curl_cv_save_LIBS"
-    else
-      LIBS="$x_xlibs $curl_cv_save_LIBS"
-    fi
-    AC_LINK_IFELSE([
-      AC_LANG_PROGRAM([
-#undef inline
+  AC_MSG_CHECKING([for monotonic clock_gettime])
+  AC_COMPILE_IFELSE([
+    AC_LANG_PROGRAM([
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
@@ -1319,43 +1306,98 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME], [
 #include <time.h>
 #endif
 #endif
-      ],[
-        (void)clock_gettime(0, 0);
-      ])
     ],[
-       curl_cv_gclk_LIBS="$x_xlibs"
-       break
+      struct timespec ts;
+      (void)clock_gettime(CLOCK_MONOTONIC, &ts);
     ])
-  done
-  #
-  LIBS="$curl_cv_save_LIBS"
+  ],[
+    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
   #
-  case X-"$curl_cv_gclk_LIBS" in
-    X-unknown)
-      AC_MSG_RESULT([cannot find clock_gettime])
-      ac_cv_func_clock_gettime="no"
-      ;;
-    X-)
-      AC_MSG_RESULT([no additional lib required])
-      ac_cv_func_clock_gettime="yes"
-      ;;
-    *)
-      if test -z "$curl_cv_save_LIBS"; then
-        LIBS="$curl_cv_gclk_LIBS"
+  if test "$ac_cv_func_clock_gettime" = "yes"; then
+    #
+    AC_MSG_CHECKING([for clock_gettime in libraries])
+    #
+    curl_cv_save_LIBS="$LIBS"
+    curl_cv_gclk_LIBS="unknown"
+    #
+    for x_xlibs in '' '-lrt' '-lposix4' ; do
+      if test -z "$x_xlibs"; then
+        LIBS="$curl_cv_save_LIBS"
       else
-        LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
+        LIBS="$x_xlibs $curl_cv_save_LIBS"
       fi
-      AC_MSG_RESULT([$curl_cv_gclk_LIBS])
-      ac_cv_func_clock_gettime="yes"
-      ;;
-  esac
-  #
-  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.])
-      ;;
-  esac
+      AC_LINK_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);
+        ])
+      ],[
+         curl_cv_gclk_LIBS="$x_xlibs"
+         break
+      ])
+    done
+    #
+    LIBS="$curl_cv_save_LIBS"
+    #
+    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-)
+        AC_MSG_RESULT([no additional lib required])
+        ac_cv_func_clock_gettime="yes"
+        ;;
+      *)
+        if test -z "$curl_cv_save_LIBS"; then
+          LIBS="$curl_cv_gclk_LIBS"
+        else
+          LIBS="$curl_cv_gclk_LIBS $curl_cv_save_LIBS"
+        fi
+        AC_MSG_RESULT([$curl_cv_gclk_LIBS])
+        ac_cv_func_clock_gettime="yes"
+        ;;
+    esac
+    #
+    case "$ac_cv_func_clock_gettime" in
+      yes)
+        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
 
index 2fbf1688c22e7f897ba08011c7edcb6de5310096..6de6c655284601f4756326756d2b4dd2fe60edbe 100644 (file)
@@ -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)
 {
index 28f90c8abdaec539c6cd28922f3298da28a16d19..70dbcce18849e52912cbb0dbe1ff96f07f684cfc 100644 (file)
@@ -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,