summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt1
-rwxr-xr-xconfigure153
-rw-r--r--configure.in42
-rw-r--r--src/common/timer.c2
4 files changed, 177 insertions, 21 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index f7ca75961..aebf857ad 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -1,6 +1,7 @@
Date Added
2011/04/05
+ * Moved detection of monotonic clock support to the configure script, which also checks, whether or not it actually works (bugreport:1003, related r11912 and r11983). [Ai4rei]
* Paying and obtaining Zeny (pc_payzeny/pc_getzeny) no longer silently reverses the effect for negative amounts, that is, getting Zeny instead of paying up and vice versa (since r8273, related r8072). [Ai4rei]
2011/03/29
* Added TargetName values to VS2010 project files to prevent MSB8012 warnings (follow-up to r14562). [Gepard]
diff --git a/configure b/configure
index 5da692cf7..9200993f7 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
#! /bin/sh
-# From configure.in Revision: 14708 .
+# From configure.in Revision: 14767 .
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.59.
#
@@ -4884,16 +4884,15 @@ fi
#
-# clock_gettime (rt on Debian)
+# clock_gettime (optional, rt on Debian)
#
-
-echo "$as_me:$LINENO: checking for clock_gettime in -lrt" >&5
-echo $ECHO_N "checking for clock_gettime in -lrt... $ECHO_C" >&6
-if test "${ac_cv_lib_rt_clock_gettime+set}" = set; then
+echo "$as_me:$LINENO: checking for library containing clock_gettime" >&5
+echo $ECHO_N "checking for library containing clock_gettime... $ECHO_C" >&6
+if test "${ac_cv_search_clock_gettime+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lrt $LIBS"
+ ac_func_search_save_LIBS=$LIBS
+ac_cv_search_clock_gettime=no
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
@@ -4938,28 +4937,146 @@ if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
- ac_cv_lib_rt_clock_gettime=yes
+ ac_cv_search_clock_gettime="none required"
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
-ac_cv_lib_rt_clock_gettime=no
fi
rm -f conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-echo "$as_me:$LINENO: result: $ac_cv_lib_rt_clock_gettime" >&5
-echo "${ECHO_T}$ac_cv_lib_rt_clock_gettime" >&6
-if test $ac_cv_lib_rt_clock_gettime = yes; then
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBRT 1
+if test "$ac_cv_search_clock_gettime" = no; then
+ for ac_lib in rt; do
+ LIBS="-l$ac_lib $ac_func_search_save_LIBS"
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
- LIBS="-lrt $LIBS"
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char clock_gettime ();
+int
+main ()
+{
+clock_gettime ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_search_clock_gettime="-l$ac_lib"
+break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ done
+fi
+LIBS=$ac_func_search_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_search_clock_gettime" >&5
+echo "${ECHO_T}$ac_cv_search_clock_gettime" >&6
+if test "$ac_cv_search_clock_gettime" != no; then
+ test "$ac_cv_search_clock_gettime" = "none required" || LIBS="$ac_cv_search_clock_gettime $LIBS"
+
+fi
+
+
+
+#
+# CLOCK_MONOTONIC clock for clock_gettime
+# Normally defines _POSIX_TIMERS > 0 and _POSIX_MONOTONIC_CLOCK (for posix
+# compliant systems) and __FreeBSD_cc_version >= 500005 (for FreeBSD
+# >= 5.1.0, which does not have the posix defines (ref. r11983)) would be
+# checked but some systems define them even when they do not support it
+# (ref. bugreport:1003).
+#
+if test "$ac_cv_search_clock_gettime" != "no" ; then
+ echo "$as_me:$LINENO: checking whether CLOCK_MONOTONIC is supported and works" >&5
+echo $ECHO_N "checking whether CLOCK_MONOTONIC is supported and works... $ECHO_C" >&6
+ if test "$cross_compiling" = yes; then
+
+ echo "$as_me:$LINENO: result: guessing no" >&5
+echo "${ECHO_T}guessing no" >&6
+
+
+else
+ cat >conftest.$ac_ext <<_ACEOF
+
+ #include <sys/time.h>
+ #include <time.h>
+ #include <unistd.h>
+
+ int main(int argc, char** argv)
+ {
+ struct timespec tval;
+ return clock_gettime(CLOCK_MONOTONIC, &tval);
+ }
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+ CFLAGS="$CFLAGS -DHAVE_MONOTONIC_CLOCK"
+
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+
+ # either it failed to compile (CLOCK_MONOTONIC undefined)
+ # or clock_gettime has returned a non-zero value
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+fi
#
diff --git a/configure.in b/configure.in
index c659ad142..6407cda1b 100644
--- a/configure.in
+++ b/configure.in
@@ -576,9 +576,47 @@ AC_SEARCH_LIBS([sqrt], [m], [], [AC_MSG_ERROR([math library not found... stoppin
#
-# clock_gettime (rt on Debian)
+# clock_gettime (optional, rt on Debian)
#
-AC_CHECK_LIB([rt], [clock_gettime])
+AC_SEARCH_LIBS([clock_gettime], [rt])
+
+
+#
+# CLOCK_MONOTONIC clock for clock_gettime
+# Normally defines _POSIX_TIMERS > 0 and _POSIX_MONOTONIC_CLOCK (for posix
+# compliant systems) and __FreeBSD_cc_version >= 500005 (for FreeBSD
+# >= 5.1.0, which does not have the posix defines (ref. r11983)) would be
+# checked but some systems define them even when they do not support it
+# (ref. bugreport:1003).
+#
+if test "$ac_cv_search_clock_gettime" != "no" ; then
+ AC_MSG_CHECKING([whether CLOCK_MONOTONIC is supported and works])
+ AC_RUN_IFELSE(
+ [
+ #include <sys/time.h>
+ #include <time.h>
+ #include <unistd.h>
+
+ int main(int argc, char** argv)
+ {
+ struct timespec tval;
+ return clock_gettime(CLOCK_MONOTONIC, &tval);
+ }
+ ],
+ [
+ AC_MSG_RESULT([yes])
+ CFLAGS="$CFLAGS -DHAVE_MONOTONIC_CLOCK"
+ ],
+ [
+ # either it failed to compile (CLOCK_MONOTONIC undefined)
+ # or clock_gettime has returned a non-zero value
+ AC_MSG_RESULT([no])
+ ],
+ [
+ AC_MSG_RESULT([guessing no])
+ ]
+ )
+fi
#
diff --git a/src/common/timer.c b/src/common/timer.c
index 190e41eaf..86e148ee3 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -146,7 +146,7 @@ static unsigned int tick(void)
//
return (unsigned int)((_rdtsc() - RDTSC_BEGINTICK) / RDTSC_CLOCK);
//
-#elif (defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) /* posix compliant */) || (defined(__FreeBSD_cc_version) && __FreeBSD_cc_version >= 500005 /* FreeBSD >= 5.1.0 */)
+#elif defined(HAVE_MONOTONIC_CLOCK)
struct timespec tval;
clock_gettime(CLOCK_MONOTONIC, &tval);
return tval.tv_sec * 1000 + tval.tv_nsec / 1000000;