commit 47e011c33d78a00015265be39f2845209eeb97fc Author: Jonathan Wakely Date: Sun Feb 3 20:45:51 2013 +0000 * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Add KIND=auto to enable features if target OS is known to support them. * configure.ac (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Default to 'auto'. * configure: Regenerate. diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 619fff0..efeb6d4 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -871,7 +871,8 @@ dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING) dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, permit a|b|c) dnl (FEATURE, DEFAULT, HELP-ARG, HELP-STRING, SHELL-CODE-HANDLER) dnl -dnl See docs/html/17_intro/configury.html#enable for documentation. +dnl See manual/appendix_porting.html#appendix.porting.build_hacking for +dnl documentation. dnl m4_define([GLIBCXX_ENABLE],[dnl m4_define([_g_switch],[--enable-$1])dnl @@ -1161,8 +1162,9 @@ dnl nanosleep and sched_yield in libc and libposix4 and, if needed, dnl links in the latter. dnl --enable-libstdcxx-time=rt dnl also searches (and, if needed, links) librt. Note that this is -dnl not always desirable because, in glibc, for example, in turn it -dnl triggers the linking of libpthread too, which activates locking, +dnl not always desirable because, in glibc 2.16 and earlier, for +dnl example, in turn it triggers the linking of libpthread too, +dnl which activates locking, dnl a large overhead for single-thread programs. dnl --enable-libstdcxx-time=no dnl --disable-libstdcxx-time @@ -1175,8 +1177,7 @@ dnl os_defines.h and also defines _GLIBCXX_USE_SCHED_YIELD. dnl AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ - AC_MSG_CHECKING([for clock_gettime, nanosleep and sched_yield]) - GLIBCXX_ENABLE(libstdcxx-time,$1,[[[=KIND]]], + GLIBCXX_ENABLE(libstdcxx-time,auto,[[[=KIND]]], [use KIND for check type], [permit yes|no|rt]) @@ -1188,9 +1189,59 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ ac_has_clock_monotonic=no ac_has_clock_realtime=no - AC_MSG_RESULT($enable_libstdcxx_time) + ac_has_nanosleep=no + ac_has_sched_yield=no + + if test x"$enable_libstdcxx_time" = x"auto"; then + + case "${target_os}" in + cygwin*) + ac_has_nanosleep=yes + ;; + darwin*) + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu) + AC_MSG_CHECKING([for at least GNU libc 2.17]) + AC_TRY_COMPILE( + [#include ], + [ + #if ! __GLIBC_PREREQ(2, 17) + #error + #endif + ], + [glibcxx_glibc217=yes], [glibcxx_glibc217=no]) + AC_MSG_RESULT($glibcxx_glibc217) + + if test x"$glibcxx_glibc217" = x"yes"; then + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + fi + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + freebsd*|netbsd*) + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + openbsd*) + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + ac_has_nanosleep=yes + ;; + solaris*) + GLIBCXX_LIBS="$GLIBCXX_LIBS -lrt" + ac_has_clock_monotonic=yes + ac_has_clock_realtime=yes + ac_has_nanosleep=yes + ac_has_sched_yield=yes + ;; + esac - if test x"$enable_libstdcxx_time" != x"no"; then + elif test x"$enable_libstdcxx_time" != x"no"; then if test x"$enable_libstdcxx_time" = x"rt"; then AC_SEARCH_LIBS(clock_gettime, [rt posix4]) @@ -1214,19 +1265,16 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ case "$ac_cv_search_sched_yield" in -lposix4*) GLIBCXX_LIBS="$GLIBCXX_LIBS $ac_cv_search_sched_yield" - AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, - [ Defined if sched_yield is available. ]) + ac_has_sched_yield=yes ;; -lrt*) if test x"$enable_libstdcxx_time" = x"rt"; then GLIBCXX_LIBS="$GLIBCXX_LIBS $ac_cv_search_sched_yield" - AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, - [ Defined if sched_yield is available. ]) + ac_has_sched_yield=yes fi ;; *) - AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, - [ Defined if sched_yield is available. ]) + ac_has_sched_yield=yes ;; esac @@ -1284,6 +1332,11 @@ AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [ [ Defined if clock_gettime has realtime clock support. ]) fi + if test x"$ac_has_sched_yield" = x"yes"; then + AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1, + [ Defined if sched_yield is available. ]) + fi + if test x"$ac_has_nanosleep" = x"yes"; then AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1, [ Defined if nanosleep is available. ]) diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 73d430a..f6ba176 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -198,8 +198,7 @@ GLIBCXX_COMPUTE_STDIO_INTEGER_CONSTANTS GLIBCXX_CHECK_GETTIMEOFDAY # For clock_gettime, nanosleep and sched_yield support. -# NB: The default is [no], because otherwise it requires linking. -GLIBCXX_ENABLE_LIBSTDCXX_TIME([no]) +GLIBCXX_ENABLE_LIBSTDCXX_TIME AC_LC_MESSAGES