]> oss.titaniummirror.com Git - msp430-gcc.git/blobdiff - libstdc++-v3/acinclude.m4
Imported gcc-4.4.3
[msp430-gcc.git] / libstdc++-v3 / acinclude.m4
index 6393278193951135425ffe7b9d890b5f0ba02dbb..186916c2e47e75b5c9ee07a35c2981414934e147 100644 (file)
+
 dnl
-dnl Initialize configure bits.
-dnl
-dnl GLIBCPP_TOPREL_CONFIGURE
-AC_DEFUN(GLIBCPP_TOPREL_CONFIGURE, [
-  dnl Default to --enable-multilib (this is also passed by default
-  dnl from the ubercommon-top-level configure)
-  AC_ARG_ENABLE(multilib,
-  [  --enable-multilib       build hella library versions (default)],
-  [case "${enableval}" in
-    yes) multilib=yes ;;
-    no)  multilib=no ;;
-    *)   AC_MSG_ERROR(bad value ${enableval} for multilib option) ;;
-   esac], [multilib=yes])dnl
-
-  # When building with srcdir == objdir, links to the source files will
-  # be created in directories within the target_subdir.  We have to
-  # adjust toplevel_srcdir accordingly, so that configure finds
-  # install-sh and other auxiliary files that live in the top-level
-  # source directory.
-  if test "${srcdir}" = "."; then
-    if test -z "${with_target_subdir}"; then
-      toprel=".."
-    else
-      if test "${with_target_subdir}" != "."; then
-        toprel="${with_multisrctop}../.."
-      else
-        toprel="${with_multisrctop}.."
-      fi
-    fi
-  else
-    toprel=".."
-  fi
-  AC_CONFIG_AUX_DIR(${srcdir}/$toprel)
-  toplevel_srcdir=\${top_srcdir}/$toprel
-  AC_SUBST(toplevel_srcdir)
-])
+dnl GLIBCXX_CONDITIONAL (NAME, SHELL-TEST)
+dnl
+dnl Exactly like AM_CONDITIONAL, but delays evaluation of the test until the
+dnl end of configure.  This lets tested variables be reassigned, and the
+dnl conditional will depend on the final state of the variable.  For a simple
+dnl example of why this is needed, see GLIBCXX_ENABLE_HOSTED.
+dnl
+m4_define([_m4_divert(glibcxx_diversion)], 8000)dnl
+AC_DEFUN([GLIBCXX_CONDITIONAL], [dnl
+  m4_divert_text([glibcxx_diversion],dnl
+   AM_CONDITIONAL([$1],[$2])
+  )dnl
+])dnl
+AC_DEFUN([GLIBCXX_EVALUATE_CONDITIONALS], [m4_undivert([glibcxx_diversion])])dnl
+
 
 dnl
-dnl Initialize configure bits.
+dnl Check to see what architecture and operating system we are compiling
+dnl for.  Also, if architecture- or OS-specific flags are required for
+dnl compilation, pick them up here.
 dnl
-dnl GLIBCPP_CONFIGURE
-AC_DEFUN(GLIBCPP_CONFIGURE, [
+AC_DEFUN([GLIBCXX_CHECK_HOST], [
+  . $glibcxx_srcdir/configure.host
+  AC_MSG_NOTICE([CPU config directory is $cpu_include_dir])
+  AC_MSG_NOTICE([OS config directory is $os_include_dir])
+])
 
-#possibly test for the presence of the compiler sources here?
+dnl
+dnl Initialize the rest of the library configury.  At this point we have
+dnl variables like $host.
+dnl
+dnl Sets:
+dnl  SUBDIRS
+dnl Substs:
+dnl  glibcxx_builddir     (absolute path)
+dnl  glibcxx_srcdir       (absolute path)
+dnl  toplevel_srcdir      (absolute path)
+dnl  with_cross_host
+dnl  with_newlib
+dnl  with_target_subdir
+dnl plus
+dnl  - the variables in GLIBCXX_CHECK_HOST / configure.host
+dnl  - default settings for all AM_CONFITIONAL test variables
+dnl  - lots of tools, like CC and CXX
+dnl
+AC_DEFUN([GLIBCXX_CONFIGURE], [
+  # Keep these sync'd with the list in Makefile.am.  The first provides an
+  # expandable list at autoconf time; the second provides an expandable list
+  # (i.e., shell variable) at configure time.
+  m4_define([glibcxx_SUBDIRS],[include libsupc++ src doc po testsuite])
+  SUBDIRS='glibcxx_SUBDIRS'
 
-  # Export build and source directories.
   # These need to be absolute paths, yet at the same time need to
   # canonicalize only relative paths, because then amd will not unmount
   # drives. Thus the use of PWDCMD: set it to 'pawd' or 'amq -w' if using amd.
-  glibcpp_builddir=`${PWDCMD-pwd}`
+  glibcxx_builddir=`${PWDCMD-pwd}`
   case $srcdir in
-  [\\/$]* | ?:[\\/]*) glibcpp_srcdir=${srcdir} ;;
-  *) glibcpp_srcdir=`cd "$srcdir" && ${PWDCMD-pwd} || echo "$srcdir"` ;;
+    [\\/$]* | ?:[\\/]*) glibcxx_srcdir=${srcdir} ;;
+    *) glibcxx_srcdir=`cd "$srcdir" && ${PWDCMD-pwd} || echo "$srcdir"` ;;
   esac
-  AC_SUBST(glibcpp_builddir)
-  AC_SUBST(glibcpp_srcdir)
-
-  dnl This is here just to satisfy automake.
-  ifelse(not,equal,[AC_CONFIG_AUX_DIR(..)])
+  toplevel_srcdir=${glibcxx_srcdir}/..
+  AC_SUBST(glibcxx_builddir)
+  AC_SUBST(glibcxx_srcdir)
+  AC_SUBST(toplevel_srcdir)
 
-  AC_PROG_AWK
-  # Will set LN_S to either 'ln -s' or 'ln'.  With autoconf 2.5x, can also
-  # be 'cp -p' if linking isn't available.  Uncomment the next line to
-  # force a particular method.
-  #ac_cv_prog_LN_S='cp -p'
+  # We use these options to decide which functions to include.  They are
+  # set from the top level.
+  AC_ARG_WITH([target-subdir],
+    AC_HELP_STRING([--with-target-subdir=SUBDIR],
+                   [configuring in a subdirectory]))
+
+  AC_ARG_WITH([cross-host],
+    AC_HELP_STRING([--with-cross-host=HOST],
+                   [configuring with a cross compiler]))
+
+  AC_ARG_WITH([newlib],
+    AC_HELP_STRING([--with-newlib],
+                   [assume newlib as a system C library]))
+
+  # We're almost certainly being configured before anything else which uses
+  # C++, so all of our AC_PROG_* discoveries will be cached.  It's vital that
+  # we not cache the value of CXX that we "discover" here, because it's set
+  # to something unique for us and libjava.  Other target libraries need to
+  # find CXX for themselves.  We yank the rug out from under the normal AC_*
+  # process by sneakily renaming the cache variable.  This also lets us debug
+  # the value of "our" CXX in postmortems.
+  #
+  # We must also force CXX to /not/ be a precious variable, otherwise the
+  # wrong (non-multilib-adjusted) value will be used in multilibs.  This
+  # little trick also affects CPPFLAGS, CXXFLAGS, and LDFLAGS.  And as a side
+  # effect, CXXFLAGS is no longer automagically subst'd, so we have to do
+  # that ourselves.  Un-preciousing AC_PROG_CC also affects CC and CFLAGS.
+  #
+  # -fno-builtin must be present here so that a non-conflicting form of
+  # std::exit can be guessed by AC_PROG_CXX, and used in later tests.
+
+  m4_define([ac_cv_prog_CXX],[glibcxx_cv_prog_CXX])
+  m4_rename([_AC_ARG_VAR_PRECIOUS],[glibcxx_PRECIOUS])
+  m4_define([_AC_ARG_VAR_PRECIOUS],[])
+  save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-builtin"
+  AC_PROG_CC
+  AC_PROG_CXX
+  CXXFLAGS="$save_CXXFLAGS"
+  m4_rename([glibcxx_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
+  AC_SUBST(CFLAGS)
+  AC_SUBST(CXXFLAGS)
+
+  # Will set LN_S to either 'ln -s', 'ln', or 'cp -p' (if linking isn't
+  # available).  Uncomment the next line to force a particular method.
   AC_PROG_LN_S
-
-  # We use these options to decide which functions to include.
-  AC_ARG_WITH(target-subdir,
-  [  --with-target-subdir=SUBDIR
-                          configuring in a subdirectory])
-  AC_ARG_WITH(cross-host,
-  [  --with-cross-host=HOST  configuring with a cross compiler])
-
-  glibcpp_basedir=$srcdir/$toprel/$1/libstdc++-v3
-  AC_SUBST(glibcpp_basedir)
-
-  # Never versions of autoconf add an underscore to these functions.
-  # Prevent future problems ...
-  ifdef([AC_PROG_CC_G],[],[define([AC_PROG_CC_G],defn([_AC_PROG_CC_G]))])
-  ifdef([AC_PROG_CC_GNU],[],[define([AC_PROG_CC_GNU],defn([_AC_PROG_CC_GNU]))])
-  ifdef([AC_PROG_CXX_G],[],[define([AC_PROG_CXX_G],defn([_AC_PROG_CXX_G]))])
-  ifdef([AC_PROG_CXX_GNU],[],[define([AC_PROG_CXX_GNU],defn([_AC_PROG_CXX_GNU]))])
-
-  # AC_PROG_CC
-  # FIXME: We temporarily define our own version of AC_PROG_CC.  This is
-  # copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS.  We
-  # are probably using a cross compiler, which will not be able to fully
-  # link an executable.  This is addressed in later versions of autoconf.
-
-  AC_DEFUN(LIB_AC_PROG_CC,
-  [AC_BEFORE([$0], [AC_PROG_CPP])dnl
-  dnl Fool anybody using AC_PROG_CC.
-  AC_PROVIDE([AC_PROG_CC])
-  AC_CHECK_PROG(CC, gcc, gcc)
-  if test -z "$CC"; then
-    AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
-    test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
-  fi
-
-  AC_PROG_CC_GNU
-
-  if test $ac_cv_prog_gcc = yes; then
-    GCC=yes
-  dnl Check whether -g works, even if CFLAGS is set, in case the package
-  dnl plays around with CFLAGS (such as to build both debugging and
-  dnl normal versions of a library), tasteless as that idea is.
-    ac_test_CFLAGS="${CFLAGS+set}"
-    ac_save_CFLAGS="$CFLAGS"
-    CFLAGS=
-    AC_PROG_CC_G
-    if test "$ac_test_CFLAGS" = set; then
-      CFLAGS="$ac_save_CFLAGS"
-    elif test $ac_cv_prog_cc_g = yes; then
-      CFLAGS="-g -O2"
-    else
-      CFLAGS="-O2"
-    fi
-  else
-    GCC=
-    test "${CFLAGS+set}" = set || CFLAGS="-g"
-  fi
-  ])
-
-  LIB_AC_PROG_CC
-
-  # Likewise for AC_PROG_CXX.  We can't just call it directly because g++
-  # will try to link in libstdc++.
-  AC_DEFUN(LIB_AC_PROG_CXX,
-  [AC_BEFORE([$0], [AC_PROG_CXXCPP])dnl
-  dnl Fool anybody using AC_PROG_CXX.
-  AC_PROVIDE([AC_PROG_CXX])
-  # Use glibcpp_CXX so that we do not cause CXX to be cached with the
-  # flags that come in CXX while configuring libstdc++.  They're different
-  # from those used for all other target libraries.  If CXX is set in
-  # the environment, respect that here.
-  glibcpp_CXX=$CXX
-  AC_CHECK_PROGS(glibcpp_CXX, $CCC c++ g++ gcc CC cxx cc++, gcc)
-  AC_SUBST(glibcpp_CXX)
-  CXX=$glibcpp_CXX
-  test -z "$glibcpp_CXX" && AC_MSG_ERROR([no acceptable c++ found in \$PATH])
-
-  AC_PROG_CXX_GNU
-
-  if test $ac_cv_prog_gxx = yes; then
-    GXX=yes
-    dnl Check whether -g works, even if CXXFLAGS is set, in case the package
-    dnl plays around with CXXFLAGS (such as to build both debugging and
-    dnl normal versions of a library), tasteless as that idea is.
-    ac_test_CXXFLAGS="${CXXFLAGS+set}"
-    ac_save_CXXFLAGS="$CXXFLAGS"
-    CXXFLAGS=
-    AC_PROG_CXX_G
-    if test "$ac_test_CXXFLAGS" = set; then
-      CXXFLAGS="$ac_save_CXXFLAGS"
-    elif test $ac_cv_prog_cxx_g = yes; then
-      CXXFLAGS="-g -O2"
-    else
-      CXXFLAGS="-O2"
-    fi
-  else
-    GXX=
-    test "${CXXFLAGS+set}" = set || CXXFLAGS="-g"
-  fi
-  ])
-
-  LIB_AC_PROG_CXX
-
-  # For directory versioning (e.g., headers) and other variables.
-  AC_MSG_CHECKING([for GCC version number])
-  gcc_version=`$glibcpp_CXX -dumpversion`
-  AC_MSG_RESULT($gcc_version)
-
-  # For some reason, gettext needs this.
-  AC_ISC_POSIX
+  #LN_S='cp -p'
 
   AC_CHECK_TOOL(AS, as)
   AC_CHECK_TOOL(AR, ar)
   AC_CHECK_TOOL(RANLIB, ranlib, ranlib-not-found-in-path-error)
-  AC_PROG_INSTALL
 
   AM_MAINTAINER_MODE
 
-  # We need AC_EXEEXT to keep automake happy in cygnus mode.  However,
-  # at least currently, we never actually build a program, so we never
-  # need to use $(EXEEXT).  Moreover, the test for EXEEXT normally
-  # fails, because we are probably configuring with a cross compiler
-  # which can't create executables.  So we include AC_EXEEXT to keep
-  # automake happy, but we don't execute it, since we don't care about
-  # the result.
-  if false; then
-    # autoconf 2.50 runs AC_EXEEXT by default, and the macro expands
-    # to nothing, so nothing would remain between `then' and `fi' if it
-    # were not for the `:' below.
-    :
-    AC_EXEEXT
-  fi
-
-  case [$]{glibcpp_basedir} in
-    /* | [A-Za-z]:[\\/]*) libgcj_flagbasedir=[$]{glibcpp_basedir} ;;
-    *) glibcpp_flagbasedir='[$](top_builddir)/'[$]{glibcpp_basedir} ;;
-  esac
-
-  # Find platform-specific directories containing configuration info.  In
-  # addition to possibly modifying the same flags, it also sets up symlinks.
-  GLIBCPP_CHECK_TARGET
-])
-
-
-dnl
-dnl Check to see if g++ can compile this library, and if so, if any version-
-dnl specific precautions need to be taken. 
-dnl 
-dnl GLIBCPP_CHECK_COMPILER_VERSION
-AC_DEFUN(GLIBCPP_CHECK_COMPILER_VERSION, [
-if test ! -f stamp-sanity-compiler; then
-  AC_MSG_CHECKING([for g++ that will successfully compile libstdc++-v3])
-  AC_LANG_SAVE
-  AC_LANG_CPLUSPLUS
-  AC_TRY_COMPILE(, [
-  #if __GNUC__ < 3
-    not_ok
+  # Set up safe default values for all subsequent AM_CONDITIONAL tests
+  # which are themselves conditionally expanded.
+  ## (Right now, this only matters for enable_wchar_t, but nothing prevents
+  ## other macros from doing the same.  This should be automated.)  -pme
+
+  # Check for uClibc since Linux platforms use different configuration
+  # directories depending on the C library in use.
+  AC_EGREP_CPP([_using_uclibc], [
+  #include <stdio.h>
+  #if __UCLIBC__
+    _using_uclibc
   #endif
-  ], gpp_satisfactory=yes, AC_MSG_ERROR([please upgrade to GCC 3.0 or above]))
-  AC_LANG_RESTORE
-  AC_MSG_RESULT($gpp_satisfactory)
-  touch stamp-sanity-compiler
-fi
+  ], uclibc=yes, uclibc=no)
+
+  # Find platform-specific directories containing configuration info.
+  # Also possibly modify flags used elsewhere, as needed by the platform.
+  GLIBCXX_CHECK_HOST
 ])
 
 
@@ -235,18 +144,17 @@ dnl Tests for newer compiler features, or features that are present in newer
 dnl compiler versions but not older compiler versions still in use, should
 dnl be placed here.
 dnl
-dnl Define WERROR='-Werror' if requested and possible; g++'s that lack the
-dnl new inlining code or the new system_header pragma will die on -Werror.
-dnl Leave it out by default and use maint-mode to use it.
-dnl
-dnl Define SECTION_FLAGS='-ffunction-sections -fdata-sections' if
-dnl compiler supports it and the user has not requested debug mode.
+dnl Defines:
+dnl  WERROR='-Werror' if requested and possible; g++'s that lack the
+dnl   new inlining code or the new system_header pragma will die on -Werror.
+dnl   Leave it out by default and use maint-mode to use it.
+dnl  SECTION_FLAGS='-ffunction-sections -fdata-sections' if
+dnl   compiler supports it and the user has not requested debug mode.
 dnl
-dnl GLIBCPP_CHECK_COMPILER_FEATURES
-AC_DEFUN(GLIBCPP_CHECK_COMPILER_FEATURES, [
+AC_DEFUN([GLIBCXX_CHECK_COMPILER_FEATURES], [
   # All these tests are for C++; save the language and the compiler flags.
   # The CXXFLAGS thing is suspicious, but based on similar bits previously
-  # found in GLIBCPP_CONFIGURE.
+  # found in GLIBCXX_CONFIGURE.
   AC_LANG_SAVE
   AC_LANG_CPLUSPLUS
   ac_test_CXXFLAGS="${CXXFLAGS+set}"
@@ -261,17 +169,15 @@ AC_DEFUN(GLIBCPP_CHECK_COMPILER_FEATURES, [
 
   # Check for -ffunction-sections -fdata-sections
   AC_MSG_CHECKING([for g++ that supports -ffunction-sections -fdata-sections])
-  CXXFLAGS='-Werror -ffunction-sections -fdata-sections'
-  AC_TRY_COMPILE(, [int foo;
-  ], [ac_fdsections=yes], [ac_fdsections=no])
+  CXXFLAGS='-g -Werror -ffunction-sections -fdata-sections'
+  AC_TRY_COMPILE([int foo; void bar() { };],, [ac_fdsections=yes], [ac_fdsections=no])
   if test "$ac_test_CXXFLAGS" = set; then
     CXXFLAGS="$ac_save_CXXFLAGS"
   else
     # this is the suspicious part
     CXXFLAGS=''
   fi
-  if test x"$ac_fdsections" = x"yes" &&
-     test x"$enable_debug" = x"no"; then
+  if test x"$ac_fdsections" = x"yes"; then
     SECTION_FLAGS='-ffunction-sections -fdata-sections'
   fi
   AC_MSG_RESULT($ac_fdsections)
@@ -287,19 +193,26 @@ dnl If GNU ld is in use, check to see if tricky linker opts can be used.  If
 dnl the native linker is in use, all variables will be defined to something
 dnl safe (like an empty string).
 dnl
-dnl Define SECTION_LDFLAGS='-Wl,--gc-sections' if possible.
-dnl Define OPT_LDFLAGS='-Wl,-O1' if possible.
-dnl Define LD, with_gnu_ld, and (possibly) glibcpp_gnu_ld_version as
-dnl side-effects of testing.
+dnl Defines:
+dnl  SECTION_LDFLAGS='-Wl,--gc-sections' if possible
+dnl  OPT_LDFLAGS='-Wl,-O1' and '-z,relro' if possible
+dnl  LD (as a side effect of testing)
+dnl Sets:
+dnl  with_gnu_ld
+dnl  glibcxx_ld_is_gold (set to "no" or "yes")
+dnl  glibcxx_gnu_ld_version (possibly)
 dnl
-dnl GLIBCPP_CHECK_LINKER_FEATURES
-AC_DEFUN(GLIBCPP_CHECK_LINKER_FEATURES, [
+dnl The last will be a single integer, e.g., version 1.23.45.0.67.89 will
+dnl set glibcxx_gnu_ld_version to 12345.  Zeros cause problems.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_LINKER_FEATURES], [
   # If we're not using GNU ld, then there's no point in even trying these
   # tests.  Check for that first.  We should have already tested for gld
   # by now (in libtool), but require it now just to be safe...
   test -z "$SECTION_LDFLAGS" && SECTION_LDFLAGS=''
   test -z "$OPT_LDFLAGS" && OPT_LDFLAGS=''
   AC_REQUIRE([AC_PROG_LD])
+  AC_REQUIRE([AC_PROG_AWK])
 
   # The name set by libtool depends on the version of libtool.  Shame on us
   # for depending on an impl detail, but c'est la vie.  Older versions used
@@ -318,53 +231,87 @@ AC_DEFUN(GLIBCPP_CHECK_LINKER_FEATURES, [
 
   # Start by getting the version number.  I think the libtool test already
   # does some of this, but throws away the result.
-  changequote(,)
-  ldver=`$LD --version 2>/dev/null | head -1 | \
-         sed -e 's/GNU ld version \([0-9.][0-9.]*\).*/\1/'`
-  changequote([,])
-  glibcpp_gnu_ld_version=`echo $ldver | \
-         $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
+  glibcxx_ld_is_gold=no
+  if test x"$with_gnu_ld" = x"yes"; then
+    AC_MSG_CHECKING([for ld version])
+    changequote(,)
+    if $LD --version 2>/dev/null | grep 'GNU gold' >/dev/null 2>&1; then
+      glibcxx_ld_is_gold=yes
+    fi
+    ldver=`$LD --version 2>/dev/null | head -1 | \
+           sed -e 's/GNU \(go\)\{0,1\}ld \(version \)\{0,1\}\(([^)]*) \)\{0,1\}\([0-9.][0-9.]*\).*/\4/'`
+    changequote([,])
+    glibcxx_gnu_ld_version=`echo $ldver | \
+           $AWK -F. '{ if (NF<3) [$]3=0; print ([$]1*100+[$]2)*100+[$]3 }'`
+    AC_MSG_RESULT($glibcxx_gnu_ld_version)
+  fi
 
   # Set --gc-sections.
-  if test "$with_gnu_ld" = "notbroken"; then
-    # GNU ld it is!  Joy and bunny rabbits!
+  glibcxx_have_gc_sections=no
+  if test "$glibcxx_ld_is_gold" = "yes"; then
+    if $LD --help 2>/dev/null | grep gc-sections >/dev/null 2>&1; then
+      glibcxx_have_gc_sections=yes
+    fi
+  else
+    glibcxx_gcsections_min_ld=21602
+    if test x"$with_gnu_ld" = x"yes" && 
+       test $glibcxx_gnu_ld_version -gt $glibcxx_gcsections_min_ld ; then
+      glibcxx_have_gc_sections=yes
+    fi
+  fi
+  if test "$glibcxx_have_gc_sections" = "yes"; then
+    # Sufficiently young GNU ld it is!  Joy and bunny rabbits!
+    # NB: This flag only works reliably after 2.16.1. Configure tests
+    # for this are difficult, so hard wire a value that should work.
 
-    # All these tests are for C++; save the language and the compiler flags.
-    # Need to do this so that g++ won't try to link in libstdc++
     ac_test_CFLAGS="${CFLAGS+set}"
     ac_save_CFLAGS="$CFLAGS"
-    CFLAGS='-x c++  -Wl,--gc-sections'
+    CFLAGS='-Wl,--gc-sections'
 
     # Check for -Wl,--gc-sections
-    # XXX This test is broken at the moment, as symbols required for
-    # linking are now in libsupc++ (not built yet.....). In addition, 
-    # this test has cored on solaris in the past. In addition,
-    # --gc-sections doesn't really work at the moment (keeps on discarding
-    # used sections, first .eh_frame and now some of the glibc sections for
-    # iconv). Bzzzzt. Thanks for playing, maybe next time.
     AC_MSG_CHECKING([for ld that supports -Wl,--gc-sections])
-    AC_TRY_RUN([
-     int main(void) 
-     {
-       try { throw 1; }
-       catch (...) { };
-       return 0;
-     }
-    ], [ac_sectionLDflags=yes],[ac_sectionLDflags=no], [ac_sectionLDflags=yes])
+    AC_TRY_LINK([ int one(void) { return 1; }
+     int two(void) { return 2; }
+       ], [ two(); ] , [ac_gcsections=yes], [ac_gcsections=no])
+    if test "$ac_gcsections" = "yes"; then
+      rm -f conftest.c
+      touch conftest.c
+      if $CC -c conftest.c; then
+       if $LD --gc-sections -o conftest conftest.o 2>&1 | \
+          grep "Warning: gc-sections option ignored" > /dev/null; then
+         ac_gcsections=no
+       fi
+      fi
+      rm -f conftest.c conftest.o conftest
+    fi
+    if test "$ac_gcsections" = "yes"; then
+      SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
+    fi
+    AC_MSG_RESULT($ac_gcsections)
+
     if test "$ac_test_CFLAGS" = set; then
       CFLAGS="$ac_save_CFLAGS"
     else
       # this is the suspicious part
       CFLAGS=''
     fi
-    if test "$ac_sectionLDflags" = "yes"; then
-      SECTION_LDFLAGS="-Wl,--gc-sections $SECTION_LDFLAGS"
+  fi
+
+  # Set -z,relro.
+  # Note this is only for shared objects.
+  ac_ld_relro=no
+  if test x"$with_gnu_ld" = x"yes"; then
+    AC_MSG_CHECKING([for ld that supports -Wl,-z,relro])
+    cxx_z_relo=`$LD -v --help 2>/dev/null | grep "z relro"`
+    if test -n "$cxx_z_relo"; then
+      OPT_LDFLAGS="-Wl,-z,relro"
+      ac_ld_relro=yes
     fi
-    AC_MSG_RESULT($ac_sectionLDflags)
+    AC_MSG_RESULT($ac_ld_relro)
   fi
 
   # Set linker optimization flags.
-  if test x"$with_gnu_ld" = x"yes" && test x"$enable_debug" = x"no"; then
+  if test x"$with_gnu_ld" = x"yes"; then
     OPT_LDFLAGS="-Wl,-O1 $OPT_LDFLAGS"
   fi
 
@@ -374,856 +321,1530 @@ AC_DEFUN(GLIBCPP_CHECK_LINKER_FEATURES, [
 
 
 dnl
-dnl Check to see if the (math function) argument passed is
-dnl declared when using the c++ compiler
-dnl ASSUMES argument is a math function with ONE parameter
-dnl
-dnl GLIBCPP_CHECK_MATH_DECL_1
-AC_DEFUN(GLIBCPP_CHECK_MATH_DECL_1, [
-  AC_MSG_CHECKING([for $1 declaration])
-  if test x${glibcpp_cv_func_$1_use+set} != xset; then
-    AC_CACHE_VAL(glibcpp_cv_func_$1_use, [
-      AC_LANG_SAVE
-      AC_LANG_CPLUSPLUS
-      AC_TRY_COMPILE([#include <math.h>
-                     #ifdef HAVE_IEEEFP_H
-                     #include <ieeefp.h>
-                     #endif
-                    ], 
-                     [ $1(0);], 
-                     [glibcpp_cv_func_$1_use=yes], [glibcpp_cv_func_$1_use=no])
-      AC_LANG_RESTORE
+dnl Check for headers for, and arguments to, the setrlimit() function.
+dnl Used only in testsuite_hooks.h.  Called from GLIBCXX_CONFIGURE_TESTSUITE.
+dnl
+dnl Defines:
+dnl  _GLIBCXX_RES_LIMITS if we can set artificial resource limits 
+dnl  various HAVE_LIMIT_* for individual limit names
+dnl
+AC_DEFUN([GLIBCXX_CHECK_SETRLIMIT_ancilliary], [
+  AC_MSG_CHECKING([for RLIMIT_$1])
+  AC_TRY_COMPILE(
+    [#include <unistd.h>
+     #include <sys/time.h>
+     #include <sys/resource.h>
+    ],
+    [ int f = RLIMIT_$1 ; ],
+    [glibcxx_mresult=1], [glibcxx_mresult=0])
+  AC_DEFINE_UNQUOTED(HAVE_LIMIT_$1, $glibcxx_mresult,
+                     [Only used in build directory testsuite_hooks.h.])
+  if test $glibcxx_mresult = 1 ; then res=yes ; else res=no ; fi
+  AC_MSG_RESULT($res)
+])
+
+AC_DEFUN([GLIBCXX_CHECK_SETRLIMIT], [
+  setrlimit_have_headers=yes
+  AC_CHECK_HEADERS(unistd.h sys/time.h sys/resource.h,
+                   [],
+                   [setrlimit_have_headers=no])
+  # If don't have the headers, then we can't run the tests now, and we
+  # won't be seeing any of these during testsuite compilation.
+  if test $setrlimit_have_headers = yes; then
+    # Can't do these in a loop, else the resulting syntax is wrong.
+    GLIBCXX_CHECK_SETRLIMIT_ancilliary(DATA)
+    GLIBCXX_CHECK_SETRLIMIT_ancilliary(RSS)
+    GLIBCXX_CHECK_SETRLIMIT_ancilliary(VMEM)
+    GLIBCXX_CHECK_SETRLIMIT_ancilliary(AS)
+    GLIBCXX_CHECK_SETRLIMIT_ancilliary(FSIZE)
+
+    # Check for rlimit, setrlimit.
+    AC_CACHE_VAL(glibcxx_cv_setrlimit, [
+      AC_TRY_COMPILE(
+        [#include <unistd.h>
+         #include <sys/time.h>
+         #include <sys/resource.h>
+        ],
+        [struct rlimit r;
+         setrlimit(0, &r);],
+        [glibcxx_cv_setrlimit=yes], [glibcxx_cv_setrlimit=no])
     ])
   fi
-  AC_MSG_RESULT($glibcpp_cv_func_$1_use)
-])
 
-dnl
-dnl Check to see if the (math function) argument passed is
-dnl 1) declared when using the c++ compiler
-dnl 2) has "C" linkage
-dnl 3) if not, see if 1) and 2) for argument prepended with '_'
-dnl
-dnl Define HAVE_CARGF etc if "cargf" is declared and links
-dnl
-dnl argument 1 is name of function to check
-dnl
-dnl ASSUMES argument is a math function with ONE parameter
-dnl
-dnl GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1
-AC_DEFUN(GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1, [
-  GLIBCPP_CHECK_MATH_DECL_1($1)
-  if test x$glibcpp_cv_func_$1_use = x"yes"; then
-    AC_CHECK_FUNCS($1)    
+  AC_MSG_CHECKING([for testsuite resource limits support])
+  if test $setrlimit_have_headers = yes && test $glibcxx_cv_setrlimit = yes; then
+    ac_res_limits=yes
+    AC_DEFINE(_GLIBCXX_RES_LIMITS, 1,
+              [Define if using setrlimit to set resource limits during
+              "make check"])
   else
-    GLIBCPP_CHECK_MATH_DECL_1(_$1)
-    if test x$glibcpp_cv_func__$1_use = x"yes"; then
-      AC_CHECK_FUNCS(_$1)    
-    fi
+    ac_res_limits=no
   fi
+  AC_MSG_RESULT($ac_res_limits)
 ])
 
 
 dnl
-dnl Like GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1, but does a bunch of
-dnl of functions at once.  It's an all-or-nothing check -- either 
-dnl HAVE_XYZ is defined for each of the functions, or for none of them.
-dnl Doing it this way saves significant configure time.
-AC_DEFUN(GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1, [
-  AC_MSG_CHECKING([for $1 functions])
-  AC_CACHE_VAL(glibcpp_cv_func_$2_use, [
-    AC_LANG_SAVE
-    AC_LANG_CPLUSPLUS
-    AC_TRY_COMPILE([#include <math.h>],
-                   [ `for x in $3; do echo "$x (0);"; done` ],
-                   [glibcpp_cv_func_$2_use=yes],
-                   [glibcpp_cv_func_$2_use=no])
-    AC_LANG_RESTORE])
-  AC_MSG_RESULT($glibcpp_cv_func_$2_use)
-  if test x$glibcpp_cv_func_$2_use = x"yes"; then
-    AC_CHECK_FUNCS($3)
+dnl Check whether S_ISREG (Posix) or S_IFREG is available in <sys/stat.h>.
+dnl Define HAVE_S_ISREG / HAVE_S_IFREG appropriately.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_S_ISREG_OR_S_IFREG], [
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
+
+  AC_MSG_CHECKING([for S_ISREG or S_IFREG])
+  AC_CACHE_VAL(glibcxx_cv_S_ISREG, [
+    GCC_TRY_COMPILE_OR_LINK(
+      [#include <sys/stat.h>],
+      [struct stat buffer;
+       fstat(0, &buffer);
+       S_ISREG(buffer.st_mode);],
+      [glibcxx_cv_S_ISREG=yes],
+      [glibcxx_cv_S_ISREG=no])
+  ])
+  AC_CACHE_VAL(glibcxx_cv_S_IFREG, [
+    GCC_TRY_COMPILE_OR_LINK(
+      [#include <sys/stat.h>],
+      [struct stat buffer;
+       fstat(0, &buffer);
+       S_IFREG & buffer.st_mode;],
+      [glibcxx_cv_S_IFREG=yes],
+      [glibcxx_cv_S_IFREG=no])
+  ])
+  res=no
+  if test $glibcxx_cv_S_ISREG = yes; then
+    AC_DEFINE(HAVE_S_ISREG, 1, 
+              [Define if S_IFREG is available in <sys/stat.h>.])
+    res=S_ISREG
+  elif test $glibcxx_cv_S_IFREG = yes; then
+    AC_DEFINE(HAVE_S_IFREG, 1,
+              [Define if S_IFREG is available in <sys/stat.h>.])
+    res=S_IFREG
   fi
+  AC_MSG_RESULT($res)
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
 ])
 
+
 dnl
-dnl Check to see if the (math function) argument passed is
-dnl declared when using the c++ compiler
-dnl ASSUMES argument is a math function with TWO parameters
-dnl
-dnl GLIBCPP_CHECK_MATH_DECL_2
-AC_DEFUN(GLIBCPP_CHECK_MATH_DECL_2, [
-  AC_MSG_CHECKING([for $1 declaration])
-  if test x${glibcpp_cv_func_$1_use+set} != xset; then
-    AC_CACHE_VAL(glibcpp_cv_func_$1_use, [
-      AC_LANG_SAVE
-      AC_LANG_CPLUSPLUS
-      AC_TRY_COMPILE([#include <math.h>], 
-                     [ $1(0, 0);], 
-                     [glibcpp_cv_func_$1_use=yes], [glibcpp_cv_func_$1_use=no])
-      AC_LANG_RESTORE
-    ])
+dnl Check whether poll is available in <poll.h>, and define HAVE_POLL.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_POLL], [
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
+
+  AC_MSG_CHECKING([for poll])
+  AC_CACHE_VAL(glibcxx_cv_POLL, [
+    GCC_TRY_COMPILE_OR_LINK(
+      [#include <poll.h>],
+      [struct pollfd pfd[1];
+       pfd[0].events = POLLIN;
+       poll(pfd, 1, 0);],
+      [glibcxx_cv_POLL=yes],
+      [glibcxx_cv_POLL=no])
+  ])
+  if test $glibcxx_cv_POLL = yes; then
+    AC_DEFINE(HAVE_POLL, 1, [Define if poll is available in <poll.h>.])
   fi
-  AC_MSG_RESULT($glibcpp_cv_func_$1_use)
+  AC_MSG_RESULT($glibcxx_cv_POLL)
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
 ])
 
+
 dnl
-dnl Check to see if the (math function) argument passed is
-dnl 1) declared when using the c++ compiler
-dnl 2) has "C" linkage
-dnl
-dnl Define HAVE_CARGF etc if "cargf" is declared and links
-dnl
-dnl argument 1 is name of function to check
-dnl
-dnl ASSUMES argument is a math function with TWO parameters
+dnl Check whether writev is available in <sys/uio.h>, and define HAVE_WRITEV.
 dnl
-dnl GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2
-AC_DEFUN(GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2, [
-  GLIBCPP_CHECK_MATH_DECL_2($1)
-  if test x$glibcpp_cv_func_$1_use = x"yes"; then
-    AC_CHECK_FUNCS($1)    
-  else
-    GLIBCPP_CHECK_MATH_DECL_2(_$1)
-    if test x$glibcpp_cv_func__$1_use = x"yes"; then
-      AC_CHECK_FUNCS(_$1)    
-    fi
+AC_DEFUN([GLIBCXX_CHECK_WRITEV], [
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
+
+  AC_MSG_CHECKING([for writev])
+  AC_CACHE_VAL(glibcxx_cv_WRITEV, [
+    GCC_TRY_COMPILE_OR_LINK(
+      [#include <sys/uio.h>],
+      [struct iovec iov[2];
+       writev(0, iov, 0);],
+      [glibcxx_cv_WRITEV=yes],
+      [glibcxx_cv_WRITEV=no])
+  ])
+  if test $glibcxx_cv_WRITEV = yes; then
+    AC_DEFINE(HAVE_WRITEV, 1, [Define if writev is available in <sys/uio.h>.])
   fi
+  AC_MSG_RESULT($glibcxx_cv_WRITEV)
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
 ])
 
 
 dnl
-dnl Check to see if the (math function) argument passed is
-dnl declared when using the c++ compiler
-dnl ASSUMES argument is a math function with THREE parameters
+dnl Check whether int64_t is available in <stdint.h>, and define HAVE_INT64_T.
+dnl Also check whether int64_t is actually a typedef to long or long long.
 dnl
-dnl GLIBCPP_CHECK_MATH_DECL_3
-AC_DEFUN(GLIBCPP_CHECK_MATH_DECL_3, [
-  AC_MSG_CHECKING([for $1 declaration])
-  if test x${glibcpp_cv_func_$1_use+set} != xset; then
-    AC_CACHE_VAL(glibcpp_cv_func_$1_use, [
-      AC_LANG_SAVE
-      AC_LANG_CPLUSPLUS
-      AC_TRY_COMPILE([#include <math.h>], 
-                     [ $1(0, 0, 0);], 
-                     [glibcpp_cv_func_$1_use=yes], [glibcpp_cv_func_$1_use=no])
-      AC_LANG_RESTORE
+AC_DEFUN([GLIBCXX_CHECK_INT64_T], [
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+
+  AC_MSG_CHECKING([for int64_t])
+  AC_CACHE_VAL(glibcxx_cv_INT64_T, [
+    AC_TRY_COMPILE(
+      [#include <stdint.h>],
+      [int64_t var;],
+      [glibcxx_cv_INT64_T=yes],
+      [glibcxx_cv_INT64_T=no])
+  ])
+
+  if test $glibcxx_cv_INT64_T = yes; then
+    AC_DEFINE(HAVE_INT64_T, 1, [Define if int64_t is available in <stdint.h>.])
+    AC_MSG_RESULT($glibcxx_cv_INT64_T)
+
+    AC_MSG_CHECKING([for int64_t as long])
+    AC_CACHE_VAL(glibcxx_cv_int64_t_long, [
+      AC_TRY_COMPILE(
+        [#include <stdint.h>
+        template<typename, typename> struct same { enum { value = -1 }; };
+        template<typename Tp> struct same<Tp, Tp> { enum { value = 1 }; };
+        int array[same<int64_t, long>::value];], [],
+       [glibcxx_cv_int64_t_long=yes], [glibcxx_cv_int64_t_long=no])
+    ])
+
+    if test $glibcxx_cv_int64_t_long = yes; then
+      AC_DEFINE(HAVE_INT64_T_LONG, 1, [Define if int64_t is a long.])
+      AC_MSG_RESULT($glibcxx_cv_int64_t_long)
+    fi
+
+    AC_MSG_CHECKING([for int64_t as long long])
+    AC_CACHE_VAL(glibcxx_cv_int64_t_long_long, [
+      AC_TRY_COMPILE(
+        [#include <stdint.h>
+        template<typename, typename> struct same { enum { value = -1 }; };
+        template<typename Tp> struct same<Tp, Tp> { enum { value = 1 }; };
+        int array[same<int64_t, long long>::value];], [],
+       [glibcxx_cv_int64_t_long_long=yes], [glibcxx_cv_int64_t_long_long=no])
     ])
+
+    if test $glibcxx_cv_int64_t_long_long = yes; then
+      AC_DEFINE(HAVE_INT64_T_LONG_LONG, 1, [Define if int64_t is a long long.])
+      AC_MSG_RESULT($glibcxx_cv_int64_t_long_long)
+    fi
   fi
-  AC_MSG_RESULT($glibcpp_cv_func_$1_use)
+
+  AC_LANG_RESTORE
 ])
 
+
 dnl
-dnl Check to see if the (math function) argument passed is
-dnl 1) declared when using the c++ compiler
-dnl 2) has "C" linkage
-dnl
-dnl Define HAVE_CARGF etc if "cargf" is declared and links
-dnl
-dnl argument 1 is name of function to check
-dnl
-dnl ASSUMES argument is a math function with THREE parameters
+dnl Check whether LFS support is available.
 dnl
-dnl GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_3
-AC_DEFUN(GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_3, [
-  GLIBCPP_CHECK_MATH_DECL_3($1)
-  if test x$glibcpp_cv_func_$1_use = x"yes"; then
-    AC_CHECK_FUNCS($1)    
-  else
-    GLIBCPP_CHECK_MATH_DECL_3(_$1)
-    if test x$glibcpp_cv_func__$1_use = x"yes"; then
-      AC_CHECK_FUNCS(_$1)    
-    fi
+AC_DEFUN([GLIBCXX_CHECK_LFS], [
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions" 
+  AC_MSG_CHECKING([for LFS support])
+  AC_CACHE_VAL(glibcxx_cv_LFS, [
+    GCC_TRY_COMPILE_OR_LINK(
+      [#include <unistd.h>
+       #include <stdio.h>
+       #include <sys/stat.h>
+      ],
+      [FILE* fp;
+       fopen64("t", "w");
+       fseeko64(fp, 0, SEEK_CUR);
+       ftello64(fp);
+       lseek64(1, 0, SEEK_CUR);
+       struct stat64 buf;
+       fstat64(1, &buf);],
+      [glibcxx_cv_LFS=yes],
+      [glibcxx_cv_LFS=no])
+  ])
+  if test $glibcxx_cv_LFS = yes; then
+    AC_DEFINE(_GLIBCXX_USE_LFS, 1, [Define if LFS support is available.])
   fi
+  AC_MSG_RESULT($glibcxx_cv_LFS)
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
 ])
 
 
 dnl
-dnl Check to see if the (stdlib function) argument passed is
-dnl 1) declared when using the c++ compiler
-dnl 2) has "C" linkage
-dnl
-dnl argument 1 is name of function to check
+dnl Check for whether a fully dynamic basic_string implementation should
+dnl be turned on, that does not put empty objects in per-process static
+dnl memory (mostly useful together with shared memory allocators, see PR
+dnl libstdc++/16612 for details).
 dnl
-dnl ASSUMES argument is a math function with TWO parameters
+dnl --enable-fully-dynamic-string defines _GLIBCXX_FULLY_DYNAMIC_STRING
+dnl --disable-fully-dynamic-string leaves _GLIBCXX_FULLY_DYNAMIC_STRING undefined
+dnl  +  Usage:  GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING[(DEFAULT)]
+dnl       Where DEFAULT is either `yes' or `no'.
 dnl
-dnl GLIBCPP_CHECK_STDLIB_DECL_AND_LINKAGE_2
-AC_DEFUN(GLIBCPP_CHECK_STDLIB_DECL_AND_LINKAGE_2, [
-  AC_MSG_CHECKING([for $1 declaration])
-  if test x${glibcpp_cv_func_$1_use+set} != xset; then
-    AC_CACHE_VAL(glibcpp_cv_func_$1_use, [
-      AC_LANG_SAVE
-      AC_LANG_CPLUSPLUS
-      AC_TRY_COMPILE([#include <stdlib.h>], 
-                     [ $1(0, 0);], 
-                     [glibcpp_cv_func_$1_use=yes], [glibcpp_cv_func_$1_use=no])
-      AC_LANG_RESTORE
-    ])
-  fi
-  AC_MSG_RESULT($glibcpp_cv_func_$1_use)
-  if test x$glibcpp_cv_func_$1_use = x"yes"; then
-    AC_CHECK_FUNCS($1)    
+AC_DEFUN([GLIBCXX_ENABLE_FULLY_DYNAMIC_STRING], [
+  GLIBCXX_ENABLE(fully-dynamic-string,$1,,[do not put empty strings in per-process static memory])
+  if test $enable_fully_dynamic_string = yes; then
+    AC_DEFINE(_GLIBCXX_FULLY_DYNAMIC_STRING, 1,
+              [Define if a fully dynamic basic_string is wanted.])
   fi
 ])
 
 
 dnl
-dnl Check to see if the (stdlib function) argument passed is
-dnl 1) declared when using the c++ compiler
-dnl 2) has "C" linkage
+dnl Does any necessary configuration of the testsuite directory.  Generates
+dnl the testsuite_hooks.h header.
 dnl
-dnl argument 1 is name of function to check
+dnl GLIBCXX_ENABLE_SYMVERS and GLIBCXX_IS_NATIVE must be done before this.
 dnl
-dnl ASSUMES argument is a function with THREE parameters
+dnl Sets:
+dnl  enable_abi_check 
+dnl  GLIBCXX_TEST_WCHAR_T
+dnl  GLIBCXX_TEST_THREAD
+dnl Substs:
+dnl  baseline_dir
 dnl
-dnl GLIBCPP_CHECK_STDLIB_DECL_AND_LINKAGE_3
-AC_DEFUN(GLIBCPP_CHECK_STDLIB_DECL_AND_LINKAGE_3, [
-  AC_MSG_CHECKING([for $1 declaration])
-  if test x${glibcpp_cv_func_$1_use+set} != xset; then
-    AC_CACHE_VAL(glibcpp_cv_func_$1_use, [
-      AC_LANG_SAVE
-      AC_LANG_CPLUSPLUS
-      AC_TRY_COMPILE([#include <stdlib.h>], 
-                     [ $1(0, 0, 0);], 
-                     [glibcpp_cv_func_$1_use=yes], [glibcpp_cv_func_$1_use=no])
-      AC_LANG_RESTORE
-    ])
+AC_DEFUN([GLIBCXX_CONFIGURE_TESTSUITE], [
+  if $GLIBCXX_IS_NATIVE ; then
+    # Do checks for resource limit functions.
+    GLIBCXX_CHECK_SETRLIMIT
+
+    # Look for setenv, so that extended locale tests can be performed.
+    GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_3(setenv)
   fi
-  AC_MSG_RESULT($glibcpp_cv_func_$1_use)
-  if test x$glibcpp_cv_func_$1_use = x"yes"; then
-    AC_CHECK_FUNCS($1)    
+
+  if $GLIBCXX_IS_NATIVE && test $is_hosted = yes &&
+     test $enable_symvers != no; then
+    case "$host" in
+      *-*-cygwin*)
+        enable_abi_check=no ;;
+      *)
+        enable_abi_check=yes ;;
+    esac
+  else
+    # Only build this as native, since automake does not understand
+    # CXX_FOR_BUILD.
+    enable_abi_check=no
   fi
+  
+  # Export file names for ABI checking.
+  baseline_dir="$glibcxx_srcdir/config/abi/post/${abi_baseline_pair}"
+  AC_SUBST(baseline_dir)
 ])
 
+
 dnl
-dnl Check to see if the (unistd function) argument passed is
-dnl 1) declared when using the c++ compiler
-dnl 2) has "C" linkage
-dnl
-dnl argument 1 is name of function to check
+dnl Set up *_INCLUDES variables for all sundry Makefile.am's.
 dnl
-dnl ASSUMES argument is a function with ONE parameter
+dnl Substs:
+dnl  GLIBCXX_INCLUDES
+dnl  TOPLEVEL_INCLUDES
 dnl
-dnl GLIBCPP_CHECK_UNISTD_DECL_AND_LINKAGE_1
-AC_DEFUN(GLIBCPP_CHECK_UNISTD_DECL_AND_LINKAGE_1, [
-  AC_MSG_CHECKING([for $1 declaration])
-  if test x${glibcpp_cv_func_$1_use+set} != xset; then
-    AC_CACHE_VAL(glibcpp_cv_func_$1_use, [
-      AC_LANG_SAVE
-      AC_LANG_CPLUSPLUS
-      AC_TRY_COMPILE([#include <unistd.h>], 
-                     [ $1(0);], 
-                     [glibcpp_cv_func_$1_use=yes], [glibcpp_cv_func_$1_use=no])
-      AC_LANG_RESTORE
-    ])
-  fi
-  AC_MSG_RESULT($glibcpp_cv_func_$1_use)
-  if test x$glibcpp_cv_func_$1_use = x"yes"; then
-    AC_CHECK_FUNCS($1)    
+AC_DEFUN([GLIBCXX_EXPORT_INCLUDES], [
+  # Used for every C++ compile we perform.
+  GLIBCXX_INCLUDES="\
+-I$glibcxx_builddir/include/$host_alias \
+-I$glibcxx_builddir/include \
+-I$glibcxx_srcdir/libsupc++"
+
+  # For Canadian crosses, pick this up too.
+  if test $CANADIAN = yes; then
+    GLIBCXX_INCLUDES="$GLIBCXX_INCLUDES -I\${includedir}"
   fi
+
+  # Stuff in the actual top level.  Currently only used by libsupc++ to
+  # get unwind* headers from the gcc dir.
+  #TOPLEVEL_INCLUDES='-I$(toplevel_srcdir)/gcc -I$(toplevel_srcdir)/include'
+  TOPLEVEL_INCLUDES='-I$(toplevel_srcdir)/gcc'
+
+  # Now, export this to all the little Makefiles....
+  AC_SUBST(GLIBCXX_INCLUDES)
+  AC_SUBST(TOPLEVEL_INCLUDES)
 ])
 
+
+dnl
+dnl Set up *_FLAGS and *FLAGS variables for all sundry Makefile.am's.
+dnl (SECTION_FLAGS is done under CHECK_COMPILER_FEATURES.)
 dnl
-dnl Because the builtins are picky picky picky about the arguments they take, 
-dnl do an explict linkage tests here.
-dnl Check to see if the (math function) argument passed is
-dnl 1) declared when using the c++ compiler
-dnl 2) has "C" linkage
+dnl Substs:
+dnl  OPTIMIZE_CXXFLAGS
+dnl  WARN_FLAGS
 dnl
-dnl Define HAVE_CARGF etc if "cargf" is declared and links
+AC_DEFUN([GLIBCXX_EXPORT_FLAGS], [
+  # Optimization flags that are probably a good idea for thrill-seekers. Just
+  # uncomment the lines below and make, everything else is ready to go...
+  # Alternatively OPTIMIZE_CXXFLAGS can be set in configure.host.
+  # OPTIMIZE_CXXFLAGS = -O3 -fstrict-aliasing -fvtable-gc
+  AC_SUBST(OPTIMIZE_CXXFLAGS)
+
+  WARN_FLAGS='-Wall -Wextra -Wwrite-strings -Wcast-qual'
+  AC_SUBST(WARN_FLAGS)
+])
+
+
 dnl
-dnl argument 1 is name of function to check
+dnl All installation directory information is determined here.
 dnl
-dnl ASSUMES argument is a math function with ONE parameter
+dnl Substs:
+dnl  gxx_install_dir
+dnl  glibcxx_prefixdir
+dnl  glibcxx_toolexecdir
+dnl  glibcxx_toolexeclibdir
 dnl
-dnl GLIBCPP_CHECK_BUILTIN_MATH_DECL_LINKAGE_1
-AC_DEFUN(GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1, [
-  AC_MSG_CHECKING([for $1 declaration])
-  if test x${glibcpp_cv_func_$1_use+set} != xset; then
-    AC_CACHE_VAL(glibcpp_cv_func_$1_use, [
-      AC_LANG_SAVE
-      AC_LANG_CPLUSPLUS
-      AC_TRY_COMPILE([#include <math.h>], 
-                     [ $1(0);], 
-                     [glibcpp_cv_func_$1_use=yes], [glibcpp_cv_func_$1_use=no])
-      AC_LANG_RESTORE
-    ])
+dnl Assumes cross_compiling bits already done, and with_cross_host in
+dnl particular.
+dnl
+dnl This logic must match gcc/configure.ac's setting of gcc_gxx_include_dir.
+dnl config/gxx-include-dir.m4 must be kept consistant with this as well.
+AC_DEFUN([GLIBCXX_EXPORT_INSTALL_INFO], [
+  glibcxx_toolexecdir=no
+  glibcxx_toolexeclibdir=no
+  glibcxx_prefixdir=$prefix
+
+  AC_MSG_CHECKING([for gxx-include-dir])
+  AC_ARG_WITH([gxx-include-dir],
+    AC_HELP_STRING([--with-gxx-include-dir=DIR],
+                   [installation directory for include files]),
+    [case "$withval" in
+      yes) AC_MSG_ERROR([Missing directory for --with-gxx-include-dir]) ;;
+      no)  gxx_include_dir=no ;;
+      *)   gxx_include_dir=$withval ;;
+     esac],
+    [gxx_include_dir=no])
+  AC_MSG_RESULT($gxx_include_dir)
+
+  AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
+  AC_ARG_ENABLE([version-specific-runtime-libs],
+    AC_HELP_STRING([--enable-version-specific-runtime-libs],
+                   [Specify that runtime libraries should be installed in a compiler-specific directory]),
+    [case "$enableval" in
+      yes) version_specific_libs=yes ;;
+      no)  version_specific_libs=no ;;
+      *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
+     esac],
+    [version_specific_libs=no])
+  AC_MSG_RESULT($version_specific_libs)
+
+  # Default case for install directory for include files.
+  if test $version_specific_libs = no && test $gxx_include_dir = no; then
+    gxx_include_dir='include/c++/${gcc_version}'
+    if test -n "$with_cross_host" && 
+       test x"$with_cross_host" != x"no"; then 
+      gxx_include_dir='${prefix}/${target_alias}/'"$gxx_include_dir"
+    else
+      gxx_include_dir='${prefix}/'"$gxx_include_dir"
+    fi
   fi
-  AC_MSG_RESULT($glibcpp_cv_func_$1_use)
-  if test x$glibcpp_cv_func_$1_use = x"yes"; then
-    AC_MSG_CHECKING([for $1 linkage])
-    if test x${glibcpp_cv_func_$1_link+set} != xset; then
-      AC_CACHE_VAL(glibcpp_cv_func_$1_link, [
-        AC_TRY_LINK([#include <math.h>], 
-                    [ $1(0);], 
-                    [glibcpp_cv_func_$1_link=yes], [glibcpp_cv_func_$1_link=no])
-      ])
+
+  # Version-specific runtime libs processing.
+  if test $version_specific_libs = yes; then
+    # Need the gcc compiler version to know where to install libraries
+    # and header files if --enable-version-specific-runtime-libs option
+    # is selected.  FIXME: these variables are misnamed, there are
+    # no executables installed in _toolexecdir or _toolexeclibdir.
+    if test x"$gxx_include_dir" = x"no"; then
+      gxx_include_dir='${libdir}/gcc/${host_alias}/${gcc_version}/include/c++'
     fi
-    AC_MSG_RESULT($glibcpp_cv_func_$1_link)
-    if test x$glibcpp_cv_func_$1_link = x"yes"; then
-      ac_tr_func=HAVE_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
-      AC_DEFINE_UNQUOTED(${ac_tr_func})
+    glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
+    glibcxx_toolexeclibdir='${toolexecdir}/${gcc_version}$(MULTISUBDIR)'
+  fi
+
+  # Calculate glibcxx_toolexecdir, glibcxx_toolexeclibdir
+  # Install a library built with a cross compiler in tooldir, not libdir.
+  if test x"$glibcxx_toolexecdir" = x"no"; then
+    if test -n "$with_cross_host" &&
+       test x"$with_cross_host" != x"no"; then
+      glibcxx_toolexecdir='${exec_prefix}/${host_alias}'
+      glibcxx_toolexeclibdir='${toolexecdir}/lib'
+    else
+      glibcxx_toolexecdir='${libdir}/gcc/${host_alias}'
+      glibcxx_toolexeclibdir='${libdir}'
     fi
+    multi_os_directory=`$CXX -print-multi-os-directory`
+    case $multi_os_directory in
+      .) ;; # Avoid trailing /.
+      *) glibcxx_toolexeclibdir=$glibcxx_toolexeclibdir/$multi_os_directory ;;
+    esac
   fi
+
+  AC_MSG_CHECKING([for install location])
+  AC_MSG_RESULT($gxx_include_dir)
+
+  AC_SUBST(glibcxx_prefixdir)
+  AC_SUBST(gxx_include_dir)
+  AC_SUBST(glibcxx_toolexecdir)
+  AC_SUBST(glibcxx_toolexeclibdir)
 ])
 
 
 dnl
-dnl Check to see what builtin math functions are supported
-dnl
-dnl check for __builtin_abs
-dnl check for __builtin_fabsf
-dnl check for __builtin_fabs
-dnl check for __builtin_fabl
-dnl check for __builtin_labs
-dnl check for __builtin_sqrtf
-dnl check for __builtin_sqrtl
-dnl check for __builtin_sqrt
-dnl check for __builtin_sinf
-dnl check for __builtin_sin
-dnl check for __builtin_sinl
-dnl check for __builtin_cosf
-dnl check for __builtin_cos
-dnl check for __builtin_cosl
-dnl
-dnl GLIBCPP_CHECK_BUILTIN_MATH_SUPPORT
-AC_DEFUN(GLIBCPP_CHECK_BUILTIN_MATH_SUPPORT, [
-  dnl Test for builtin math functions.
-  dnl These are made in gcc/c-common.c 
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_abs)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_fabsf)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_fabs)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_fabsl)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_labs)
-
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrtf)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrt)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrtl)
-
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sinf)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sin)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sinl)
-
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_cosf)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_cos)
-  GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_cosl)
-
-  dnl There is, without a doubt, a more elegant way to have these
-  dnl names exported so that they won't be stripped out of acconfig.h by
-  dnl autoheader. I leave this as an exercise to somebody less frustrated
-  dnl than I.... please email the libstdc++ list if you can figure out a
-  dnl more elegant approach (see autoconf/acgen.m4 and specifically
-  dnl AC_CHECK_FUNC for things to steal.)
-  dummyvar=no
-  if test x$dummyvar = x"yes"; then
-    AC_DEFINE(HAVE___BUILTIN_ABS)
-    AC_DEFINE(HAVE___BUILTIN_LABS)
-    AC_DEFINE(HAVE___BUILTIN_COS)
-    AC_DEFINE(HAVE___BUILTIN_COSF)
-    AC_DEFINE(HAVE___BUILTIN_COSL)
-    AC_DEFINE(HAVE___BUILTIN_FABS)
-    AC_DEFINE(HAVE___BUILTIN_FABSF)
-    AC_DEFINE(HAVE___BUILTIN_FABSL)
-    AC_DEFINE(HAVE___BUILTIN_SIN)
-    AC_DEFINE(HAVE___BUILTIN_SINF)
-    AC_DEFINE(HAVE___BUILTIN_SINL)
-    AC_DEFINE(HAVE___BUILTIN_SQRT)
-    AC_DEFINE(HAVE___BUILTIN_SQRTF)
-    AC_DEFINE(HAVE___BUILTIN_SQRTL)
-  fi
+dnl GLIBCXX_ENABLE
+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
+m4_define([GLIBCXX_ENABLE],[dnl
+m4_define([_g_switch],[--enable-$1])dnl
+m4_define([_g_help],[AC_HELP_STRING(_g_switch$3,[$4 @<:@default=$2@:>@])])dnl
+ AC_ARG_ENABLE($1,_g_help,
+  m4_bmatch([$5],
+   [^permit ],
+     [[
+      case "$enableval" in
+       m4_bpatsubst([$5],[permit ])) ;;
+       *) AC_MSG_ERROR(Unknown argument to enable/disable $1) ;;
+          dnl Idea for future:  generate a URL pointing to
+          dnl "onlinedocs/configopts.html#whatever"
+      esac
+     ]],
+   [^$],
+     [[
+      case "$enableval" in
+       yes|no) ;;
+       *) AC_MSG_ERROR(Argument to enable/disable $1 must be yes or no) ;;
+      esac
+     ]],
+   [[$5]]),
+  [enable_]m4_bpatsubst([$1],-,_)[=][$2])
+m4_undefine([_g_switch])dnl
+m4_undefine([_g_help])dnl
 ])
 
 
 dnl
-dnl Check to see what the underlying c library is like
-dnl These checks need to do two things: 
-dnl 1) make sure the name is declared when using the c++ compiler
-dnl 2) make sure the name has "C" linkage
-dnl This might seem like overkill but experience has shown that it's not...
+dnl Check for ISO/IEC 9899:1999 "C99" support.
 dnl
-dnl Define HAVE_STRTOLD if "strtold" is declared and links
-dnl Define HAVE_STRTOF if "strtof" is declared and links
-dnl Define HAVE_DRAND48 if "drand48" is declared and links
+dnl --enable-c99 defines _GLIBCXX_USE_C99
+dnl --disable-c99 leaves _GLIBCXX_USE_C99 undefined
+dnl  +  Usage:  GLIBCXX_ENABLE_C99[(DEFAULT)]
+dnl       Where DEFAULT is either `yes' or `no'.
+dnl  +  If 'C99' stuff is not available, ignores DEFAULT and sets `no'.
 dnl
-dnl GLIBCPP_CHECK_STDLIB_SUPPORT
-AC_DEFUN(GLIBCPP_CHECK_STDLIB_SUPPORT, [
-  ac_test_CXXFLAGS="${CXXFLAGS+set}"
-  ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS='-fno-builtins -D_GNU_SOURCE'
+AC_DEFUN([GLIBCXX_ENABLE_C99], [
+  GLIBCXX_ENABLE(c99,$1,,[turns on ISO/IEC 9899:1999 support])
 
-  GLIBCPP_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtold)
-  GLIBCPP_CHECK_STDLIB_DECL_AND_LINKAGE_2(strtof)
-  AC_CHECK_FUNCS(drand48)
+  if test x"$enable_c99" = x"yes"; then
 
-  CXXFLAGS="$ac_save_CXXFLAGS"
-])
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
 
-dnl
-dnl Check to see what the underlying c library is like
-dnl These checks need to do two things: 
-dnl 1) make sure the name is declared when using the c++ compiler
-dnl 2) make sure the name has "C" linkage
-dnl This might seem like overkill but experience has shown that it's not...
-dnl
-dnl Define HAVE_ISATTY if "isatty" is declared and links
-dnl
-dnl GLIBCPP_CHECK_UNISTD_SUPPORT
-AC_DEFUN(GLIBCPP_CHECK_UNISTD_SUPPORT, [
-  ac_test_CXXFLAGS="${CXXFLAGS+set}"
+  # Use -std=c++98 because the default (-std=gnu++98) leaves __STRICT_ANSI__
+  # undefined and fake C99 facilities - like pre-standard snprintf - may be
+  # spuriously enabled.
+  # Long term, -std=c++0x could be even better, could manage to explicitely
+  # request C99 facilities to the underlying C headers.
   ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS='-fno-builtins -D_GNU_SOURCE'
+  CXXFLAGS="$CXXFLAGS -std=c++98"
+  ac_save_LIBS="$LIBS"
+  ac_save_gcc_no_link="$gcc_no_link"
+
+  if test x$gcc_no_link != xyes; then
+    # Use -fno-exceptions to that the C driver can link these tests without
+    # hitting undefined references to personality routines.
+    CXXFLAGS="$CXXFLAGS -fno-exceptions"
+    AC_CHECK_LIB(m, sin, [
+      LIBS="$LIBS -lm"
+    ], [
+      # Use the default compile-only tests in GCC_TRY_COMPILE_OR_LINK
+      gcc_no_link=yes
+    ])
+  fi
 
-  GLIBCPP_CHECK_UNISTD_DECL_AND_LINKAGE_1(isatty)
-  
-  CXXFLAGS="$ac_save_CXXFLAGS"
-])
+  # Check for the existence of <math.h> functions used if C99 is enabled.
+  AC_MSG_CHECKING([for ISO C99 support in <math.h>])
+  AC_CACHE_VAL(glibcxx_cv_c99_math, [
+  GCC_TRY_COMPILE_OR_LINK(
+     [#include <math.h>
+      volatile double d1, d2;
+      volatile int i;],
+     [i = fpclassify(d1);
+      i = isfinite(d1);
+      i = isinf(d1);
+      i = isnan(d1);
+      i = isnormal(d1);
+      i = signbit(d1);
+      i = isgreater(d1, d2);
+      i = isgreaterequal(d1, d2);
+      i = isless(d1, d2);
+      i = islessequal(d1, d2);
+      i = islessgreater(d1, d2);
+      i = islessgreater(d1, d2);
+      i = isunordered(d1, d2);
+     ],[glibcxx_cv_c99_math=yes], [glibcxx_cv_c99_math=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_c99_math)
+  if test x"$glibcxx_cv_c99_math" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_MATH, 1,
+              [Define if C99 functions or macros in <math.h> should be imported
+              in <cmath> in namespace std.])
+  fi
 
-dnl
-dnl Check to see what the underlying c library or math library is like.
-dnl These checks need to do two things: 
-dnl 1) make sure the name is declared when using the c++ compiler
-dnl 2) make sure the name has "C" linkage
-dnl This might seem like overkill but experience has shown that it's not...
-dnl
-dnl Define HAVE_CARGF etc if "cargf" is found.
-dnl
-dnl GLIBCPP_CHECK_MATH_SUPPORT
-AC_DEFUN(GLIBCPP_CHECK_MATH_SUPPORT, [
-  ac_test_CXXFLAGS="${CXXFLAGS+set}"
-  ac_save_CXXFLAGS="$CXXFLAGS"
-  CXXFLAGS='-fno-builtins -D_GNU_SOURCE'
+  # Check for the existence of <complex.h> complex math functions.
+  # This is necessary even though libstdc++ uses the builtin versions
+  # of these functions, because if the builtin cannot be used, a reference
+  # to the library function is emitted.
+  AC_CHECK_HEADERS(tgmath.h, ac_has_tgmath_h=yes, ac_has_tgmath_h=no)
+  AC_CHECK_HEADERS(complex.h, ac_has_complex_h=yes, ac_has_complex_h=no)
+  glibcxx_cv_c99_complex=no;
+  if test x"$ac_has_complex_h" = x"yes"; then
+    AC_MSG_CHECKING([for ISO C99 support in <complex.h>])
+    GCC_TRY_COMPILE_OR_LINK(
+       [#include <complex.h>
+       typedef __complex__ float float_type;
+       typedef __complex__ double double_type;
+       typedef __complex__ long double ld_type;
+       volatile float_type tmpf;
+       volatile double_type tmpd;
+       volatile ld_type tmpld;
+       volatile float f;
+       volatile double d;
+       volatile long double ld;],
+       [f = cabsf(tmpf);
+       f = cargf(tmpf);
+       tmpf = ccosf(tmpf);
+       tmpf = ccoshf(tmpf);
+       tmpf = cexpf(tmpf);
+       tmpf = clogf(tmpf);
+       tmpf = csinf(tmpf);
+       tmpf = csinhf(tmpf);
+       tmpf = csqrtf(tmpf);
+       tmpf = ctanf(tmpf);
+       tmpf = ctanhf(tmpf);
+       tmpf = cpowf(tmpf, tmpf);
+       tmpf = cprojf(tmpf);
+       d = cabs(tmpd);
+       d = carg(tmpd);
+       tmpd = ccos(tmpd);
+       tmpd = ccosh(tmpd);
+       tmpd = cexp(tmpd);
+       tmpd = clog(tmpd);
+       tmpd = csin(tmpd);
+       tmpd = csinh(tmpd);
+       tmpd = csqrt(tmpd);
+       tmpd = ctan(tmpd);
+       tmpd = ctanh(tmpd);
+       tmpd = cpow(tmpd, tmpd);
+       tmpd = cproj(tmpd);
+       ld = cabsl(tmpld);
+       ld = cargl(tmpld);
+       tmpld = ccosl(tmpld);
+       tmpld = ccoshl(tmpld);
+       tmpld = cexpl(tmpld);
+       tmpld = clogl(tmpld);
+       tmpld = csinl(tmpld);
+       tmpld = csinhl(tmpld);
+       tmpld = csqrtl(tmpld);
+       tmpld = ctanl(tmpld);
+       tmpld = ctanhl(tmpld);
+       tmpld = cpowl(tmpld, tmpld);
+       tmpld = cprojl(tmpld);
+       ],[glibcxx_cv_c99_complex=yes], [glibcxx_cv_c99_complex=no])
+  fi
+  AC_MSG_RESULT($glibcxx_cv_c99_complex)
+  if test x"$glibcxx_cv_c99_complex" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_COMPLEX, 1,
+              [Define if C99 functions in <complex.h> should be used in
+              <complex>. Using compiler builtins for these functions requires
+              corresponding C99 library functions to be present.])
+  fi
 
-  dnl Check libm
-  AC_CHECK_LIB(m, sin, libm="-lm")
-  ac_save_LIBS="$LIBS"
-  LIBS="$LIBS $libm"
-
-  dnl Check to see if certain C math functions exist.
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(isinf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(isnan)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(finite)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(copysign)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_3(sincos)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(fpclass)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(qfpclass)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(hypot)
-
-  dnl Check to see if basic C math functions have float versions.
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(float trig,
-                                          float_trig,
-                                          acosf asinf atanf \
-                                          cosf sinf tanf \
-                                          coshf sinhf tanhf)
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(float round,
-                                          float_round,
-                                          ceilf floorf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(expf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(isnanf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(isinff)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(atan2f)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(fabsf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(fmodf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(frexpf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(hypotf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(ldexpf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(logf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(log10f)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(modff)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(powf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(sqrtf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_3(sincosf)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(finitef)
-
-  dnl Check to see if basic C math functions have long double versions.
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(long double trig,
-                                          long_double_trig,
-                                          acosl asinl atanl \
-                                          cosl sinl tanl \
-                                          coshl sinhl tanhl)
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(long double round,
-                                          long_double_round,
-                                          ceill floorl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(isnanl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(isinfl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(copysignl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(atan2l)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(expl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(fabsl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(fmodl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(frexpl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(hypotl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(ldexpl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(logl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(log10l)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(modfl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_2(powl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(sqrtl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_3(sincosl)
-  GLIBCPP_CHECK_MATH_DECL_AND_LINKAGE_1(finitel)
-
-  dnl Some runtimes have these functions with a preceding underscore. Please
-  dnl keep this sync'd with the one above. And if you add any new symbol,
-  dnl please add the corresponding block in the @BOTTOM@ section of acconfig.h.
-  dnl Check to see if certain C math functions exist.
-
-  dnl Check to see if basic C math functions have float versions.
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(_float trig,
-                                          _float_trig,
-                                          _acosf _asinf _atanf \
-                                          _cosf _sinf _tanf \
-                                          _coshf _sinhf _tanhf)
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(_float round,
-                                          _float_round,
-                                          _ceilf _floorf)
-
-  dnl Check to see if basic C math functions have long double versions.
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(_long double trig,
-                                          _long_double_trig,
-                                          _acosl _asinl _atanl \
-                                          _cosl _sinl _tanl \
-                                          _coshl _sinhl _tanhl)
-  GLIBCPP_CHECK_MATH_DECLS_AND_LINKAGES_1(_long double round,
-                                          _long_double_round,
-                                          _ceill _floorl)
+  # Check for the existence in <stdio.h> of vscanf, et. al.
+  AC_MSG_CHECKING([for ISO C99 support in <stdio.h>])
+  AC_CACHE_VAL(glibcxx_cv_c99_stdio, [
+  GCC_TRY_COMPILE_OR_LINK(
+     [#include <stdio.h>
+      #include <stdarg.h>
+      void foo(char* fmt, ...)
+      {
+       va_list args; va_start(args, fmt);
+       vfscanf(stderr, "%i", args); 
+       vscanf("%i", args);
+       vsnprintf(fmt, 0, "%i", args);
+       vsscanf(fmt, "%i", args);
+      }],
+     [snprintf("12", 0, "%i");],
+     [glibcxx_cv_c99_stdio=yes], [glibcxx_cv_c99_stdio=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_c99_stdio)
+
+  # Check for the existence in <stdlib.h> of lldiv_t, et. al.
+  AC_MSG_CHECKING([for ISO C99 support in <stdlib.h>])
+  AC_CACHE_VAL(glibcxx_cv_c99_stdlib, [
+  GCC_TRY_COMPILE_OR_LINK(
+     [#include <stdlib.h>
+      volatile float f;
+      volatile long double ld;
+      volatile unsigned long long ll;
+      lldiv_t mydivt;],
+     [char* tmp;
+      f = strtof("gnu", &tmp);
+      ld = strtold("gnu", &tmp);
+      ll = strtoll("gnu", &tmp, 10);
+      ll = strtoull("gnu", &tmp, 10);
+      ll = llabs(10);
+      mydivt = lldiv(10,1);
+      ll = mydivt.quot;
+      ll = mydivt.rem;
+      ll = atoll("10");
+      _Exit(0);
+      ],[glibcxx_cv_c99_stdlib=yes], [glibcxx_cv_c99_stdlib=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_c99_stdlib)
+
+  # Check for the existence in <wchar.h> of wcstold, etc.
+  glibcxx_cv_c99_wchar=no;
+  if test x"$ac_has_wchar_h" = xyes &&
+     test x"$ac_has_wctype_h" = xyes; then
+    AC_MSG_CHECKING([for ISO C99 support in <wchar.h>])        
+    AC_TRY_COMPILE([#include <wchar.h>
+                    namespace test
+                    {
+                     using ::wcstold;
+                     using ::wcstoll;
+                     using ::wcstoull;
+                   }
+                  ],[],[glibcxx_cv_c99_wchar=yes], [glibcxx_cv_c99_wchar=no])
+
+    # Checks for wide character functions that may not be present.
+    # Injection of these is wrapped with guard macros.
+    # NB: only put functions here, instead of immediately above, if
+    # absolutely necessary.
+    AC_TRY_COMPILE([#include <wchar.h>
+                    namespace test { using ::vfwscanf; } ], [],
+                  [AC_DEFINE(HAVE_VFWSCANF,1,
+                       [Defined if vfwscanf exists.])],[])
+
+    AC_TRY_COMPILE([#include <wchar.h>
+                    namespace test { using ::vswscanf; } ], [],
+                  [AC_DEFINE(HAVE_VSWSCANF,1,
+                       [Defined if vswscanf exists.])],[])
+
+    AC_TRY_COMPILE([#include <wchar.h>
+                    namespace test { using ::vwscanf; } ], [],
+                  [AC_DEFINE(HAVE_VWSCANF,1,[Defined if vwscanf exists.])],[])
+
+    AC_TRY_COMPILE([#include <wchar.h>
+                    namespace test { using ::wcstof; } ], [],
+                  [AC_DEFINE(HAVE_WCSTOF,1,[Defined if wcstof exists.])],[])
+
+    AC_TRY_COMPILE([#include <wctype.h>],
+                   [ wint_t t; int i = iswblank(t);], 
+                  [AC_DEFINE(HAVE_ISWBLANK,1,
+                       [Defined if iswblank exists.])],[])
+
+    AC_MSG_RESULT($glibcxx_cv_c99_wchar)
+  fi
+
+  # Option parsed, now set things appropriately.
+  if test x"$glibcxx_cv_c99_math" = x"no" ||
+     test x"$glibcxx_cv_c99_complex" = x"no" ||
+     test x"$glibcxx_cv_c99_stdio" = x"no" ||
+     test x"$glibcxx_cv_c99_stdlib" = x"no" ||
+     test x"$glibcxx_cv_c99_wchar" = x"no"; then
+    enable_c99=no;
+  else
+    AC_DEFINE(_GLIBCXX_USE_C99, 1,
+    [Define if C99 functions or macros from <wchar.h>, <math.h>,
+    <complex.h>, <stdio.h>, and <stdlib.h> can be used or exposed.])
+  fi
 
+  gcc_no_link="$ac_save_gcc_no_link"
   LIBS="$ac_save_LIBS"
   CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+  fi   
+
+  AC_MSG_CHECKING([for fully enabled ISO C99 support])
+  AC_MSG_RESULT($enable_c99)
 ])
 
 
 dnl
-dnl Check to see if there is native support for complex 
-dnl
-dnl Don't compile bits in math/* if native support exits.
+dnl Check for clock_gettime, nanosleep and sched_yield, used in the
+dnl implementation of 20.8.5 [time.clock], and 30.2.2 [thread.thread.this]
+dnl in the current C++0x working draft.
 dnl
-dnl Define USE_COMPLEX_LONG_DOUBLE etc if "copysignl" is found.
+dnl --enable-libstdcxx-time
+dnl --enable-libstdcxx-time=yes
+dnl        checks for the availability of monotonic and realtime clocks,
+dnl        nanosleep and sched_yield in libc and libposix4 and, in case, links
+dnl       the latter
+dnl --enable-libstdcxx-time=rt
+dnl        also searches (and, in case, 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        a large overhead for single-thread programs.
+dnl --enable-libstdcxx-time=no
+dnl --disable-libstdcxx-time
+dnl        disables the checks completely
 dnl
-dnl GLIBCPP_CHECK_COMPLEX_MATH_SUPPORT
-AC_DEFUN(GLIBCPP_CHECK_COMPLEX_MATH_SUPPORT, [
-  dnl Check for complex versions of math functions of platform.
-  AC_CHECK_LIB(m, main)
-  AC_REPLACE_MATHFUNCS(nan copysignf)
+AC_DEFUN([GLIBCXX_ENABLE_LIBSTDCXX_TIME], [
 
-  dnl For __signbit to signbit conversions.
-  AC_CHECK_FUNCS([__signbit], , [LIBMATHOBJS="$LIBMATHOBJS signbit.lo"])
-  AC_CHECK_FUNCS([__signbitf], , [LIBMATHOBJS="$LIBMATHOBJS signbitf.lo"])
+  AC_MSG_CHECKING([for clock_gettime, nanosleep and sched_yield])
+  GLIBCXX_ENABLE(libstdcxx-time,$1,[=KIND],
+    [use KIND for check type],
+    [permit yes|no|rt])
 
-  dnl Compile the long double complex functions only if the function 
-  dnl provides the non-complex long double functions that are needed.
-  dnl Currently this includes copysignl, which should be
-  dnl cached from the GLIBCPP_CHECK_MATH_SUPPORT macro, above.
-  if test x$ac_cv_func_copysignl = x"yes"; then
-    AC_CHECK_FUNCS([__signbitl], , [LIBMATHOBJS="$LIBMATHOBJS signbitl.lo"])
-  fi
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
+  ac_save_LIBS="$LIBS"
 
-  AC_SUBST(LIBMATHOBJS)
-])
+  ac_has_clock_monotonic=no;
+  ac_has_clock_realtime=no;
 
+  if test x"$enable_libstdcxx_time" != x"no"; then
 
-dnl Check to see what architecture and operating system we are compiling
-dnl for.  Also, if architecture- or OS-specific flags are required for
-dnl compilation, pick them up here.
-dnl 
-dnl GLIBCPP_CHECK_TARGET
-AC_DEFUN(GLIBCPP_CHECK_TARGET, [
-    . [$]{glibcpp_basedir}/configure.target
-    AC_MSG_RESULT(CPU config directory is $cpu_include_dir)
-    AC_MSG_RESULT(OS config directory is $os_include_dir)
-])
+    if test x"$enable_libstdcxx_time" = x"rt"; then
+      AC_SEARCH_LIBS(clock_gettime, [rt posix4])
+      AC_SEARCH_LIBS(nanosleep, [rt posix4])
+    else
+      AC_SEARCH_LIBS(clock_gettime, [posix4])
+      AC_SEARCH_LIBS(nanosleep, [posix4])
+    fi
 
+    case "$ac_cv_search_clock_gettime" in
+      -l*) GLIBCXX_LIBS=$ac_cv_search_clock_gettime
+      ;;
+    esac
+    case "$ac_cv_search_nanosleep" in
+      -l*) GLIBCXX_LIBS="$GLIBCXX_LIBS $ac_cv_search_nanosleep"
+      ;;
+    esac
 
-dnl
-dnl Check to see if this target can enable the wchar_t parts of libstdc++.
-dnl If --disable-c-mbchar was given, no wchar_t stuff is enabled.  (This
-dnl must have been previously checked.)
-dnl
-dnl Define _GLIBCPP_USE_WCHAR_T if all the bits are found 
-dnl Define HAVE_MBSTATE_T if mbstate_t is not in wchar.h
-dnl
-dnl GLIBCPP_CHECK_WCHAR_T_SUPPORT
-AC_DEFUN(GLIBCPP_CHECK_WCHAR_T_SUPPORT, [
+    AC_SEARCH_LIBS(sched_yield, [rt posix4])
 
-  dnl Test wchar.h for mbstate_t, which is needed for char_traits and
-  dnl others even if wchar_t support is not on.
-  AC_MSG_CHECKING([for mbstate_t])
-  AC_TRY_COMPILE([#include <wchar.h>],
-  [mbstate_t teststate;], 
-  have_mbstate_t=yes, have_mbstate_t=no)
-  AC_MSG_RESULT($have_mbstate_t)
-  if test x"$have_mbstate_t" = xyes; then
-    AC_DEFINE(HAVE_MBSTATE_T)
-  fi
+    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. ])
+      ;;
+      -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. ])
+      fi
+      ;;
+      *)
+      AC_DEFINE(_GLIBCXX_USE_SCHED_YIELD, 1,
+                [ Defined if sched_yield is available. ])
+      ;;
+    esac
 
-  dnl Sanity check for existence of ISO C99 headers for extended encoding.
-  AC_CHECK_HEADERS(wchar.h, ac_has_wchar_h=yes, ac_has_wchar_h=no)
-  AC_CHECK_HEADERS(wctype.h, ac_has_wctype_h=yes, ac_has_wctype_h=no)
-  
-  dnl Only continue checking if the ISO C99 headers exist and support is on.
-  if test x"$ac_has_wchar_h" = xyes &&
-     test x"$ac_has_wctype_h" = xyes &&
-     test x"$enable_c_mbchar" != xno; then
-      
-    dnl Test wchar.h for WCHAR_MIN, WCHAR_MAX, which is needed before
-    dnl numeric_limits can instantiate type_traits<wchar_t>
-    AC_MSG_CHECKING([for WCHAR_MIN and WCHAR_MAX])
-    AC_TRY_COMPILE([#include <wchar.h>],
-    [int i = WCHAR_MIN; int j = WCHAR_MAX;], 
-    has_wchar_minmax=yes, has_wchar_minmax=no)
-    AC_MSG_RESULT($has_wchar_minmax)
+    AC_CHECK_HEADERS(unistd.h, ac_has_unistd_h=yes, ac_has_unistd_h=no)
+
+    if test x"$ac_has_unistd_h" = x"yes"; then
+      AC_MSG_CHECKING([for monotonic clock])
+      AC_TRY_LINK(
+        [#include <unistd.h>
+         #include <time.h>
+        ],
+        [#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
+          timespec tp;     
+         #endif
+          clock_gettime(CLOCK_MONOTONIC, &tp);
+        ], [ac_has_clock_monotonic=yes], [ac_has_clock_monotonic=no])
+
+      AC_MSG_RESULT($ac_has_clock_monotonic)   
     
-    dnl Test wchar.h for WEOF, which is what we use to determine whether
-    dnl to specialize for char_traits<wchar_t> or not.
-    AC_MSG_CHECKING([for WEOF])
-    AC_TRY_COMPILE([
-      #include <wchar.h>
-      #include <stddef.h>],
-    [wint_t i = WEOF;],
-    has_weof=yes, has_weof=no)
-    AC_MSG_RESULT($has_weof)
+      AC_MSG_CHECKING([for realtime clock])
+      AC_TRY_LINK(
+        [#include <unistd.h>
+         #include <time.h>
+        ],
+        [#if _POSIX_TIMERS > 0
+          timespec tp;      
+         #endif
+          clock_gettime(CLOCK_REALTIME, &tp);
+        ], [ac_has_clock_realtime=yes], [ac_has_clock_realtime=no])
+
+      AC_MSG_RESULT($ac_has_clock_realtime)
+
+      AC_MSG_CHECKING([for nanosleep])
+      AC_TRY_LINK(
+        [#include <unistd.h>
+         #include <time.h>
+        ],
+        [#if _POSIX_TIMERS > 0
+          timespec tp;
+         #endif
+          nanosleep(&tp, 0);
+        ], [ac_has_nanosleep=yes], [ac_has_nanosleep=no])
+
+      AC_MSG_RESULT($ac_has_nanosleep)
+    fi
+  fi
+
+  if test x"$ac_has_clock_monotonic" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_CLOCK_MONOTONIC, 1,
+      [ Defined if clock_gettime has monotonic clock support. ])
+  fi
+
+  if test x"$ac_has_clock_realtime" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_CLOCK_REALTIME, 1,
+      [ Defined if clock_gettime has realtime clock support. ])
+  fi
+
+  if test x"$ac_has_nanosleep" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_NANOSLEEP, 1,
+      [ Defined if nanosleep is available. ])
+  fi
+
+  AC_SUBST(GLIBCXX_LIBS)
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  LIBS="$ac_save_LIBS"
+  AC_LANG_RESTORE
+])
+
+dnl
+dnl Check for gettimeofday, used in the implementation of 20.8.5
+dnl [time.clock] in the current C++0x working draft.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_GETTIMEOFDAY], [
   
-    dnl Tests for wide character functions used in char_traits<wchar_t>.
-    ac_wfuncs=yes
-    AC_CHECK_FUNCS(wcslen wmemchr wmemcmp wmemcpy wmemmove wmemset,, \
-    ac_wfuncs=no)
+  AC_MSG_CHECKING([for gettimeofday])
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions"
   
-    dnl Checks for names injected into std:: by the c_std headers.
-    AC_CHECK_FUNCS(btowc wctob fgetwc fgetwc fgetws fputwc fputws fwide \
-    fwprintf fwscanf swprintf swscanf vfwprintf vfwscanf vswprintf vswscanf \
-    vwprintf vwscanf wprintf wscanf getwc getwchar mbsinit mbrlen mbrtowc \
-    mbsrtowcs wcsrtombs putwc putwchar ungetwc wcrtomb wcstod wcstof wcstol \
-    wcstoul wcscpy wcsncpy wcscat wcsncat wcscmp wcscoll wcsncmp wcsxfrm \
-    wcscspn wcsspn wcstok wcsftime wcschr wcspbrk wcsrchr wcsstr,, \
-    ac_wfuncs=no)
-
-    AC_MSG_CHECKING([for ISO C99 wchar_t support])
-    if test x"$has_weof" = xyes &&
-       test x"$has_wchar_minmax" = xyes &&
-       test x"$ac_wfuncs" = xyes; then
-      ac_isoC99_wchar_t=yes
-    else
-      ac_isoC99_wchar_t=no
-    fi
-    AC_MSG_RESULT($ac_isoC99_wchar_t)
+  ac_has_gettimeofday=no;
+  AC_CHECK_HEADERS(sys/time.h, ac_has_sys_time_h=yes, ac_has_sys_time_h=no)
+  if test x"$ac_has_sys_time_h" = x"yes"; then
+    AC_MSG_CHECKING([for gettimeofday])
+    GCC_TRY_COMPILE_OR_LINK([#include <sys/time.h>],
+      [timeval tv; gettimeofday(&tv, 0);],
+      [ac_has_gettimeofday=yes], [ac_has_gettimeofday=no])
+    
+    AC_MSG_RESULT($ac_has_gettimeofday)
+  fi
   
-    dnl Use iconv for wchar_t to char conversions. As such, check for 
-    dnl X/Open Portability Guide, version 2 features (XPG2).
-    AC_CHECK_HEADER(iconv.h, ac_has_iconv_h=yes, ac_has_iconv_h=no)
-    AC_CHECK_HEADER(langinfo.h, ac_has_langinfo_h=yes, ac_has_langinfo_h=no)
-
-    dnl Check for existence of libiconv.a providing XPG2 wchar_t support.
-    AC_CHECK_LIB(iconv, iconv, libiconv="-liconv")
-    ac_save_LIBS="$LIBS"
-    LIBS="$LIBS $libiconv"
-
-    AC_CHECK_FUNCS(iconv_open iconv_close iconv nl_langinfo, \
-    ac_XPG2funcs=yes, ac_XPG2funcs=no)
+  if test x"$ac_has_gettimeofday" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_GETTIMEOFDAY, 1,
+      [ Defined if gettimeofday is available. ])
+  fi
   
-    LIBS="$ac_save_LIBS"
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+])
 
-    AC_MSG_CHECKING([for XPG2 wchar_t support])
-    if test x"$ac_has_iconv_h" = xyes &&
-       test x"$ac_has_langinfo_h" = xyes &&
-       test x"$ac_XPG2funcs" = xyes; then
-      ac_XPG2_wchar_t=yes
-    else
-      ac_XPG2_wchar_t=no
-    fi
-    AC_MSG_RESULT($ac_XPG2_wchar_t)
-  
-    dnl At the moment, only enable wchar_t specializations if all the
-    dnl above support is present.
-    AC_MSG_CHECKING([for enabled wchar_t specializations])
-    if test x"$ac_isoC99_wchar_t" = xyes &&
-       test x"$ac_XPG2_wchar_t" = xyes; then
-      AC_DEFINE(_GLIBCPP_USE_WCHAR_T)
-      AC_MSG_RESULT("yes")
+dnl
+dnl Check for ISO/IEC 9899:1999 "C99" support to ISO/IEC DTR 19768 "TR1"
+dnl facilities in Chapter 8, "C compatibility".
+dnl
+AC_DEFUN([GLIBCXX_CHECK_C99_TR1], [
+
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+
+  # Use -std=c++98 because the default (-std=gnu++98) leaves __STRICT_ANSI__
+  # undefined and fake C99 facilities may be spuriously enabled.
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -std=c++98"
+
+  # Check for the existence of <complex.h> complex math functions used
+  # by tr1/complex.
+  AC_CHECK_HEADERS(complex.h, ac_has_complex_h=yes, ac_has_complex_h=no)
+  ac_c99_complex_tr1=no;
+  if test x"$ac_has_complex_h" = x"yes"; then
+    AC_MSG_CHECKING([for ISO C99 support to TR1 in <complex.h>])
+    AC_TRY_COMPILE([#include <complex.h>],
+                  [typedef __complex__ float float_type; float_type tmpf;
+                   cacosf(tmpf);
+                   casinf(tmpf);
+                   catanf(tmpf);
+                   cacoshf(tmpf);
+                   casinhf(tmpf);
+                   catanhf(tmpf);
+                   typedef __complex__ double double_type; double_type tmpd;
+                   cacos(tmpd);
+                   casin(tmpd);
+                   catan(tmpd);
+                   cacosh(tmpd);
+                   casinh(tmpd);
+                   catanh(tmpd);
+                   typedef __complex__ long double ld_type; ld_type tmpld;
+                   cacosl(tmpld);
+                   casinl(tmpld);
+                   catanl(tmpld);
+                   cacoshl(tmpld);
+                   casinhl(tmpld);
+                   catanhl(tmpld);
+                  ],[ac_c99_complex_tr1=yes], [ac_c99_complex_tr1=no])
+  fi
+  AC_MSG_RESULT($ac_c99_complex_tr1)
+  if test x"$ac_c99_complex_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_COMPLEX_TR1, 1,
+              [Define if C99 functions in <complex.h> should be used in
+              <tr1/complex>. Using compiler builtins for these functions
+             requires corresponding C99 library functions to be present.])
+  fi
+
+  # Check for the existence of <ctype.h> functions.
+  AC_MSG_CHECKING([for ISO C99 support to TR1 in <ctype.h>])
+  AC_CACHE_VAL(glibcxx_cv_c99_ctype_tr1, [
+  AC_TRY_COMPILE([#include <ctype.h>],
+                [int ch;
+                 int ret;
+                 ret = isblank(ch);
+                ],[glibcxx_cv_c99_ctype_tr1=yes],
+                  [glibcxx_cv_c99_ctype_tr1=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_c99_ctype_tr1)
+  if test x"$glibcxx_cv_c99_ctype_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_CTYPE_TR1, 1,
+              [Define if C99 functions in <ctype.h> should be imported in
+             <tr1/cctype> in namespace std::tr1.])
+  fi
+
+  # Check for the existence of <fenv.h> functions.
+  AC_CHECK_HEADERS(fenv.h, ac_has_fenv_h=yes, ac_has_fenv_h=no)
+  ac_c99_fenv_tr1=no;
+  if test x"$ac_has_fenv_h" = x"yes"; then
+    AC_MSG_CHECKING([for ISO C99 support to TR1 in <fenv.h>])
+    AC_TRY_COMPILE([#include <fenv.h>],
+                  [int except, mode;
+                   fexcept_t* pflag;
+                    fenv_t* penv;
+                   int ret;
+                   ret = feclearexcept(except);
+                   ret = fegetexceptflag(pflag, except);
+                   ret = feraiseexcept(except);
+                   ret = fesetexceptflag(pflag, except);
+                   ret = fetestexcept(except);
+                   ret = fegetround();
+                   ret = fesetround(mode);
+                   ret = fegetenv(penv);
+                   ret = feholdexcept(penv);
+                   ret = fesetenv(penv);
+                   ret = feupdateenv(penv);
+                  ],[ac_c99_fenv_tr1=yes], [ac_c99_fenv_tr1=no])
+  fi
+  AC_MSG_RESULT($ac_c99_fenv_tr1)
+  if test x"$ac_c99_fenv_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_FENV_TR1, 1,
+              [Define if C99 functions in <fenv.h> should be imported in
+             <tr1/cfenv> in namespace std::tr1.])
+  fi
+
+  # Check for the existence of <stdint.h> types.
+  AC_MSG_CHECKING([for ISO C99 support to TR1 in <stdint.h>])
+  AC_CACHE_VAL(glibcxx_cv_c99_stdint_tr1, [
+  AC_TRY_COMPILE([#define __STDC_LIMIT_MACROS
+                  #define __STDC_CONSTANT_MACROS
+                  #include <stdint.h>],
+                [typedef int8_t          my_int8_t;
+                 my_int8_t               i8 = INT8_MIN;
+                 i8 = INT8_MAX;
+                 typedef int16_t         my_int16_t;
+                 my_int16_t              i16 = INT16_MIN;
+                 i16 = INT16_MAX;
+                 typedef int32_t         my_int32_t;
+                 my_int32_t              i32 = INT32_MIN;
+                 i32 = INT32_MAX;
+                 typedef int64_t         my_int64_t;
+                 my_int64_t              i64 = INT64_MIN;
+                 i64 = INT64_MAX;
+                 typedef int_fast8_t     my_int_fast8_t;
+                 my_int_fast8_t          if8 = INT_FAST8_MIN;
+                 if8 = INT_FAST8_MAX;
+                 typedef int_fast16_t    my_int_fast16_t;
+                 my_int_fast16_t         if16 = INT_FAST16_MIN;
+                 if16 = INT_FAST16_MAX;
+                 typedef int_fast32_t    my_int_fast32_t;
+                 my_int_fast32_t         if32 = INT_FAST32_MIN;
+                 if32 = INT_FAST32_MAX;
+                 typedef int_fast64_t    my_int_fast64_t;
+                 my_int_fast64_t         if64 = INT_FAST64_MIN;
+                 if64 = INT_FAST64_MAX;
+                 typedef int_least8_t    my_int_least8_t;
+                 my_int_least8_t         il8 = INT_LEAST8_MIN;
+                 il8 = INT_LEAST8_MAX;
+                 typedef int_least16_t   my_int_least16_t;
+                 my_int_least16_t        il16 = INT_LEAST16_MIN;
+                 il16 = INT_LEAST16_MAX;
+                 typedef int_least32_t   my_int_least32_t;
+                 my_int_least32_t        il32 = INT_LEAST32_MIN;
+                 il32 = INT_LEAST32_MAX;
+                 typedef int_least64_t   my_int_least64_t;
+                 my_int_least64_t        il64 = INT_LEAST64_MIN;
+                 il64 = INT_LEAST64_MAX;
+                 typedef intmax_t        my_intmax_t;
+                 my_intmax_t             im = INTMAX_MAX;
+                 im = INTMAX_MIN;
+                 typedef intptr_t        my_intptr_t;
+                 my_intptr_t             ip = INTPTR_MAX;
+                 ip = INTPTR_MIN;
+                 typedef uint8_t         my_uint8_t;
+                 my_uint8_t              ui8 = UINT8_MAX;
+                 ui8 = UINT8_MAX;
+                 typedef uint16_t        my_uint16_t;
+                 my_uint16_t             ui16 = UINT16_MAX;
+                 ui16 = UINT16_MAX;
+                 typedef uint32_t        my_uint32_t;
+                 my_uint32_t             ui32 = UINT32_MAX;
+                 ui32 = UINT32_MAX;
+                 typedef uint64_t        my_uint64_t;
+                 my_uint64_t             ui64 = UINT64_MAX;
+                 ui64 = UINT64_MAX;
+                 typedef uint_fast8_t    my_uint_fast8_t;
+                 my_uint_fast8_t         uif8 = UINT_FAST8_MAX;
+                 uif8 = UINT_FAST8_MAX;
+                 typedef uint_fast16_t   my_uint_fast16_t;
+                 my_uint_fast16_t        uif16 = UINT_FAST16_MAX;
+                 uif16 = UINT_FAST16_MAX;
+                 typedef uint_fast32_t   my_uint_fast32_t;
+                 my_uint_fast32_t        uif32 = UINT_FAST32_MAX;
+                 uif32 = UINT_FAST32_MAX;
+                 typedef uint_fast64_t   my_uint_fast64_t;
+                 my_uint_fast64_t        uif64 = UINT_FAST64_MAX;
+                 uif64 = UINT_FAST64_MAX;
+                 typedef uint_least8_t   my_uint_least8_t;
+                 my_uint_least8_t        uil8 = UINT_LEAST8_MAX;
+                 uil8 = UINT_LEAST8_MAX;
+                 typedef uint_least16_t  my_uint_least16_t;
+                 my_uint_least16_t       uil16 = UINT_LEAST16_MAX;
+                 uil16 = UINT_LEAST16_MAX;
+                 typedef uint_least32_t  my_uint_least32_t;
+                 my_uint_least32_t       uil32 = UINT_LEAST32_MAX;
+                 uil32 = UINT_LEAST32_MAX;
+                 typedef uint_least64_t  my_uint_least64_t;
+                 my_uint_least64_t       uil64 = UINT_LEAST64_MAX;
+                 uil64 = UINT_LEAST64_MAX;
+                 typedef uintmax_t       my_uintmax_t;
+                 my_uintmax_t            uim = UINTMAX_MAX;
+                 uim = UINTMAX_MAX;
+                 typedef uintptr_t       my_uintptr_t;
+                 my_uintptr_t            uip = UINTPTR_MAX;
+                 uip = UINTPTR_MAX;
+                ],[glibcxx_cv_c99_stdint_tr1=yes],
+                  [glibcxx_cv_c99_stdint_tr1=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_c99_stdint_tr1)
+  if test x"$glibcxx_cv_c99_stdint_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_STDINT_TR1, 1,
+              [Define if C99 types in <stdint.h> should be imported in
+             <tr1/cstdint> in namespace std::tr1.])
+  fi
+
+  # Check for the existence of <math.h> functions.
+  AC_MSG_CHECKING([for ISO C99 support to TR1 in <math.h>])
+  AC_CACHE_VAL(glibcxx_cv_c99_math_tr1, [
+  AC_TRY_COMPILE([#include <math.h>],
+                [typedef double_t  my_double_t;
+                 typedef float_t   my_float_t;
+                 acosh(0.0);
+                 acoshf(0.0f);
+                 acoshl(0.0l);
+                 asinh(0.0);
+                 asinhf(0.0f);
+                 asinhl(0.0l);
+                 atanh(0.0);
+                 atanhf(0.0f);
+                 atanhl(0.0l);
+                 cbrt(0.0);
+                 cbrtf(0.0f);
+                 cbrtl(0.0l);
+                 copysign(0.0, 0.0);
+                 copysignf(0.0f, 0.0f);
+                 copysignl(0.0l, 0.0l);
+                 erf(0.0);
+                 erff(0.0f);
+                 erfl(0.0l);
+                 erfc(0.0);
+                 erfcf(0.0f);
+                 erfcl(0.0l);
+                 exp2(0.0);
+                 exp2f(0.0f);
+                 exp2l(0.0l);
+                 expm1(0.0);
+                 expm1f(0.0f);
+                 expm1l(0.0l);
+                 fdim(0.0, 0.0);
+                 fdimf(0.0f, 0.0f);
+                 fdiml(0.0l, 0.0l);
+                 fma(0.0, 0.0, 0.0);
+                 fmaf(0.0f, 0.0f, 0.0f);
+                 fmal(0.0l, 0.0l, 0.0l);
+                 fmax(0.0, 0.0);
+                 fmaxf(0.0f, 0.0f);
+                 fmaxl(0.0l, 0.0l);
+                 fmin(0.0, 0.0);
+                 fminf(0.0f, 0.0f);
+                 fminl(0.0l, 0.0l);
+                 hypot(0.0, 0.0);
+                 hypotf(0.0f, 0.0f);
+                 hypotl(0.0l, 0.0l);
+                 ilogb(0.0);
+                 ilogbf(0.0f);
+                 ilogbl(0.0l);
+                 lgamma(0.0);
+                 lgammaf(0.0f);
+                 lgammal(0.0l);
+                 llrint(0.0);
+                 llrintf(0.0f);
+                 llrintl(0.0l);
+                 llround(0.0);
+                 llroundf(0.0f);
+                 llroundl(0.0l);
+                 log1p(0.0);
+                 log1pf(0.0f);
+                 log1pl(0.0l);
+                 log2(0.0);
+                 log2f(0.0f);
+                 log2l(0.0l);
+                 logb(0.0);
+                 logbf(0.0f);
+                 logbl(0.0l);
+                 lrint(0.0);
+                 lrintf(0.0f);
+                 lrintl(0.0l);
+                 lround(0.0);
+                 lroundf(0.0f);
+                 lroundl(0.0l);
+                 nan(0);
+                 nanf(0);
+                 nanl(0);
+                 nearbyint(0.0);
+                 nearbyintf(0.0f);
+                 nearbyintl(0.0l);
+                 nextafter(0.0, 0.0);
+                 nextafterf(0.0f, 0.0f);
+                 nextafterl(0.0l, 0.0l);
+                 nexttoward(0.0, 0.0);
+                 nexttowardf(0.0f, 0.0f);
+                 nexttowardl(0.0l, 0.0l);
+                 remainder(0.0, 0.0);
+                 remainderf(0.0f, 0.0f);
+                 remainderl(0.0l, 0.0l);
+                 remquo(0.0, 0.0, 0);
+                 remquof(0.0f, 0.0f, 0);
+                 remquol(0.0l, 0.0l, 0);
+                 rint(0.0);
+                 rintf(0.0f);
+                 rintl(0.0l);
+                 round(0.0);
+                 roundf(0.0f);
+                 roundl(0.0l);
+                 scalbln(0.0, 0l);
+                 scalblnf(0.0f, 0l);
+                 scalblnl(0.0l, 0l);
+                 scalbn(0.0, 0);
+                 scalbnf(0.0f, 0);
+                 scalbnl(0.0l, 0);
+                 tgamma(0.0);
+                 tgammaf(0.0f);
+                 tgammal(0.0l);
+                 trunc(0.0);
+                 truncf(0.0f);
+                 truncl(0.0l);
+                ],[glibcxx_cv_c99_math_tr1=yes], [glibcxx_cv_c99_math_tr1=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_c99_math_tr1)
+  if test x"$glibcxx_cv_c99_math_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_MATH_TR1, 1,
+              [Define if C99 functions or macros in <math.h> should be imported
+              in <tr1/cmath> in namespace std::tr1.])
+  fi
+
+  # Check for the existence of <inttypes.h> functions (NB: doesn't make
+  # sense if the glibcxx_cv_c99_stdint_tr1 check fails, per C99, 7.8/1).
+  ac_c99_inttypes_tr1=no;
+  if test x"$glibcxx_cv_c99_stdint_tr1" = x"yes"; then
+    AC_MSG_CHECKING([for ISO C99 support to TR1 in <inttypes.h>])
+    AC_TRY_COMPILE([#include <inttypes.h>],
+                  [intmax_t i, numer, denom, base;
+                   const char* s;
+                   char** endptr;
+                   intmax_t ret = imaxabs(i);
+                   imaxdiv_t dret = imaxdiv(numer, denom);
+                   ret = strtoimax(s, endptr, base);
+                   uintmax_t uret = strtoumax(s, endptr, base);
+                  ],[ac_c99_inttypes_tr1=yes], [ac_c99_inttypes_tr1=no])
+  fi
+  AC_MSG_RESULT($ac_c99_inttypes_tr1)
+  if test x"$ac_c99_inttypes_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_INTTYPES_TR1, 1,
+              [Define if C99 functions in <inttypes.h> should be imported in
+              <tr1/cinttypes> in namespace std::tr1.])
+  fi
+
+  # Check for the existence of whcar_t <inttypes.h> functions (NB: doesn't
+  # make sense if the glibcxx_cv_c99_stdint_tr1 check fails, per C99, 7.8/1).
+  ac_c99_inttypes_wchar_t_tr1=no;
+  if test x"$glibcxx_cv_c99_stdint_tr1" = x"yes"; then
+    AC_MSG_CHECKING([for wchar_t ISO C99 support to TR1 in <inttypes.h>])
+    AC_TRY_COMPILE([#include <inttypes.h>],
+                  [intmax_t base;
+                   const wchar_t* s;
+                   wchar_t** endptr;
+                   intmax_t ret = wcstoimax(s, endptr, base);
+                   uintmax_t uret = wcstoumax(s, endptr, base);
+                  ],[ac_c99_inttypes_wchar_t_tr1=yes],
+                    [ac_c99_inttypes_wchar_t_tr1=no])
+  fi
+  AC_MSG_RESULT($ac_c99_inttypes_wchar_t_tr1)
+  if test x"$ac_c99_inttypes_wchar_t_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_C99_INTTYPES_WCHAR_T_TR1, 1,
+              [Define if wchar_t C99 functions in <inttypes.h> should be
+             imported in <tr1/cinttypes> in namespace std::tr1.])
+  fi
+
+  # Check for the existence of the <stdbool.h> header. 
+  AC_CHECK_HEADERS(stdbool.h)
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
+])
+
+dnl
+dnl Check whether "/dev/random" and "/dev/urandom" are available for the
+dnl random_device of "TR1" (Chapter 5.1, "Random number generation").
+dnl
+AC_DEFUN([GLIBCXX_CHECK_RANDOM_TR1], [
+
+  AC_MSG_CHECKING([for "/dev/random" and "/dev/urandom" for TR1 random_device])
+  AC_CACHE_VAL(glibcxx_cv_random_tr1, [
+    if test -r /dev/random && test -r /dev/urandom; then
+      glibcxx_cv_random_tr1=yes;
     else
-      AC_MSG_RESULT("no")
+      glibcxx_cv_random_tr1=no;
     fi
-  else
-    dnl Wide characters disabled by the user. 
-    AC_MSG_WARN([wchar_t support disabled.])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_random_tr1)
+
+  if test x"$glibcxx_cv_random_tr1" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_RANDOM_TR1, 1,
+              [Define if /dev/random and /dev/urandom are available for
+              the random_device of TR1 (Chapter 5.1).])
   fi
-])
 
+])
 
 dnl
-dnl Check for special debugging mode; not for production use.
-dnl
-dnl GLIBCPP_ENABLE_DEBUG
-dnl --enable-debug sets '-ggdb3 -O0'.
-dnl --disable-debug sets '-g' and whatever optimization options the
-dnl     compiler can handle.
-dnl  +  --enable-maintainer-mode automatically defaults this to on.
-dnl  +  Perhaps -D/-U of NDEBUG, DEBUG, DEBUG_ASSERT, ...?
-dnl  +  Usage:  GLIBCPP_ENABLE_DEBUG[(DEFAULT)]
-dnl       Where DEFAULT is either `yes' or `no'.  If ommitted, it
-dnl       defaults to `no'.
-AC_DEFUN(GLIBCPP_ENABLE_DEBUG, [dnl
-define([GLIBCPP_ENABLE_DEBUG_DEFAULT], ifelse($1, yes, yes, no))dnl
-AC_ARG_ENABLE(debug,
-changequote(<<, >>)dnl
-<<  --enable-debug          extra debugging, turn off optimization [default=>>GLIBCPP_ENABLE_DEBUG_DEFAULT],
-changequote([, ])dnl
-[case "${enableval}" in
- yes) enable_debug=yes ;;
- no)  enable_debug=no ;;
- *)   AC_MSG_ERROR([Unknown argument to enable/disable extra debugging]) ;;
- esac],
-enable_debug=GLIBCPP_ENABLE_DEBUG_DEFAULT)dnl
-
-dnl Option parsed, now set things appropriately
-case "${enable_debug}" in
-    yes) 
-        DEBUG_FLAGS='-O0 -ggdb3'                        
-        ;; 
-    no)   
-        DEBUG_FLAGS='-g'
-        ;;
-esac
-AC_SUBST(DEBUG_FLAGS)
-])
+dnl Check whether EOF, SEEK_CUR, and SEEK_END have the most common values:
+dnl in that case including <cstdio> in some C++ headers can be avoided.
+dnl
+AC_DEFUN([GLIBCXX_CHECK_STDIO_MACROS], [
+
+  AC_MSG_CHECKING([for EOF == -1, SEEK_CUR == 1, SEEK_END == 2])
+  AC_CACHE_VAL(glibcxx_cv_stdio_macros, [
+  AC_TRY_COMPILE([#include <stdio.h>],
+                 [#if ((EOF != -1) || (SEEK_CUR != 1) || (SEEK_END != 2))
+                   unusual values...
+                 #endif
+                ], [glibcxx_cv_stdio_macros=yes],
+                   [glibcxx_cv_stdio_macros=no])
+  ])
+  AC_MSG_RESULT($glibcxx_cv_stdio_macros)
+  if test x"$glibcxx_cv_stdio_macros" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_STDIO_MACROS, 1,
+              [Define if EOF == -1, SEEK_CUR == 1, SEEK_END == 2.])
+  fi
 
+])
 
 dnl
-dnl Check for "unusual" flags to pass to the compiler while building.
+dnl Check whether macros, etc are present for <system_error>
 dnl
-dnl GLIBCPP_ENABLE_CXX_FLAGS
-dnl --enable-cxx-flags='-foo -bar -baz' is a general method for passing
-dnl     experimental flags such as -fhonor-std, -fsquangle, -Dfloat=char, etc.
-dnl     Somehow this same set of flags must be passed when [re]building
-dnl     libgcc.
-dnl --disable-cxx-flags passes nothing.
-dnl  +  See http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00131.html
-dnl         http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00284.html
-dnl         http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00035.html
-dnl  +  Usage:  GLIBCPP_ENABLE_CXX_FLAGS(default flags)
-dnl       If "default flags" is an empty string (or "none"), the effect is
-dnl       the same as --disable or --enable=no.
-AC_DEFUN(GLIBCPP_ENABLE_CXX_FLAGS, [dnl
-define([GLIBCPP_ENABLE_CXX_FLAGS_DEFAULT], ifelse($1,,, $1))dnl
-AC_ARG_ENABLE(cxx-flags,
-changequote(<<, >>)dnl
-<<  --enable-cxx-flags=FLAGS      pass compiler FLAGS when building library;
-                                [default=>>GLIBCPP_ENABLE_CXX_FLAGS_DEFAULT],
-changequote([, ])dnl
-[case "x$enableval" in
- xyes)   
-        AC_MSG_ERROR([--enable-cxx-flags needs compiler flags as arguments]) ;;
- xno|x)  
-        enable_cxx_flags='' ;;
- *)      
-        enable_cxx_flags="$enableval" ;;
- esac],
-enable_cxx_flags='GLIBCPP_ENABLE_CXX_FLAGS_DEFAULT')
-
-dnl Thinko on my part during design.  This kludge is the workaround.
-if test "$enable_cxx_flags" = "none"; then 
-  enable_cxx_flags=''; 
-fi
+AC_DEFUN([GLIBCXX_CHECK_SYSTEM_ERROR], [
 
-dnl Run through flags (either default or command-line) and set anything
-dnl extra (e.g., #defines) that must accompany particular g++ options.
-if test -n "$enable_cxx_flags"; then
-    for f in $enable_cxx_flags; do
-        case "$f" in
-            -fhonor-std)  ;;
-            -*)  ;;
-            *)   # and we're trying to pass /what/ exactly?
-                 AC_MSG_ERROR([compiler flags start with a -]) ;;
-        esac
-    done
+m4_pushdef([n_syserr], [1])dnl
+m4_foreach([syserr], [EOWNERDEAD, ENOTRECOVERABLE, ENOLINK, EPROTO, ENODATA,
+                     ENOSR, ENOSTR, ETIME, EBADMSG, ECANCELED,
+                     EOVERFLOW, ENOTSUP, EIDRM, ETXTBSY],
+[m4_pushdef([SYSERR], m4_toupper(syserr))dnl
+AC_MSG_CHECKING([for syserr])
+AC_CACHE_VAL([glibcxx_cv_system_error[]n_syserr], [
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <errno.h>]],
+                                  [int i = syserr;])],
+                 [glibcxx_cv_system_error[]n_syserr=yes],
+                 [glibcxx_cv_system_error[]n_syserr=no])
+])
+AC_MSG_RESULT([$glibcxx_cv_system_error[]n_syserr])
+if test x"$glibcxx_cv_system_error[]n_syserr" = x"yes"; then
+  AC_DEFINE([HAVE_]SYSERR, 1, [Define if ]syserr[ exists.])
 fi
-EXTRA_CXX_FLAGS="$enable_cxx_flags"
-AC_SUBST(EXTRA_CXX_FLAGS)
+m4_define([n_syserr], m4_incr(n_syserr))dnl
+m4_popdef([SYSERR])dnl
+])
+m4_popdef([n_syserr])dnl
+])
+
+dnl
+dnl Check for what type of C headers to use.
+dnl
+dnl --enable-cheaders= [does stuff].
+dnl --disable-cheaders [does not do anything, really].
+dnl  +  Usage:  GLIBCXX_ENABLE_CHEADERS[(DEFAULT)]
+dnl       Where DEFAULT is either 'c' or 'c_std' or 'c_global'.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_CHEADERS], [
+  GLIBCXX_ENABLE(cheaders,$1,[=KIND],
+    [construct "C" headers for g++], [permit c|c_std|c_global])
+  AC_MSG_NOTICE("C" header strategy set to $enable_cheaders)
+
+  C_INCLUDE_DIR='${glibcxx_srcdir}/include/'$enable_cheaders
+
+  # Allow overrides to configure.host here.
+  if test $enable_cheaders = c_global; then
+     c_compatibility=yes
+  fi
+
+  if test $enable_cheaders = c_global || test $enable_cheaders = c_std; then
+     c_extra=yes
+  fi
+
+  AC_SUBST(C_INCLUDE_DIR)
+  GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C, test $enable_cheaders = c)
+  GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C_STD, test $enable_cheaders = c_std)
+  GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_C_GLOBAL, test $enable_cheaders = c_global)
+  GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_COMPATIBILITY, test $c_compatibility = yes)
+  GLIBCXX_CONDITIONAL(GLIBCXX_C_HEADERS_EXTRA, test $c_extra = yes)
 ])
 
 
 dnl
-dnl Check for which locale library to use:  gnu or generic.
+dnl Check for which locale library to use.  The choice is mapped to
+dnl a subdirectory of config/locale.
 dnl
-dnl GLIBCPP_ENABLE_CLOCALE
-dnl --enable-clocale=gnu sets config/locale/c_locale_gnu.cc and friends
-dnl --enable-clocale=generic sets config/locale/c_locale_generic.cc and friends
-dnl 
-dnl default is generic
+dnl Default is generic.
 dnl
-AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
-  AC_MSG_CHECKING([for clocale to use])
-  AC_ARG_ENABLE(clocale,
-  [  --enable-clocale        enable model for target locale package. 
-  --enable-clocale=MODEL  use MODEL target-speific locale package. [default=generic]
-  ], 
-  if test x$enable_clocale = xno; then
-     enable_clocale=no
-  fi,
-     enable_clocale=no)
+AC_DEFUN([GLIBCXX_ENABLE_CLOCALE], [
+  GLIBCXX_ENABLE(clocale,auto,[@<:@=MODEL@:>@],
+    [use MODEL for target locale package],
+    [permit generic|gnu|ieee_1003.1-2001|yes|no|auto])
 
+  # Deal with gettext issues.  Default to not using it (=no) until we detect
+  # support for it later.  Let the user turn it off via --e/d, but let that
+  # default to on for easier handling.
+  USE_NLS=no
+  AC_ARG_ENABLE(nls,
+    AC_HELP_STRING([--enable-nls],[use Native Language Support (default)]),
+    [],
+    [enable_nls=yes])
+  
+  # Either a known packaage, or "auto"
+  if test $enable_clocale = no || test $enable_clocale = yes; then
+     enable_clocale=auto
+  fi
   enable_clocale_flag=$enable_clocale
 
-  dnl Probe for locale support if no specific model is specified.
-  dnl Default to "generic"
-  if test x$enable_clocale_flag = xno; then
-    case x${target_os} in
-      xlinux* | xgnu*)
-       AC_EGREP_CPP([_GLIBCPP_ok], [
-        #include <features.h>
-        #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) 
-          _GLIBCPP_ok
-        #endif
-        ], enable_clocale_flag=gnu, enable_clocale_flag=generic)
-
-       # Test for bugs early in glibc-2.2.x series
-       if test x$enable_clocale_flag = xgnu; then
-         AC_TRY_RUN([
-         #define _GNU_SOURCE 1
-         #include <locale.h>
-         #include <string.h>
-         #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
-         extern __typeof(newlocale) __newlocale;
-         extern __typeof(duplocale) __duplocale;
-         extern __typeof(strcoll_l) __strcoll_l;
-         #endif
-         int main()
-         {
-           const char __one[] = "Äuglein Augmen";
-           const char __two[] = "Äuglein";
-           int i;
-           int j;
-           __locale_t  loc;
-           __locale_t  loc_dup;
-           loc = __newlocale(1 << LC_ALL, "de_DE", 0);
-           loc_dup = __duplocale(loc);
-           i = __strcoll_l(__one, __two, loc);
-           j = __strcoll_l(__one, __two, loc_dup);
-           return 0;
-         }
-         ], 
-         [enable_clocale_flag=gnu],[enable_clocale_flag=generic],
-         [enable_clocale_flag=generic])
-       fi
-
-       # ... at some point put __strxfrm_l tests in as well.
+  # Probe for locale model to use if none specified.
+  # Default to "generic".
+  if test $enable_clocale_flag = auto; then
+    case ${target_os} in
+      linux* | gnu* | kfreebsd*-gnu | knetbsd*-gnu)
+        enable_clocale_flag=gnu        
         ;;
-      *)
-       enable_clocale_flag=generic
+      darwin* | freebsd*)
+        enable_clocale_flag=darwin
        ;;
+      *)
+        enable_clocale_flag=generic
+        ;;
     esac
   fi
 
-  dnl Deal with gettext issues.
-  AC_ARG_ENABLE(nls,
-  [  --enable-nls            use Native Language Support (default)],
-  , enable_nls=yes)
-  USE_NLS=no
+  # Sanity check model, and test for special functionality.
+  if test $enable_clocale_flag = gnu; then
+    AC_EGREP_CPP([_GLIBCXX_ok], [
+    #include <features.h>
+    #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
+      _GLIBCXX_ok
+    #endif
+    ], enable_clocale_flag=gnu, enable_clocale_flag=generic)
+
+    if test $enable_clocale = auto; then
+      # Test for bugs early in glibc-2.2.x series
+      AC_TRY_RUN([
+      #define _GNU_SOURCE 1
+      #include <locale.h>
+      #include <string.h>
+      #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2)
+      extern __typeof(newlocale) __newlocale;
+      extern __typeof(duplocale) __duplocale;
+      extern __typeof(strcoll_l) __strcoll_l;
+      #endif
+      int main()
+      {
+       const char __one[] = "Äuglein Augmen";
+        const char __two[] = "Äuglein";
+               int i;
+        int j;
+        __locale_t        loc;
+        __locale_t        loc_dup;
+        loc = __newlocale(1 << LC_ALL, "de_DE", 0);
+        loc_dup = __duplocale(loc);
+        i = __strcoll_l(__one, __two, loc);
+        j = __strcoll_l(__one, __two, loc_dup);
+        return 0;
+      }
+      ],
+      [enable_clocale_flag=gnu],[enable_clocale_flag=generic],
+      [enable_clocale_flag=generic])
+    fi
+
+    # Set it to scream when it hurts.
+    ac_save_CFLAGS="$CFLAGS"   
+    CFLAGS="-Wimplicit-function-declaration -Werror"
+
+    # Use strxfrm_l if available.
+    AC_TRY_COMPILE([#define _GNU_SOURCE 1
+                   #include <string.h>
+                   #include <locale.h>],
+                   [char s[128]; __locale_t loc; strxfrm_l(s, "C", 5, loc);], 
+                    AC_DEFINE(HAVE_STRXFRM_L, 1, 
+                    [Define if strxfrm_l is available in <string.h>.]),)
+    
+    # Use strerror_l if available.
+    AC_TRY_COMPILE([#define _GNU_SOURCE 1
+                   #include <string.h>
+                   #include <locale.h>],
+                   [__locale_t loc; strerror_l(5, loc);], 
+                    AC_DEFINE(HAVE_STRERROR_L, 1, 
+                    [Define if strerror_l is available in <string.h>.]),)
+
+    CFLAGS="$ac_save_CFLAGS"
+  fi
 
-  dnl Set configure bits for specified locale package
-  case x${enable_clocale_flag} in
-    xgeneric)
+  # Perhaps use strerror_r if available, and strerror_l isn't.
+  ac_save_CFLAGS="$CFLAGS"     
+  CFLAGS="-Wimplicit-function-declaration -Werror"
+  AC_TRY_COMPILE([#define _GNU_SOURCE 1
+                 #include <string.h>
+                 #include <locale.h>],
+                 [char s[128]; strerror_r(5, s, 128);], 
+                  AC_DEFINE(HAVE_STRERROR_R, 1, 
+                  [Define if strerror_r is available in <string.h>.]),)
+  CFLAGS="$ac_save_CFLAGS"
+
+  # Set configure bits for specified locale package
+  AC_MSG_CHECKING([for C locale to use])
+  case ${enable_clocale_flag} in
+    generic)
       AC_MSG_RESULT(generic)
 
       CLOCALE_H=config/locale/generic/c_locale.h
       CLOCALE_CC=config/locale/generic/c_locale.cc
-      CCODECVT_H=config/locale/generic/codecvt_specializations.h
       CCODECVT_CC=config/locale/generic/codecvt_members.cc
       CCOLLATE_CC=config/locale/generic/collate_members.cc
       CCTYPE_CC=config/locale/generic/ctype_members.cc
@@ -1235,7 +1856,24 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
       CTIME_CC=config/locale/generic/time_members.cc
       CLOCALE_INTERNAL_H=config/locale/generic/c++locale_internal.h
       ;;
-    xgnu)
+    darwin)
+      AC_MSG_RESULT(darwin or freebsd)
+
+      CLOCALE_H=config/locale/generic/c_locale.h
+      CLOCALE_CC=config/locale/generic/c_locale.cc
+      CCODECVT_CC=config/locale/generic/codecvt_members.cc
+      CCOLLATE_CC=config/locale/generic/collate_members.cc
+      CCTYPE_CC=config/locale/darwin/ctype_members.cc
+      CMESSAGES_H=config/locale/generic/messages_members.h
+      CMESSAGES_CC=config/locale/generic/messages_members.cc
+      CMONEY_CC=config/locale/generic/monetary_members.cc
+      CNUMERIC_CC=config/locale/generic/numeric_members.cc
+      CTIME_H=config/locale/generic/time_members.h
+      CTIME_CC=config/locale/generic/time_members.cc
+      CLOCALE_INTERNAL_H=config/locale/generic/c++locale_internal.h
+      ;;
+       
+    gnu)
       AC_MSG_RESULT(gnu)
 
       # Declare intention to use gettext, and add support for specific
@@ -1246,19 +1884,18 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
       # Don't call AM-GNU-GETTEXT here. Instead, assume glibc.
       AC_CHECK_PROG(check_msgfmt, msgfmt, yes, no)
       if test x"$check_msgfmt" = x"yes" && test x"$enable_nls" = x"yes"; then
-       USE_NLS=yes
+        USE_NLS=yes
       fi
       # Export the build objects.
       for ling in $ALL_LINGUAS; do \
-        glibcpp_MOFILES="$glibcpp_MOFILES $ling.mo"; \
-        glibcpp_POFILES="$glibcpp_POFILES $ling.po"; \
+        glibcxx_MOFILES="$glibcxx_MOFILES $ling.mo"; \
+        glibcxx_POFILES="$glibcxx_POFILES $ling.po"; \
       done
-      AC_SUBST(glibcpp_MOFILES)
-      AC_SUBST(glibcpp_POFILES)
+      AC_SUBST(glibcxx_MOFILES)
+      AC_SUBST(glibcxx_POFILES)
 
       CLOCALE_H=config/locale/gnu/c_locale.h
       CLOCALE_CC=config/locale/gnu/c_locale.cc
-      CCODECVT_H=config/locale/ieee_1003.1-2001/codecvt_specializations.h
       CCODECVT_CC=config/locale/gnu/codecvt_members.cc
       CCOLLATE_CC=config/locale/gnu/collate_members.cc
       CCTYPE_CC=config/locale/gnu/ctype_members.cc
@@ -1270,12 +1907,11 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
       CTIME_CC=config/locale/gnu/time_members.cc
       CLOCALE_INTERNAL_H=config/locale/gnu/c++locale_internal.h
       ;;
-    xieee_1003.1-2001)
-      AC_MSG_RESULT(generic)
+    ieee_1003.1-2001)
+      AC_MSG_RESULT(IEEE 1003.1)
 
       CLOCALE_H=config/locale/ieee_1003.1-2001/c_locale.h
       CLOCALE_CC=config/locale/ieee_1003.1-2001/c_locale.cc
-      CCODECVT_H=config/locale/ieee_1003.1-2001/codecvt_specializations.h
       CCODECVT_CC=config/locale/generic/codecvt_members.cc
       CCOLLATE_CC=config/locale/generic/collate_members.cc
       CCTYPE_CC=config/locale/generic/ctype_members.cc
@@ -1287,831 +1923,1046 @@ AC_DEFUN(GLIBCPP_ENABLE_CLOCALE, [
       CTIME_CC=config/locale/generic/time_members.cc
       CLOCALE_INTERNAL_H=config/locale/generic/c++locale_internal.h
       ;;
-    *)
-      echo "$enable_clocale is an unknown locale package" 1>&2
-      exit 1
-      ;;
   esac
 
   # This is where the testsuite looks for locale catalogs, using the
   # -DLOCALEDIR define during testsuite compilation.
-  glibcpp_localedir=${glibcpp_builddir}/po/share/locale
-  AC_SUBST(glibcpp_localedir)
+  glibcxx_localedir=${glibcxx_builddir}/po/share/locale
+  AC_SUBST(glibcxx_localedir)
 
-  # For the time being, transform ctype_noninline.h to ctype_members_char.cc
-#  CCTYPE_CHAR_CC=config/${os_include_dir}/ctype_noninline.h
+  # A standalone libintl (e.g., GNU libintl) may be in use.
+  if test $USE_NLS = yes; then
+    AC_CHECK_HEADERS([libintl.h], [], USE_NLS=no)
+    AC_SEARCH_LIBS(gettext, intl, [], USE_NLS=no)
+  fi
+  if test $USE_NLS = yes; then
+    AC_DEFINE(_GLIBCXX_USE_NLS, 1, 
+              [Define if NLS translations are to be used.])
+  fi
 
   AC_SUBST(USE_NLS)
   AC_SUBST(CLOCALE_H)
-  AC_SUBST(CCODECVT_H)
   AC_SUBST(CMESSAGES_H)
+  AC_SUBST(CCODECVT_CC)
+  AC_SUBST(CCOLLATE_CC)
+  AC_SUBST(CCTYPE_CC)
+  AC_SUBST(CMESSAGES_CC)
+  AC_SUBST(CMONEY_CC)
+  AC_SUBST(CNUMERIC_CC)
   AC_SUBST(CTIME_H)
-  AC_LINK_FILES($CLOCALE_CC, src/c++locale.cc)
-  AC_LINK_FILES($CCODECVT_CC, src/codecvt_members.cc)
-  AC_LINK_FILES($CCOLLATE_CC, src/collate_members.cc)
-#  AC_LINK_FILES($CCTYPE_CHAR_CC, src/ctype_members_char.cc)
-  AC_LINK_FILES($CCTYPE_CC, src/ctype_members.cc)
-  AC_LINK_FILES($CMESSAGES_CC, src/messages_members.cc)
-  AC_LINK_FILES($CMONEY_CC, src/monetary_members.cc)
-  AC_LINK_FILES($CNUMERIC_CC, src/numeric_members.cc)
-  AC_LINK_FILES($CTIME_CC, src/time_members.cc)
-  AC_LINK_FILES($CLOCALE_INTERNAL_H, src/c++locale_internal.h)
+  AC_SUBST(CTIME_CC)
+  AC_SUBST(CLOCALE_CC)
+  AC_SUBST(CLOCALE_INTERNAL_H)
 ])
 
 
 dnl
-dnl Check for which I/O library to use:  libio, or something specific.
-dnl
-dnl GLIBCPP_ENABLE_CSTDIO
-dnl --enable-cstdio=libio sets config/io/c_io_libio.h and friends
-dnl 
-dnl default is stdio
-dnl
-AC_DEFUN(GLIBCPP_ENABLE_CSTDIO, [
-  AC_MSG_CHECKING([for cstdio to use])
-  AC_ARG_ENABLE(cstdio,
-  [  --enable-cstdio         enable stdio for target io package. 
-  --enable-cstdio=LIB     use LIB target-speific io package. [default=stdio]
-  ], 
-  if test x$enable_cstdio = xno; then
-     enable_cstdio=stdio
-  fi,
-     enable_cstdio=stdio)
-
-  enable_cstdio_flag=$enable_cstdio
-
-  dnl Check if a valid I/O package
-  case x${enable_cstdio_flag} in
-    xlibio)
-      CSTDIO_H=config/io/c_io_libio.h
-      BASIC_FILE_H=config/io/basic_file_libio.h
-      BASIC_FILE_CC=config/io/basic_file_libio.cc
-      AC_MSG_RESULT(libio)
-
-      # see if we are on a system with libio native (ie, linux)
-      AC_CHECK_HEADER(libio.h,  has_libio=yes, has_libio=no)
-
-      # Need to check and see what version of glibc is being used. If
-      # it's not glibc-2.2 or higher, then we'll need to go ahead and 
-      # compile most of libio for linux systems.
-      if test x$has_libio = x"yes"; then
-        case "$target" in
-          *-*-linux*)
-              AC_MSG_CHECKING([for glibc version >= 2.2])
-              AC_EGREP_CPP([ok], [
-            #include <features.h>
-              #if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) 
-                    ok
-              #endif
-              ], glibc_satisfactory=yes, glibc_satisfactory=no)
-              AC_MSG_RESULT($glibc_satisfactory)
-            ;;
-        esac
-
-        # XXX at the moment, admit defeat and force the recompilation
-        # XXX of glibc even on glibc-2.2 systems, because libio is not synched.
-        glibc_satisfactory=no        
-
-        if test x$glibc_satisfactory = x"yes"; then
-           need_libio=no
-           need_wlibio=no        
-        else
-           need_libio=yes
-           # bkoz XXX need to add checks to enable this
-           # pme XXX here's a first pass at such a check
-           if test x$enable_c_mbchar != xno; then
-              need_wlibio=yes
-           else
-              need_wlibio=no
-           fi
-        fi
+dnl Check for which std::allocator base class to use.  The choice is
+dnl mapped from a subdirectory of include/ext.
+dnl
+dnl Default is new.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_ALLOCATOR], [
+  AC_MSG_CHECKING([for std::allocator base class])
+  GLIBCXX_ENABLE(libstdcxx-allocator,auto,[=KIND],
+    [use KIND for target std::allocator base],
+    [permit new|malloc|mt|bitmap|pool|yes|no|auto])
 
-      else
-         # Using libio, but <libio.h> doesn't exist on the target system. . .
-         need_libio=yes
-         # bkoz XXX need to add checks to enable this
-         # pme XXX here's a first pass at such a check
-         if test x$enable_c_mbchar != xno; then
-             need_wlibio=yes
-         else
-             need_wlibio=no
-         fi
-      fi
+  # If they didn't use this option switch, or if they specified --enable
+  # with no specific model, we'll have to look for one.  If they
+  # specified --disable (???), do likewise.
+  if test $enable_libstdcxx_allocator = no ||
+     test $enable_libstdcxx_allocator = yes;
+  then
+     enable_libstdcxx_allocator=auto
+  fi
+
+  # Either a known package, or "auto". Auto implies the default choice
+  # for a particular platform.
+  enable_libstdcxx_allocator_flag=$enable_libstdcxx_allocator
+
+  # Probe for host-specific support if no specific model is specified.
+  # Default to "new".
+  if test $enable_libstdcxx_allocator_flag = auto; then
+    case ${target_os} in
+      linux* | gnu* | kfreebsd*-gnu | knetbsd*-gnu)
+        enable_libstdcxx_allocator_flag=new
+        ;;
+      *)
+        enable_libstdcxx_allocator_flag=new
+        ;;
+    esac
+  fi
+  AC_MSG_RESULT($enable_libstdcxx_allocator_flag)
+  
+
+  # Set configure bits for specified locale package
+  case ${enable_libstdcxx_allocator_flag} in
+    bitmap)
+      ALLOCATOR_H=config/allocator/bitmap_allocator_base.h
+      ALLOCATOR_NAME=__gnu_cxx::bitmap_allocator
+      ;;
+    malloc)
+      ALLOCATOR_H=config/allocator/malloc_allocator_base.h
+      ALLOCATOR_NAME=__gnu_cxx::malloc_allocator
+      ;;
+    mt)
+      ALLOCATOR_H=config/allocator/mt_allocator_base.h
+      ALLOCATOR_NAME=__gnu_cxx::__mt_alloc
+      ;;
+    new)
+      ALLOCATOR_H=config/allocator/new_allocator_base.h
+      ALLOCATOR_NAME=__gnu_cxx::new_allocator
       ;;
-    xstdio | x | xno | xnone | xyes)
-      # default
+    pool)
+      ALLOCATOR_H=config/allocator/pool_allocator_base.h
+      ALLOCATOR_NAME=__gnu_cxx::__pool_alloc
+      ;;       
+  esac
+
+  AC_SUBST(ALLOCATOR_H)
+  AC_SUBST(ALLOCATOR_NAME)
+])
+
+
+dnl
+dnl Check for whether the Boost-derived checks should be turned on.
+dnl
+dnl --enable-concept-checks turns them on.
+dnl --disable-concept-checks leaves them off.
+dnl  +  Usage:  GLIBCXX_ENABLE_CONCEPT_CHECKS[(DEFAULT)]
+dnl       Where DEFAULT is either `yes' or `no'.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_CONCEPT_CHECKS], [
+  GLIBCXX_ENABLE(concept-checks,$1,,[use Boost-derived template checks])
+  if test $enable_concept_checks = yes; then
+    AC_DEFINE(_GLIBCXX_CONCEPT_CHECKS, 1,
+              [Define to use concept checking code from the boost libraries.])
+  fi
+])
+
+dnl
+dnl Check for parallel mode pre-requisites, including OpenMP support.
+dnl
+dnl  +  Usage:  GLIBCXX_ENABLE_PARALLEL
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_PARALLEL], [
+
+  enable_parallel=no;
+
+  # See if configured libgomp/omp.h exists. (libgomp may be in
+  # noconfigdirs but not explicitly disabled.)
+  if test -f $glibcxx_builddir/../libgomp/omp.h; then
+    enable_parallel=yes;
+  else
+    AC_MSG_NOTICE([$glibcxx_builddir/../libgomp/omp.h not found])
+  fi
+
+  AC_MSG_CHECKING([for parallel mode support])
+  AC_MSG_RESULT([$enable_parallel])
+  GLIBCXX_CONDITIONAL(ENABLE_PARALLEL, test $enable_parallel = yes)
+])
+
+
+dnl
+dnl Check for which I/O library to use:  stdio, or something specific.
+dnl
+dnl Default is stdio.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_CSTDIO], [
+  AC_MSG_CHECKING([for underlying I/O to use])
+  GLIBCXX_ENABLE(cstdio,stdio,[=PACKAGE],
+    [use target-specific I/O package], [permit stdio])
+
+  # Now that libio has been removed, you can have any color you want as long
+  # as it's black.  This is one big no-op until other packages are added, but
+  # showing the framework never hurts.
+  case ${enable_cstdio} in
+    stdio)
       CSTDIO_H=config/io/c_io_stdio.h
       BASIC_FILE_H=config/io/basic_file_stdio.h
       BASIC_FILE_CC=config/io/basic_file_stdio.cc
       AC_MSG_RESULT(stdio)
-
-      # We're not using stdio.
-      need_libio=no
-      need_wlibio=no
-      ;;
-    *)
-      echo "$enable_cstdio is an unknown io package" 1>&2
-      exit 1
       ;;
   esac
+
   AC_SUBST(CSTDIO_H)
   AC_SUBST(BASIC_FILE_H)
-  AC_LINK_FILES($BASIC_FILE_CC, src/basic_file.cc)
-
-  # 2000-08-04 bkoz hack
-  CCODECVT_C=config/io/c_io_libio_codecvt.c
-  AC_SUBST(CCODECVT_C)
-  # 2000-08-04 bkoz hack
-
-  AM_CONDITIONAL(GLIBCPP_BUILD_LIBIO,
-                 test "$need_libio" = yes || test "$need_wlibio" = yes)
-  AM_CONDITIONAL(GLIBCPP_NEED_LIBIO, test "$need_libio" = yes)
-  AM_CONDITIONAL(GLIBCPP_NEED_WLIBIO, test "$need_wlibio" = yes)
-  if test "$need_libio" = yes || test "$need_wlibio" = yes; then
-    libio_la=../libio/libio.la
-  else
-    libio_la=
-  fi
-  AC_SUBST(libio_la)
+  AC_SUBST(BASIC_FILE_CC)
 ])
 
 
 dnl
-dnl Setup to use the gcc gthr.h thread-specific memory and mutex model.
-dnl We must stage the required headers so that they will be installed
-dnl with the library (unlike libgcc, the STL implementation is provided
-dnl solely within headers).  Since we must not inject random user-space
-dnl macro names into user-provided C++ code, we first stage into <file>-in
-dnl and process to <file> with an output command.  The reason for a two-
-dnl stage process here is to correctly handle $srcdir!=$objdir without
-dnl having to write complex code (the sed commands to clean the macro
-dnl namespace are complex and fragile enough as it is).  We must also
-dnl add a relative path so that -I- is supported properly.
+dnl Check for "unusual" flags to pass to the compiler while building.
 dnl
-AC_DEFUN(GLIBCPP_ENABLE_THREADS, [
-  AC_MSG_CHECKING([for thread model used by GCC])
-  target_thread_file=`$CC -v 2>&1 | sed -n 's/^Thread model: //p'`
-  AC_MSG_RESULT([$target_thread_file])
-
-  if test $target_thread_file != single; then
-    AC_DEFINE(HAVE_GTHR_DEFAULT)
-    AC_DEFINE(_GLIBCPP_SUPPORTS_WEAK, __GXX_WEAK__)
+dnl --enable-cxx-flags='-foo -bar -baz' is a general method for passing
+dnl     experimental flags such as -fpch, -fIMI, -Dfloat=char, etc.
+dnl --disable-cxx-flags passes nothing.
+dnl  +  See http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00131.html
+dnl         http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00284.html
+dnl         http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00035.html
+dnl  +  Usage:  GLIBCXX_ENABLE_CXX_FLAGS(default flags)
+dnl       If "default flags" is an empty string, the effect is the same
+dnl       as --disable or --enable=no.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_CXX_FLAGS], [dnl
+  AC_MSG_CHECKING([for extra compiler flags for building])
+  GLIBCXX_ENABLE(cxx-flags,$1,[=FLAGS],
+    [pass compiler FLAGS when building library],
+    [case "x$enable_cxx_flags" in
+      xno | x)   enable_cxx_flags= ;;
+      x-*)       ;;
+      *)         AC_MSG_ERROR(_g_switch needs compiler flags as arguments) ;;
+     esac])
+
+  # Run through flags (either default or command-line) and set anything
+  # extra (e.g., #defines) that must accompany particular g++ options.
+  if test -n "$enable_cxx_flags"; then
+    for f in $enable_cxx_flags; do
+      case "$f" in
+        -fhonor-std)  ;;
+        -*)  ;;
+        *)   # and we're trying to pass /what/ exactly?
+             AC_MSG_ERROR([compiler flags start with a -]) ;;
+      esac
+    done
   fi
 
-  glibcpp_thread_h=gthr-$target_thread_file.h
-  AC_SUBST(glibcpp_thread_h)
+  EXTRA_CXX_FLAGS="$enable_cxx_flags"
+  AC_MSG_RESULT($EXTRA_CXX_FLAGS)
+  AC_SUBST(EXTRA_CXX_FLAGS)
 ])
 
 
 dnl
-dnl Check for exception handling support.  If an explicit enable/disable
-dnl sjlj exceptions is given, we don't have to detect.  Otherwise the
-dnl target may or may not support call frame exceptions.
+dnl Check to see if debugging libraries are to be built.
 dnl
-dnl GLIBCPP_ENABLE_SJLJ_EXCEPTIONS
-dnl --enable-sjlj-exceptions forces the use of builtin setjmp.
-dnl --disable-sjlj-exceptions forces the use of call frame unwinding.
+dnl --enable-libstdcxx-debug
+dnl builds a separate set of debugging libraries in addition to the
+dnl normal (shared, static) libstdc++ binaries.
 dnl
-dnl Define _GLIBCPP_SJLJ_EXCEPTIONS if the compiler is configured for it.
+dnl --disable-libstdcxx-debug
+dnl builds only one (non-debug) version of libstdc++.
 dnl
-AC_DEFUN(GLIBCPP_ENABLE_SJLJ_EXCEPTIONS, [
-  AC_MSG_CHECKING([for exception model to use])
-  AC_LANG_SAVE
-  AC_LANG_CPLUSPLUS
-  AC_ARG_ENABLE(sjlj-exceptions,
-  [  --enable-sjlj-exceptions  force use of builtin_setjmp for exceptions],
-  [:],
-  [dnl Botheration.  Now we've got to detect the exception model.
-   dnl Link tests against libgcc.a are problematic since -- at least
-   dnl as of this writing -- we've not been given proper -L bits for
-   dnl single-tree newlib and libgloss.
-   dnl
-   dnl This is what AC_TRY_COMPILE would do if it didn't delete the
-   dnl conftest files before we got a change to grep them first.
-   cat > conftest.$ac_ext << EOF
-[#]line __oline__ "configure"
-struct S { ~S(); };
-void bar();
-void foo()
-{
-  S s;
-  bar();
-}
-EOF
-   old_CXXFLAGS="$CXXFLAGS"  
-   CXXFLAGS="-S -fexceptions"
-   if AC_TRY_EVAL(ac_compile); then
-     if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1 ; then
-       enable_sjlj_exceptions=yes
-     elif grep _Unwind_Resume conftest.s >/dev/null 2>&1 ; then
-       enable_sjlj_exceptions=no
-     fi
-   fi
-   CXXFLAGS="$old_CXXFLAGS"
-   rm -f conftest*])
-   if test x$enable_sjlj_exceptions = xyes; then
-     AC_DEFINE(_GLIBCPP_SJLJ_EXCEPTIONS, 1,
-        [Define if the compiler is configured for setjmp/longjmp exceptions.])
-     ac_exception_model_name=sjlj
-   elif test x$enable_sjlj_exceptions = xno; then
-     ac_exception_model_name="call frame"
-   else
-     AC_MSG_ERROR([unable to detect exception model])
-   fi
-   AC_LANG_RESTORE
-   AC_MSG_RESULT($ac_exception_model_name)
+dnl --enable-libstdcxx-debug-flags=FLAGS
+dnl iff --enable-debug == yes, then use FLAGS to build the debug library.
+dnl
+dnl  +  Usage:  GLIBCXX_ENABLE_DEBUG[(DEFAULT)]
+dnl       Where DEFAULT is either `yes' or `no'.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_DEBUG], [
+  AC_MSG_CHECKING([for additional debug build])
+  GLIBCXX_ENABLE(libstdcxx-debug,$1,,[build extra debug library])
+  AC_MSG_RESULT($enable_libstdcxx_debug)
+  GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_DEBUG, test $enable_libstdcxx_debug = yes)
 ])
 
 
 dnl
-dnl Check for libunwind exception handling support. If enabled then
-dnl we assume that the _Unwind_* functions that make up the Unwind ABI
-dnl (_Unwind_RaiseException, _Unwind_Resume, etc.) are defined by
-dnl libunwind instead of libgcc and that libstdc++ has a dependency
-dnl on libunwind as well as libgcc.
+dnl Check for explicit debug flags.
 dnl
-dnl GLIBCPP_ENABLE_LIBUNWIND_EXCEPTIONS
-dnl --enable-libunwind-exceptions forces the use of libunwind.
-dnl --disable-libunwind-exceptions assumes there is no libunwind.
+dnl --enable-libstdcxx-debug-flags='-O1'
+dnl is a general method for passing flags to be used when
+dnl building debug libraries with --enable-debug.
 dnl
-dnl Define _GLIBCPP_LIBUNWIND_EXCEPTIONS if requested.
+dnl --disable-libstdcxx-debug-flags does nothing.
+dnl  +  Usage:  GLIBCXX_ENABLE_DEBUG_FLAGS(default flags)
+dnl       If "default flags" is an empty string, the effect is the same
+dnl       as --disable or --enable=no.
 dnl
-AC_DEFUN(GLIBCPP_ENABLE_LIBUNWIND_EXCEPTIONS, [
-  AC_MSG_CHECKING([for use of libunwind])
-  AC_ARG_ENABLE(libunwind-exceptions,
-  [  --enable-libunwind-exceptions  force use of libunwind for exceptions],
-  use_libunwind_exceptions=$enableval,
-  use_libunwind_exceptions=no)
-  AC_MSG_RESULT($use_libunwind_exceptions)
-  dnl Option parsed, now set things appropriately
-  if test x"$use_libunwind_exceptions" = xyes; then
-    LIBUNWIND_FLAG="-lunwind"
-  else
-    LIBUNWIND_FLAG=""
-  fi
-  AC_SUBST(LIBUNWIND_FLAG)
-])
+AC_DEFUN([GLIBCXX_ENABLE_DEBUG_FLAGS], [
+  GLIBCXX_ENABLE(libstdcxx-debug-flags,[$1],[=FLAGS],
+    [pass compiler FLAGS when building debug library],
+    [case "x$enable_libstdcxx_debug_flags" in
+      xno | x)    enable_libstdcxx_debug_flags= ;;
+      x-*)        ;;
+      *)          AC_MSG_ERROR(_g_switch needs compiler flags as arguments) ;;
+     esac])
 
-dnl
-dnl Check for ISO/IEC 9899:1999 "C99" support.
-dnl
-dnl GLIBCPP_ENABLE_C99
-dnl --enable-c99 defines _GLIBCPP_USE_C99
-dnl --disable-c99 leaves _GLIBCPP_USE_C99 undefined
-dnl  +  Usage:  GLIBCPP_ENABLE_C99[(DEFAULT)]
-dnl       Where DEFAULT is either `yes' or `no'.  If omitted, it
-dnl       defaults to `no'.
-dnl  +  If 'C99' stuff is not available, ignores DEFAULT and sets `no'.
-dnl
-dnl GLIBCPP_ENABLE_C99
-AC_DEFUN(GLIBCPP_ENABLE_C99, [dnl
-  define([GLIBCPP_ENABLE_C99_DEFAULT], ifelse($1, yes, yes, no))dnl
-
-  AC_ARG_ENABLE(c99,
-  changequote(<<, >>)dnl
-  <<--enable-c99            turns on 'ISO/IEC 9899:1999 support' [default=>>GLIBCPP_ENABLE_C99_DEFAULT],
-  changequote([, ])dnl
-  [case "$enableval" in
-   yes) enable_c99=yes ;;
-   no)  enable_c99=no ;;
-   *)   AC_MSG_ERROR([Unknown argument to enable/disable C99]) ;;
-   esac],
-  enable_c99=GLIBCPP_ENABLE_C99_DEFAULT)dnl
-  AC_LANG_SAVE
-  AC_LANG_CPLUSPLUS
-
-  # Check for the existence of <math.h> functions used if C99 is enabled.
-  ac_c99_math=yes;
-  AC_MSG_CHECKING([for ISO C99 support in <math.h>])
-  AC_TRY_COMPILE([#include <math.h>],[fpclassify(0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[isfinite(0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[isinf(0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[isnan(0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[isnormal(0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[signbit(0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[isgreater(0.0,0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],
-                 [isgreaterequal(0.0,0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[isless(0.0,0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],[islessequal(0.0,0.0);],,[ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],
-                [islessgreater(0.0,0.0);],, [ac_c99_math=no])
-  AC_TRY_COMPILE([#include <math.h>],
-                [isunordered(0.0,0.0);],, [ac_c99_math=no])
-  AC_MSG_RESULT($ac_c99_math)
+  # Option parsed, now set things appropriately
+  DEBUG_FLAGS="$enable_libstdcxx_debug_flags"
+  AC_SUBST(DEBUG_FLAGS)
 
-  # Check for the existence in <stdio.h> of vscanf, et. al.
-  ac_c99_stdio=yes;
-  AC_MSG_CHECKING([for ISO C99 support in <stdio.h>])
-  AC_TRY_COMPILE([#include <stdio.h>],
-                [snprintf("12", 0, "%i");],, [ac_c99_stdio=no])
-  AC_TRY_COMPILE([#include <stdio.h>
-                 #include <stdarg.h>
-                 void foo(char* fmt, ...)
-                 {va_list args; va_start(args, fmt);
-                 vfscanf(stderr, "%i", args);}],
-                 [],, [ac_c99_stdio=no])
-  AC_TRY_COMPILE([#include <stdio.h>
-                 #include <stdarg.h>
-                 void foo(char* fmt, ...)
-                 {va_list args; va_start(args, fmt);
-                 vscanf("%i", args);}],
-                 [],, [ac_c99_stdio=no])
-  AC_TRY_COMPILE([#include <stdio.h>
-                 #include <stdarg.h>
-                 void foo(char* fmt, ...)
-                 {va_list args; va_start(args, fmt);
-                 vsnprintf(fmt, 0, "%i", args);}],
-                 [],, [ac_c99_stdio=no])
-  AC_TRY_COMPILE([#include <stdio.h>
-                 #include <stdarg.h>
-                 void foo(char* fmt, ...)
-                 {va_list args; va_start(args, fmt);
-                 vsscanf(fmt, "%i", args);}],
-                 [],, [ac_c99_stdio=no])
-  AC_MSG_RESULT($ac_c99_stdio)
+  AC_MSG_NOTICE([Debug build flags set to $DEBUG_FLAGS])
+])
 
-  # Check for the existence in <stdlib.h> of lldiv_t, et. al.
-  ac_c99_stdlib=yes;
-  AC_MSG_CHECKING([for lldiv_t declaration])
-  AC_CACHE_VAL(ac_c99_lldiv_t, [
-  AC_TRY_COMPILE([#include <stdlib.h>], 
-                   [ lldiv_t mydivt;], 
-                   [ac_c99_lldiv_t=yes], [ac_c99_lldiv_t=no])
-  ])
-  AC_MSG_RESULT($ac_c99_lldiv_t)
 
-  AC_MSG_CHECKING([for ISO C99 support in <stdlib.h>])
-  AC_TRY_COMPILE([#include <stdlib.h>],
-                [char* tmp; strtof("gnu", &tmp);],, [ac_c99_stdlib=no])
-  AC_TRY_COMPILE([#include <stdlib.h>],
-                [char* tmp; strtold("gnu", &tmp);],, [ac_c99_stdlib=no])
-  AC_TRY_COMPILE([#include <stdlib.h>], [llabs(10);],, [ac_c99_stdlib=no])
-  AC_TRY_COMPILE([#include <stdlib.h>], [lldiv(10,1);],, [ac_c99_stdlib=no])
-  AC_TRY_COMPILE([#include <stdlib.h>], [atoll("10");],, [ac_c99_stdlib=no])
-  AC_TRY_COMPILE([#include <stdlib.h>], [_Exit(0);],, [ac_c99_stdlib=no])
-  if test x"$ac_c99_lldiv_t" = x"no"; then
-    ac_c99_stdlib=no; 
-  fi; 
-  AC_MSG_RESULT($ac_c99_stdlib)
-
-  # Check for the existence of <wchar.h> functions used if C99 is enabled.
-  # XXX the wchar.h checks should be rolled into the general C99 bits.
-  ac_c99_wchar=yes;
-  AC_MSG_CHECKING([for additional ISO C99 support in <wchar.h>])
-  AC_TRY_COMPILE([#include <wchar.h>], 
-                [wcstold(L"10.0", NULL);],, [ac_c99_wchar=no])
-  AC_TRY_COMPILE([#include <wchar.h>], 
-                [wcstoll(L"10", NULL, 10);],, [ac_c99_wchar=no])
-  AC_TRY_COMPILE([#include <wchar.h>], 
-                [wcstoull(L"10", NULL, 10);],, [ac_c99_wchar=no])
-  AC_MSG_RESULT($ac_c99_wchar)
-
-  AC_MSG_CHECKING([for enabled ISO C99 support])
-  if test x"$ac_c99_math" = x"no" ||
-     test x"$ac_c99_stdio" = x"no" ||
-     test x"$ac_c99_stdlib" = x"no" ||
-     test x"$ac_c99_wchar" = x"no"; then
-    enable_c99=no; 
-  fi; 
-  AC_MSG_RESULT($enable_c99)
-
-  # Option parsed, now set things appropriately
-  if test x"$enable_c99" = x"yes"; then
-    AC_DEFINE(_GLIBCPP_USE_C99)
+dnl
+dnl Check if the user only wants a freestanding library implementation.
+dnl
+dnl --disable-hosted-libstdcxx will turn off most of the library build,
+dnl installing only the headers required by [17.4.1.3] and the language
+dnl support library.  More than that will be built (to keep the Makefiles
+dnl conveniently clean), but not installed.
+dnl
+dnl Sets:
+dnl  is_hosted  (yes/no)
+dnl
+dnl Defines:
+dnl  _GLIBCXX_HOSTED   (always defined, either to 1 or 0)
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_HOSTED], [
+  AC_ARG_ENABLE([hosted-libstdcxx],
+    AC_HELP_STRING([--disable-hosted-libstdcxx],
+                   [only build freestanding C++ runtime support]),,
+    [case "$host" in
+       arm*-*-symbianelf*) 
+           enable_hosted_libstdcxx=no
+           ;;
+        *) 
+           enable_hosted_libstdcxx=yes
+           ;;
+     esac])
+  if test "$enable_hosted_libstdcxx" = no; then
+    AC_MSG_NOTICE([Only freestanding libraries will be built])
+    is_hosted=no
+    hosted_define=0
+    enable_abi_check=no
+    enable_libstdcxx_pch=no
+  else
+    is_hosted=yes
+    hosted_define=1
   fi
-
-  AC_LANG_RESTORE
+  GLIBCXX_CONDITIONAL(GLIBCXX_HOSTED, test $is_hosted = yes)
+  AC_DEFINE_UNQUOTED(_GLIBCXX_HOSTED, $hosted_define,
+    [Define to 1 if a full hosted library is built, or 0 if freestanding.])
 ])
 
 
 dnl
-dnl Check for template specializations for the 'long long' type extension.
+dnl Check for template specializations for the 'long long' type.
 dnl The result determines only whether 'long long' I/O is enabled; things
 dnl like numeric_limits<> specializations are always available.
 dnl
-dnl GLIBCPP_ENABLE_LONG_LONG
-dnl --enable-long-long defines _GLIBCPP_USE_LONG_LONG
-dnl --disable-long-long leaves _GLIBCPP_USE_LONG_LONG undefined
-dnl  +  Usage:  GLIBCPP_ENABLE_LONG_LONG[(DEFAULT)]
-dnl       Where DEFAULT is either `yes' or `no'.  If omitted, it
-dnl       defaults to `no'.
-dnl  +  If 'long long' stuff is not available, ignores DEFAULT and sets `no'.
-dnl
-dnl GLIBCPP_ENABLE_LONG_LONG
-AC_DEFUN(GLIBCPP_ENABLE_LONG_LONG, [dnl
-  define([GLIBCPP_ENABLE_LONG_LONG_DEFAULT], ifelse($1, yes, yes, no))dnl
-
-  AC_ARG_ENABLE(long-long,
-  changequote(<<, >>)dnl
-  <<--enable-long-long      turns on 'long long' [default=>>GLIBCPP_ENABLE_LONG_LONG_DEFAULT],
-  changequote([, ])dnl
-  [case "$enableval" in
-   yes) enable_long_long=yes ;;
-   no)  enable_long_long=no ;;
-   *)   AC_MSG_ERROR([Unknown argument to enable/disable long long]) ;;
-   esac],
-  enable_long_long=GLIBCPP_ENABLE_LONG_LONG_DEFAULT)dnl
+dnl --enable-long-long defines _GLIBCXX_USE_LONG_LONG
+dnl --disable-long-long leaves _GLIBCXX_USE_LONG_LONG undefined
+dnl  +  Usage:  GLIBCXX_ENABLE_LONG_LONG[(DEFAULT)]
+dnl       Where DEFAULT is either `yes' or `no'.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_LONG_LONG], [
+  GLIBCXX_ENABLE(long-long,$1,,[enable template specializations for 'long long'])
+  if test $enable_long_long = yes; then
+    AC_DEFINE(_GLIBCXX_USE_LONG_LONG, 1, 
+              [Define if code specialized for long long should be used.])
+  fi
+  AC_MSG_CHECKING([for enabled long long specializations])
+  AC_MSG_RESULT([$enable_long_long])
+])
 
-  AC_LANG_SAVE
-  AC_LANG_CPLUSPLUS
 
-  AC_MSG_CHECKING([for enabled long long I/O support])
-  # iostreams require strtoll, strtoull to compile
-  AC_TRY_COMPILE([#include <stdlib.h>],
-                 [char* tmp; strtoll("gnu", &tmp, 10);],,[enable_long_long=no])
-  AC_TRY_COMPILE([#include <stdlib.h>],
-                 [char* tmp; strtoull("gnu", &tmp, 10);],,[enable_long_long=no])
+dnl
+dnl Check for template specializations for the 'wchar_t' type.
+dnl
+dnl --enable-wchar_t defines _GLIBCXX_USE_WCHAR_T
+dnl --disable-wchar_t leaves _GLIBCXX_USE_WCHAR_T undefined
+dnl  +  Usage:  GLIBCXX_ENABLE_WCHAR_T[(DEFAULT)]
+dnl       Where DEFAULT is either `yes' or `no'.
+dnl
+dnl Necessary support must also be present.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_WCHAR_T], [
+  GLIBCXX_ENABLE(wchar_t,$1,,[enable template specializations for 'wchar_t'])
 
-  # Option parsed, now set things appropriately
-  if test x"$enable_long_long" = xyes; then
-    AC_DEFINE(_GLIBCPP_USE_LONG_LONG)
+  # Test wchar.h for mbstate_t, which is needed for char_traits and fpos.
+  AC_CHECK_HEADERS(wchar.h, ac_has_wchar_h=yes, ac_has_wchar_h=no)
+  AC_MSG_CHECKING([for mbstate_t])
+  AC_TRY_COMPILE([#include <wchar.h>],
+  [mbstate_t teststate;],
+  have_mbstate_t=yes, have_mbstate_t=no)
+  AC_MSG_RESULT($have_mbstate_t)
+  if test x"$have_mbstate_t" = xyes; then
+    AC_DEFINE(HAVE_MBSTATE_T,1,[Define if mbstate_t exists in wchar.h.])
   fi
-  AC_MSG_RESULT($enable_long_long)
 
-  AC_LANG_RESTORE
-])
+  # Test it always, for use in GLIBCXX_ENABLE_C99, together with
+  # ac_has_wchar_h.
+  AC_CHECK_HEADERS(wctype.h, ac_has_wctype_h=yes, ac_has_wctype_h=no)
+  
+  if test x"$enable_wchar_t" = x"yes"; then
 
+    AC_LANG_SAVE
+    AC_LANG_CPLUSPLUS
+    
+    if test x"$ac_has_wchar_h" = xyes &&
+       test x"$ac_has_wctype_h" = xyes; then
+      AC_TRY_COMPILE([#include <wchar.h>
+                      #include <stddef.h>
+                      wint_t i;
+                     long l = WEOF;
+                     long j = WCHAR_MIN;
+                     long k = WCHAR_MAX;
+                      namespace test
+                      {
+                       using ::btowc;
+                       using ::fgetwc;
+                       using ::fgetws;
+                       using ::fputwc;
+                       using ::fputws;
+                       using ::fwide;
+                       using ::fwprintf; 
+                       using ::fwscanf;
+                       using ::getwc;
+                       using ::getwchar;
+                       using ::mbrlen; 
+                       using ::mbrtowc; 
+                       using ::mbsinit; 
+                       using ::mbsrtowcs; 
+                       using ::putwc;
+                       using ::putwchar;
+                       using ::swprintf; 
+                       using ::swscanf; 
+                       using ::ungetwc;
+                       using ::vfwprintf; 
+                       using ::vswprintf; 
+                       using ::vwprintf; 
+                       using ::wcrtomb; 
+                       using ::wcscat; 
+                       using ::wcschr; 
+                       using ::wcscmp; 
+                       using ::wcscoll; 
+                       using ::wcscpy; 
+                       using ::wcscspn; 
+                       using ::wcsftime; 
+                       using ::wcslen;
+                       using ::wcsncat; 
+                       using ::wcsncmp; 
+                       using ::wcsncpy; 
+                       using ::wcspbrk;
+                       using ::wcsrchr; 
+                       using ::wcsrtombs; 
+                       using ::wcsspn; 
+                       using ::wcsstr;
+                       using ::wcstod; 
+                       using ::wcstok; 
+                       using ::wcstol;
+                       using ::wcstoul; 
+                       using ::wcsxfrm; 
+                       using ::wctob; 
+                       using ::wmemchr;
+                       using ::wmemcmp;
+                       using ::wmemcpy;
+                       using ::wmemmove;
+                       using ::wmemset;
+                       using ::wprintf; 
+                       using ::wscanf; 
+                     }
+                    ],[],[], [enable_wchar_t=no])
+    else
+      enable_wchar_t=no
+    fi
 
-dnl
-dnl Check for what kind of C headers to use.
-dnl
-dnl GLIBCPP_ENABLE_CHEADERS
-dnl --enable-cheaders= [does stuff].
-dnl --disable-cheaders [does not do anything, really].
-dnl  +  This will eventually need to be 'c_shadow' by default.
-dnl  +  Usage:  GLIBCPP_ENABLE_CHEADERS[(DEFAULT)]
-dnl       Where DEFAULT is either `c' or `c_std' or 'c_shadow'.  
-dnl       If ommitted, it defaults to `c_std'.
-AC_DEFUN(GLIBCPP_ENABLE_CHEADERS, [dnl
-define([GLIBCPP_ENABLE_CHEADERS_DEFAULT], ifelse($1, c_std, c_std, c_std))dnl
-AC_MSG_CHECKING([for c header strategy to use])
-AC_ARG_ENABLE(cheaders,
-changequote(<<, >>)dnl
-<<  --enable-cheaders       construct "C" header files for g++ [default=>>GLIBCPP_ENABLE_CHEADERS_DEFAULT],
-changequote([, ])
-  [case "$enableval" in
-   c) 
-        enable_cheaders=c 
-        ;;
-   c_std)  
-        enable_cheaders=c_std 
-        ;;
-   c_shadow)  
-        enable_cheaders=c_shadow 
-        ;;
-   *)   AC_MSG_ERROR([Unknown argument to enable/disable "C" headers]) 
-        ;;
-  esac],
-  enable_cheaders=GLIBCPP_ENABLE_CHEADERS_DEFAULT)
-  AC_MSG_RESULT($enable_cheaders)
-
-  dnl Option parsed, now set things appropriately
-  case "$enable_cheaders" in
-    c_shadow) 
-        C_INCLUDE_DIR='${glibcpp_srcdir}/include/c_shadow'
-        ;;
-    c_std)   
-        C_INCLUDE_DIR='${glibcpp_srcdir}/include/c_std'
-        ;;
-    c)   
-        C_INCLUDE_DIR='${glibcpp_srcdir}/include/c'
-        ;;
-  esac
+    AC_LANG_RESTORE
+  fi
 
-  AC_SUBST(C_INCLUDE_DIR)
-  AM_CONDITIONAL(GLIBCPP_C_HEADERS_C, test "$enable_cheaders" = c)
-  AM_CONDITIONAL(GLIBCPP_C_HEADERS_C_STD, test "$enable_cheaders" = c_std)
-  AM_CONDITIONAL(GLIBCPP_C_HEADERS_COMPATIBILITY, test "$c_compatibility" = yes)
+  if test x"$enable_wchar_t" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_USE_WCHAR_T, 1,
+              [Define if code specialized for wchar_t should be used.])
+  fi
+
+  AC_MSG_CHECKING([for enabled wchar_t specializations])
+  AC_MSG_RESULT([$enable_wchar_t])
 ])
 
 
 dnl
-dnl Check for wide character support.  Has the same effect as the option
-dnl in gcc's configure, but in a form that autoconf can mess with.
-dnl
-dnl GLIBCPP_ENABLE_C_MBCHAR
-dnl --enable-c-mbchar requests all the wchar_t stuff.
-dnl --disable-c-mbchar doesn't.
-dnl  +  Usage:  GLIBCPP_ENABLE_C_MBCHAR[(DEFAULT)]
-dnl       Where DEFAULT is either `yes' or `no'.  If ommitted, it
-dnl       defaults to `no'.
-AC_DEFUN(GLIBCPP_ENABLE_C_MBCHAR, [dnl
-define([GLIBCPP_ENABLE_C_MBCHAR_DEFAULT], ifelse($1, yes, yes, no))dnl
-AC_ARG_ENABLE(c-mbchar,
-changequote(<<, >>)dnl
-<<  --enable-c-mbchar       enable multibyte (wide) characters [default=>>GLIBCPP_ENABLE_C_MBCHAR_DEFAULT],
-changequote([, ])dnl
-[case "$enableval" in
- yes) enable_c_mbchar=yes ;;
- no)  enable_c_mbchar=no ;;
- *)   AC_MSG_ERROR([Unknown argument to enable/disable c-mbchar]) ;;
- esac],
-enable_c_mbchar=GLIBCPP_ENABLE_C_MBCHAR_DEFAULT)dnl
-dnl Option parsed, now other scripts can test enable_c_mbchar for yes/no.
+dnl Check to see if building and using a C++ precompiled header can be done.
+dnl
+dnl --enable-libstdcxx-pch=yes
+dnl default, this shows intent to use stdc++.h.gch If it looks like it
+dnl may work, after some light-hearted attempts to puzzle out compiler
+dnl support, flip bits on in include/Makefile.am
+dnl
+dnl --disable-libstdcxx-pch
+dnl turns off attempts to use or build stdc++.h.gch.
+dnl
+dnl Substs:
+dnl  glibcxx_PCHFLAGS
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_PCH], [
+  GLIBCXX_ENABLE(libstdcxx-pch,$1,,[build pre-compiled libstdc++ headers])
+  if test $enable_libstdcxx_pch = yes; then
+    AC_CACHE_CHECK([for compiler with PCH support],
+      [glibcxx_cv_prog_CXX_pch],
+      [ac_save_CXXFLAGS="$CXXFLAGS"
+       CXXFLAGS="$CXXFLAGS -Werror -Winvalid-pch -Wno-deprecated"
+       AC_LANG_SAVE
+       AC_LANG_CPLUSPLUS
+       echo '#include <math.h>' > conftest.h
+       if $CXX $CXXFLAGS $CPPFLAGS -x c++-header conftest.h \
+                         -o conftest.h.gch 1>&5 2>&1 &&
+               echo '#error "pch failed"' > conftest.h &&
+          echo '#include "conftest.h"' > conftest.cc &&
+              $CXX -c $CXXFLAGS $CPPFLAGS conftest.cc 1>&5 2>&1 ;
+       then
+         glibcxx_cv_prog_CXX_pch=yes
+       else
+         glibcxx_cv_prog_CXX_pch=no
+       fi
+       rm -f conftest*
+       CXXFLAGS=$ac_save_CXXFLAGS
+       AC_LANG_RESTORE
+      ])
+    enable_libstdcxx_pch=$glibcxx_cv_prog_CXX_pch
+  fi
+
+  AC_MSG_CHECKING([for enabled PCH])
+  AC_MSG_RESULT([$enable_libstdcxx_pch])
+
+  GLIBCXX_CONDITIONAL(GLIBCXX_BUILD_PCH, test $enable_libstdcxx_pch = yes)
+  if test $enable_libstdcxx_pch = yes; then
+    glibcxx_PCHFLAGS="-include bits/stdc++.h"
+  else
+    glibcxx_PCHFLAGS=""
+  fi
+  AC_SUBST(glibcxx_PCHFLAGS)
 ])
 
 
 dnl
-dnl Set up *_INCLUDES and *_INCLUDE_DIR variables for all sundry Makefile.am's.
+dnl Check for atomic builtins.
+dnl See:
+dnl http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html#Atomic-Builtins
+dnl
+dnl This checks to see if the host supports the compiler-generated
+dnl builtins for atomic operations for various integral sizes. Note, this 
+dnl is intended to be an all-or-nothing switch, so all the atomic operations
+dnl that are used should be checked.
+dnl
+dnl Note:
+dnl libgomp and libgfortran do this with a link test, instead of an asm test.
+dnl see: CHECK_SYNC_FETCH_AND_ADD
 dnl
-dnl TOPLEVEL_INCLUDES
-dnl LIBMATH_INCLUDES
-dnl LIBSUPCXX_INCLUDES
-dnl LIBIO_INCLUDES
-dnl CSHADOW_INCLUDES
+dnl Defines:
+dnl  _GLIBCXX_ATOMIC_BUILTINS_1 
+dnl  _GLIBCXX_ATOMIC_BUILTINS_2
+dnl  _GLIBCXX_ATOMIC_BUILTINS_4
+dnl  _GLIBCXX_ATOMIC_BUILTINS_8
 dnl
-dnl GLIBCPP_EXPORT_INCLUDES
-AC_DEFUN(GLIBCPP_EXPORT_INCLUDES, [
-  # Root level of the build directory include sources.
-  GLIBCPP_INCLUDES="-I${glibcpp_builddir}/include/${target_alias} -I${glibcpp_builddir}/include"
+AC_DEFUN([GLIBCXX_ENABLE_ATOMIC_BUILTINS], [
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  old_CXXFLAGS="$CXXFLAGS"
+  
+  # Compile unoptimized.
+  CXXFLAGS='-O0 -S'
 
-  # Passed down for canadian crosses.
-  if test x"$CANADIAN" = xyes; then
-    TOPLEVEL_INCLUDES='-I$(includedir)'
-  fi
+  # Fake what AC_TRY_COMPILE does, without linking as this is
+  # unnecessary for a builtins test.
+
+    cat > conftest.$ac_ext << EOF
+[#]line __oline__ "configure"
+int main()
+{
+  typedef bool atomic_type;
+  atomic_type c1;
+  atomic_type c2;
+  const atomic_type c3(0);
+  __sync_fetch_and_add(&c1, c2);
+  __sync_val_compare_and_swap(&c1, c3, c2);
+  __sync_lock_test_and_set(&c1, c3);
+  __sync_lock_release(&c1);
+  __sync_synchronize();
+  return 0;
+}
+EOF
+
+    AC_MSG_CHECKING([for atomic builtins for bool])
+    if AC_TRY_EVAL(ac_compile); then
+      if grep __sync_ conftest.s >/dev/null 2>&1 ; then
+        enable_atomic_builtinsb=no
+      else
+      AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_1, 1,
+      [Define if builtin atomic operations for bool are supported on this host.])
+        enable_atomic_builtinsb=yes
+      fi
+    fi
+    AC_MSG_RESULT($enable_atomic_builtinsb)
+    rm -f conftest*
+
+    cat > conftest.$ac_ext << EOF
+[#]line __oline__ "configure"
+int main()
+{
+  typedef short atomic_type;
+  atomic_type c1;
+  atomic_type c2;
+  const atomic_type c3(0);
+  __sync_fetch_and_add(&c1, c2);
+  __sync_val_compare_and_swap(&c1, c3, c2);
+  __sync_lock_test_and_set(&c1, c3);
+  __sync_lock_release(&c1);
+  __sync_synchronize();
+  return 0;
+}
+EOF
+
+    AC_MSG_CHECKING([for atomic builtins for short])
+    if AC_TRY_EVAL(ac_compile); then
+      if grep __sync_ conftest.s >/dev/null 2>&1 ; then
+        enable_atomic_builtinss=no
+      else
+      AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_2, 1,
+      [Define if builtin atomic operations for short are supported on this host.])
+        enable_atomic_builtinss=yes
+      fi
+    fi
+    AC_MSG_RESULT($enable_atomic_builtinss)
+    rm -f conftest*
+
+    cat > conftest.$ac_ext << EOF
+[#]line __oline__ "configure"
+int main()
+{
+  // NB: _Atomic_word not necessarily int. 
+  typedef int atomic_type;
+  atomic_type c1;
+  atomic_type c2;
+  const atomic_type c3(0);
+  __sync_fetch_and_add(&c1, c2);
+  __sync_val_compare_and_swap(&c1, c3, c2);
+  __sync_lock_test_and_set(&c1, c3);
+  __sync_lock_release(&c1);
+  __sync_synchronize();
+  return 0;
+}
+EOF
+
+    AC_MSG_CHECKING([for atomic builtins for int])
+    if AC_TRY_EVAL(ac_compile); then
+      if grep __sync_ conftest.s >/dev/null 2>&1 ; then
+        enable_atomic_builtinsi=no
+      else
+      AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_4, 1,
+        [Define if builtin atomic operations for int are supported on this host.])
+        enable_atomic_builtinsi=yes
+      fi
+    fi
+    AC_MSG_RESULT($enable_atomic_builtinsi)
+    rm -f conftest*
+
+    cat > conftest.$ac_ext << EOF
+[#]line __oline__ "configure"
+int main()
+{
+  typedef long long atomic_type;
+  atomic_type c1;
+  atomic_type c2;
+  const atomic_type c3(0);
+  __sync_fetch_and_add(&c1, c2);
+  __sync_val_compare_and_swap(&c1, c3, c2);
+  __sync_lock_test_and_set(&c1, c3);
+  __sync_lock_release(&c1);
+  __sync_synchronize();
+  return 0;
+}
+EOF
+
+    AC_MSG_CHECKING([for atomic builtins for long long])
+    if AC_TRY_EVAL(ac_compile); then
+      if grep __sync_ conftest.s >/dev/null 2>&1 ; then
+        enable_atomic_builtinsll=no
+      else
+      AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS_8, 1,
+      [Define if builtin atomic operations for long long are supported on this host.])
+        enable_atomic_builtinsll=yes
+      fi
+    fi
+    AC_MSG_RESULT($enable_atomic_builtinsll)
+    rm -f conftest*
 
-  LIBMATH_INCLUDES='-I$(top_srcdir)/libmath'
 
-  LIBSUPCXX_INCLUDES='-I$(top_srcdir)/libsupc++'
+  CXXFLAGS="$old_CXXFLAGS"
+  AC_LANG_RESTORE
 
-  if test x"$need_libio" = xyes; then
-    LIBIO_INCLUDES='-I$(top_builddir)/libio -I$(top_srcdir)/libio'
-    AC_SUBST(LIBIO_INCLUDES)
+  # Set atomicity_dir to builtins if either of above tests pass.
+  if test $enable_atomic_builtinsi = yes || test $enable_atomic_builtinsb = yes ; then
+    atomicity_dir=cpu/generic/atomicity_builtins
+  fi
+
+  # If still generic, set to mutex.
+  if test $atomicity_dir = "cpu/generic" ; then
+    atomicity_dir=cpu/generic/atomicity_mutex
+    AC_MSG_WARN([No native atomic operations are provided for this platform.])
+      if test "x$target_thread_file" = xsingle; then
+        AC_MSG_WARN([They cannot be faked when thread support is disabled.])
+        AC_MSG_WARN([Thread-safety of certain classes is not guaranteed.])
+      else
+        AC_MSG_WARN([They will be faked using a mutex.])
+        AC_MSG_WARN([Performance of certain classes will degrade as a result.])
+      fi
   fi
 
-  # Now, export this to all the little Makefiles....
-  AC_SUBST(GLIBCPP_INCLUDES)
-  AC_SUBST(TOPLEVEL_INCLUDES)
-  AC_SUBST(LIBMATH_INCLUDES)
-  AC_SUBST(LIBSUPCXX_INCLUDES)
 ])
 
 
 dnl
-dnl Set up *_FLAGS and *FLAGS variables for all sundry Makefile.am's.
+dnl Check for exception handling support.  If an explicit enable/disable
+dnl sjlj exceptions is given, we don't have to detect.  Otherwise the
+dnl target may or may not support call frame exceptions.
 dnl
-AC_DEFUN(GLIBCPP_EXPORT_FLAGS, [
-  # Optimization flags that are probably a good idea for thrill-seekers. Just
-  # uncomment the lines below and make, everything else is ready to go... 
-  # OPTIMIZE_CXXFLAGS = -O3 -fstrict-aliasing -fvtable-gc 
-  OPTIMIZE_CXXFLAGS=
-  AC_SUBST(OPTIMIZE_CXXFLAGS)
+dnl --enable-sjlj-exceptions forces the use of builtin setjmp.
+dnl --disable-sjlj-exceptions forces the use of call frame unwinding.
+dnl Neither one forces an attempt at detection.
+dnl
+dnl Defines:
+dnl  _GLIBCXX_SJLJ_EXCEPTIONS if the compiler is configured for it
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_SJLJ_EXCEPTIONS], [
+  AC_MSG_CHECKING([for exception model to use])
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+  GLIBCXX_ENABLE(sjlj-exceptions,auto,,
+    [force use of builtin_setjmp for exceptions],
+    [permit yes|no|auto])
+
+  if test $enable_sjlj_exceptions = auto; then
+    # Botheration.  Now we've got to detect the exception model.  Link tests
+    # against libgcc.a are problematic since we've not been given proper -L
+    # bits for single-tree newlib and libgloss.
+    #
+    # Fake what AC_TRY_COMPILE does.  XXX Look at redoing this new-style.
+    cat > conftest.$ac_ext << EOF
+[#]line __oline__ "configure"
+struct S { ~S(); };
+void bar();
+void foo()
+{
+  S s;
+  bar();
+}
+EOF
+    old_CXXFLAGS="$CXXFLAGS"
+    CXXFLAGS=-S
+    if AC_TRY_EVAL(ac_compile); then
+      if grep _Unwind_SjLj_Resume conftest.s >/dev/null 2>&1 ; then
+        enable_sjlj_exceptions=yes
+      elif grep _Unwind_Resume conftest.s >/dev/null 2>&1 ; then
+        enable_sjlj_exceptions=no
+      elif grep __cxa_end_cleanup conftest.s >/dev/null 2>&1 ; then
+        enable_sjlj_exceptions=no
+      fi
+    fi
+    CXXFLAGS="$old_CXXFLAGS"
+    rm -f conftest*
+  fi
 
-  WARN_FLAGS='-Wall -Wno-format -W -Wwrite-strings -Winline'
-  AC_SUBST(WARN_FLAGS)
+  # This is a tad weird, for hysterical raisins.  We have to map
+  # enable/disable to two different models.
+  case $enable_sjlj_exceptions in
+    yes)
+      AC_DEFINE(_GLIBCXX_SJLJ_EXCEPTIONS, 1,
+        [Define if the compiler is configured for setjmp/longjmp exceptions.])
+      ac_exception_model_name=sjlj
+      ;;
+    no)
+      ac_exception_model_name="call frame"
+      ;;
+    *)
+      AC_MSG_ERROR([unable to detect exception model])
+      ;;
+  esac
+ AC_LANG_RESTORE
+ AC_MSG_RESULT($ac_exception_model_name)
 ])
 
+
 dnl
-dnl  GLIBCPP_EXPORT_INSTALL_INFO
-dnl  calculates gxx_install_dir
-dnl  exports glibcpp_toolexecdir
-dnl  exports glibcpp_toolexeclibdir
-dnl  exports glibcpp_prefixdir
+dnl Allow visibility attributes to be used on namespaces, objects, etc.
 dnl
-dnl Assumes cross_compiling bits already done, and with_cross_host in
-dnl particular
-dnl
-dnl GLIBCPP_EXPORT_INSTALL_INFO
-AC_DEFUN(GLIBCPP_EXPORT_INSTALL_INFO, [
-# Assumes glibcpp_builddir, glibcpp_srcdir are alreay set up and
-# exported correctly in GLIBCPP_CONFIGURE.
-glibcpp_toolexecdir=no
-glibcpp_toolexeclibdir=no
-glibcpp_prefixdir=${prefix}
-
-# Process the option --with-gxx-include-dir=<path to include-files directory>
-AC_MSG_CHECKING([for --with-gxx-include-dir])
-AC_ARG_WITH(gxx-include-dir,
-[  --with-gxx-include-dir  the installation directory for include files],
-[case "${withval}" in
-  yes)
-    AC_MSG_ERROR(Missing directory for --with-gxx-include-dir)
-    gxx_include_dir=no
-    ;;
-  no)
-    gxx_include_dir=no
-    ;;
-  *)
-    gxx_include_dir=${withval}
-    ;;
-esac], [gxx_include_dir=no])
-AC_MSG_RESULT($gxx_include_dir)
-
-# Process the option "--enable-version-specific-runtime-libs"
-AC_MSG_CHECKING([for --enable-version-specific-runtime-libs])
-AC_ARG_ENABLE(version-specific-runtime-libs,
-[  --enable-version-specific-runtime-libs    Specify that runtime libraries should be installed in a compiler-specific directory ],
-[case "$enableval" in
- yes) version_specific_libs=yes ;;
- no)  version_specific_libs=no ;;
- *)   AC_MSG_ERROR([Unknown argument to enable/disable version-specific libs]);;
- esac],
-version_specific_libs=no)dnl
-# Option set, now we can test it.
-AC_MSG_RESULT($version_specific_libs)
-
-# Default case for install directory for include files.
-if test $version_specific_libs = no && test $gxx_include_dir = no; then
-  gxx_include_dir='$(prefix)'/include/c++/${gcc_version}
-fi
+dnl --enable-visibility enables attempt to use visibility attributes.
+dnl --disable-visibility turns off all use of visibility attributes.
+dnl  +  Usage:  GLIBCXX_ENABLE_VISIBILITY[(DEFAULT)]
+dnl       Where DEFAULT is 'yes'.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_VISIBILITY], [
+GLIBCXX_ENABLE(visibility,$1,,[enables visibility safe usage])
 
-# Version-specific runtime libs processing.
-if test $version_specific_libs = yes; then
-  # Need the gcc compiler version to know where to install libraries
-  # and header files if --enable-version-specific-runtime-libs option
-  # is selected.
-  if test x"$gxx_include_dir" = x"no"; then
-    gxx_include_dir='$(libdir)/gcc-lib/$(target_alias)/'${gcc_version}/include/c++
+if test x$enable_visibility = xyes ; then
+  dnl all hail libgfortran
+  dnl Check whether the target supports hidden visibility.
+  AC_CACHE_CHECK([whether the target supports hidden visibility],
+                glibcxx_cv_have_attribute_visibility, [
+  save_CFLAGS="$CFLAGS"
+  CFLAGS="$CFLAGS -Werror"
+  AC_TRY_COMPILE([void __attribute__((visibility("hidden"))) foo(void) { }],
+                [], glibcxx_cv_have_attribute_visibility=yes,
+                glibcxx_cv_have_attribute_visibility=no)
+  CFLAGS="$save_CFLAGS"])
+  if test $glibcxx_cv_have_attribute_visibility = no; then
+    enable_visibility=no
   fi
-  glibcpp_toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
-  glibcpp_toolexeclibdir='$(toolexecdir)/'${gcc_version}'$(MULTISUBDIR)'
 fi
 
-# Calculate glibcpp_toolexecdir, glibcpp_toolexeclibdir
-# Install a library built with a cross compiler in tooldir, not libdir.
-if test x"$glibcpp_toolexecdir" = x"no"; then 
-  if test -n "$with_cross_host" &&
-     test x"$with_cross_host" != x"no"; then
-    glibcpp_toolexecdir='$(exec_prefix)/$(target_alias)'
-    glibcpp_toolexeclibdir='$(toolexecdir)/lib'
+GLIBCXX_CONDITIONAL(ENABLE_VISIBILITY, test $enable_visibility = yes)
+AC_MSG_NOTICE([visibility supported: $enable_visibility])
+])
+
+
+dnl
+dnl Add version tags to symbols in shared library (or not), additionally
+dnl marking other symbols as private/local (or not).
+dnl
+dnl --enable-symvers=style adds a version script to the linker call when
+dnl       creating the shared library.  The choice of version script is
+dnl       controlled by 'style'.
+dnl --disable-symvers does not.
+dnl  +  Usage:  GLIBCXX_ENABLE_SYMVERS[(DEFAULT)]
+dnl       Where DEFAULT is either 'yes' or 'no'.  Passing `yes' tries to
+dnl       choose a default style based on linker characteristics.  Passing
+dnl       'no' disables versioning.
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_SYMVERS], [
+
+GLIBCXX_ENABLE(symvers,$1,[=STYLE],
+  [enables symbol versioning of the shared library],
+  [permit yes|no|gnu|gnu-versioned-namespace|darwin|darwin-export])
+
+# If we never went through the GLIBCXX_CHECK_LINKER_FEATURES macro, then we
+# don't know enough about $LD to do tricks...
+AC_REQUIRE([GLIBCXX_CHECK_LINKER_FEATURES])
+
+# Turn a 'yes' into a suitable default.
+if test x$enable_symvers = xyes ; then
+  if test $enable_shared = no || test "x$LD" = x || test x$gcc_no_link = xyes; then
+    enable_symvers=no
   else
-    glibcpp_toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
-    glibcpp_toolexeclibdir='$(libdir)'
+    if test $with_gnu_ld = yes ; then
+      case ${target_os} in
+        cygwin* | pe | mingw32* | hpux*)
+          enable_symvers=no ;;
+        *)
+          enable_symvers=gnu ;;
+      esac
+    else
+      case ${target_os} in
+        darwin*)
+         enable_symvers=darwin ;;
+        *)
+          enable_symvers=no ;;
+      esac
+    fi
   fi
-  glibcpp_toolexeclibdir=$glibcpp_toolexeclibdir/`$CC -print-multi-os-directory`
 fi
 
-AC_MSG_CHECKING([for install location])
-AC_MSG_RESULT($gxx_include_dir)
-
-AC_SUBST(glibcpp_prefixdir)
-AC_SUBST(gxx_include_dir)
-AC_SUBST(glibcpp_toolexecdir)
-AC_SUBST(glibcpp_toolexeclibdir)
-])
+# Check to see if 'darwin' or 'darwin-export' can win.
+if test x$enable_symvers = xdarwin-export ; then
+    enable_symvers=darwin
+fi
 
+# Check to see if 'gnu' can win.
+if test $enable_symvers = gnu || test $enable_symvers = gnu-versioned-namespace; then
+  # Check to see if libgcc_s exists, indicating that shared libgcc is possible.
+  AC_MSG_CHECKING([for shared libgcc])
+  ac_save_CFLAGS="$CFLAGS"
+  CFLAGS=' -lgcc_s'
+  AC_TRY_LINK(, [return 0;], glibcxx_shared_libgcc=yes, glibcxx_shared_libgcc=no)
+  CFLAGS="$ac_save_CFLAGS"
+  if test $glibcxx_shared_libgcc = no; then
+    cat > conftest.c <<EOF
+int main (void) { return 0; }
+EOF
+changequote(,)dnl
+    glibcxx_libgcc_s_suffix=`${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS \
+                            -shared -shared-libgcc -o conftest.so \
+                            conftest.c -v 2>&1 >/dev/null \
+                            | sed -n 's/^.* -lgcc_s\([^ ]*\) .*$/\1/p'`
+changequote([,])dnl
+    rm -f conftest.c conftest.so
+    if test x${glibcxx_libgcc_s_suffix+set} = xset; then
+      CFLAGS=" -lgcc_s$glibcxx_libgcc_s_suffix"
+      AC_TRY_LINK(, [return 0;], glibcxx_shared_libgcc=yes)
+      CFLAGS="$ac_save_CFLAGS"
+    fi
+  fi
+  AC_MSG_RESULT($glibcxx_shared_libgcc)
 
-# Check for functions in math library.
-# Ulrich Drepper <drepper@cygnus.com>, 1998.
-#
-# This file can be copied and used freely without restrictions.  It can
-# be used in projects which are not available under the GNU Public License
-# but which still want to provide support for the GNU gettext functionality.
-# Please note that the actual code is *not* freely available.
+  # For GNU ld, we need at least this version.  The format is described in
+  # GLIBCXX_CHECK_LINKER_FEATURES above.
+  glibcxx_min_gnu_ld_version=21400
 
-# serial 1
-
-dnl AC_REPLACE_MATHFUNCS(FUNCTION...)
-AC_DEFUN(AC_REPLACE_MATHFUNCS,
-[AC_CHECK_FUNCS([$1], , [LIBMATHOBJS="$LIBMATHOBJS ${ac_func}.lo"])])
-
-
-dnl This macro searches for a GNU version of make.  If a match is found, the
-dnl makefile variable `ifGNUmake' is set to the empty string, otherwise it is
-dnl set to "#". This is useful for  including a special features in a Makefile,
-dnl which cannot be handled by other versions of make.  The variable
-dnl _cv_gnu_make_command is set to the command to invoke GNU make if it exists,
-dnl the empty string otherwise.
-dnl
-dnl Here is an example of its use:
-dnl
-dnl Makefile.in might contain:
-dnl
-dnl     # A failsafe way of putting a dependency rule into a makefile
-dnl     $(DEPEND):
-dnl             $(CC) -MM $(srcdir)/*.c > $(DEPEND)
-dnl
-dnl     @ifGNUmake@ ifeq ($(DEPEND),$(wildcard $(DEPEND)))
-dnl     @ifGNUmake@ include $(DEPEND)
-dnl     @ifGNUmake@ endif
-dnl
-dnl Then configure.in would normally contain:
-dnl
-dnl     CHECK_GNU_MAKE()
-dnl     AC_OUTPUT(Makefile)
-dnl
-dnl Then perhaps to cause gnu make to override any other make, we could do
-dnl something like this (note that GNU make always looks for GNUmakefile first):
-dnl
-dnl     if  ! test x$_cv_gnu_make_command = x ; then
-dnl             mv Makefile GNUmakefile
-dnl             echo .DEFAULT: > Makefile ;
-dnl             echo \  $_cv_gnu_make_command \$@ >> Makefile;
-dnl     fi
-dnl
-dnl Then, if any (well almost any) other make is called, and GNU make also
-dnl exists, then the other make wraps the GNU make.
-dnl
-dnl @author John Darrington <j.darrington@elvis.murdoch.edu.au>
-dnl @version 1.1 #### replaced Id string now that Id is for lib-v3; pme
-dnl
-dnl #### Changes for libstdc++-v3:  reformatting and linewrapping; prepending
-dnl #### GLIBCPP_ to the macro name; adding the :-make fallback in the
-dnl #### conditional's subshell (" --version" is not a command), using a
-dnl #### different option to grep(1).
-dnl #### -pme
-dnl #### Fixed Bourne shell portability bug (use ${MAKE-make}, not
-dnl #### ${MAKE:-make}).
-dnl #### -msokolov
-AC_DEFUN(
-  GLIBCPP_CHECK_GNU_MAKE, [AC_CACHE_CHECK( for GNU make,_cv_gnu_make_command,
-          _cv_gnu_make_command='' ;
-dnl Search all the common names for GNU make
-          for a in "${MAKE-make}" make gmake gnumake ; do
-                  if ( $a --version 2> /dev/null | grep -c GNU > /dev/null )
-                  then
-                          _cv_gnu_make_command=$a ;
-                          break;
-                  fi
-          done ;
-  ) ;
-dnl If there was a GNU version, then set @ifGNUmake@ to the empty
-dnl string, '#' otherwise
-  if test  "x$_cv_gnu_make_command" != "x"  ; then
-          ifGNUmake='' ;
-  else
-          ifGNUmake='#' ;
+  # If no shared libgcc, can't win.
+  if test $glibcxx_shared_libgcc != yes; then
+      AC_MSG_WARN([=== You have requested GNU symbol versioning, but])
+      AC_MSG_WARN([=== you are not building a shared libgcc_s.])
+      AC_MSG_WARN([=== Symbol versioning will be disabled.])
+      enable_symvers=no
+  elif test $with_gnu_ld != yes ; then
+    # just fail for now
+    AC_MSG_WARN([=== You have requested GNU symbol versioning, but])
+    AC_MSG_WARN([=== you are not using the GNU linker.])
+    AC_MSG_WARN([=== Symbol versioning will be disabled.])
+    enable_symvers=no
+  elif test $glibcxx_ld_is_gold = yes ; then
+    : All versions of gold support symbol versioning.
+  elif test $glibcxx_gnu_ld_version -lt $glibcxx_min_gnu_ld_version ; then
+    # The right tools, the right setup, but too old.  Fallbacks?
+    AC_MSG_WARN(=== Linker version $glibcxx_gnu_ld_version is too old for)
+    AC_MSG_WARN(=== full symbol versioning support in this release of GCC.)
+    AC_MSG_WARN(=== You would need to upgrade your binutils to version)
+    AC_MSG_WARN(=== $glibcxx_min_gnu_ld_version or later and rebuild GCC.)
+    AC_MSG_WARN([=== Symbol versioning will be disabled.])
+    enable_symvers=no
   fi
-  AC_SUBST(ifGNUmake)
-])
+fi
 
+# Everything parsed; figure out what file to use.
+case $enable_symvers in
+  no)
+    SYMVER_FILE=config/abi/pre/none.ver
+    ;;
+  gnu)
+    SYMVER_FILE=config/abi/pre/gnu.ver
+    AC_DEFINE(_GLIBCXX_SYMVER_GNU, 1, 
+              [Define to use GNU versioning in the shared library.])
+    ;;
+  gnu-versioned-namespace)
+    SYMVER_FILE=config/abi/pre/gnu-versioned-namespace.ver
+    AC_DEFINE(_GLIBCXX_SYMVER_GNU_NAMESPACE, 1, 
+              [Define to use GNU namespace versioning in the shared library.])
+    ;;
+  darwin)
+    SYMVER_FILE=config/abi/pre/gnu.ver
+    AC_DEFINE(_GLIBCXX_SYMVER_DARWIN, 1, 
+              [Define to use darwin versioning in the shared library.])
+    ;;
+esac
 
-dnl Check for headers for, and arguments to, the setrlimit() function.
-dnl Used only in testsuite_hooks.h.
-AC_DEFUN(GLIBCPP_CHECK_SETRLIMIT_ancilliary, [
-  AC_TRY_COMPILE([#include <sys/resource.h>
-                  #include <unistd.h>
-                 ], [ int f = RLIMIT_$1 ; ],
-                 [glibcpp_mresult=1], [glibcpp_mresult=0])
-  AC_DEFINE_UNQUOTED(HAVE_MEMLIMIT_$1, $glibcpp_mresult,
-                     [Only used in build directory testsuite_hooks.h.])
+if test x$enable_symvers != xno ; then
+  AC_DEFINE(_GLIBCXX_SYMVER, 1,
+        [Define to use symbol versioning in the shared library.])
+fi
+
+AC_CACHE_CHECK([whether the target supports .symver directive],
+              glibcxx_cv_have_as_symver_directive, [
+  AC_TRY_COMPILE([void foo (void); __asm (".symver foo, bar@SYMVER");],
+                [], glibcxx_cv_have_as_symver_directive=yes,
+                glibcxx_cv_have_as_symver_directive=no)])
+if test $glibcxx_cv_have_as_symver_directive = yes; then
+  AC_DEFINE(HAVE_AS_SYMVER_DIRECTIVE, 1,
+    [Define to 1 if the target assembler supports .symver directive.])
+fi
+
+AC_SUBST(SYMVER_FILE)
+AC_SUBST(port_specific_symbol_files)
+GLIBCXX_CONDITIONAL(ENABLE_SYMVERS, test $enable_symvers != no)
+GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_GNU, test $enable_symvers = gnu)
+GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_GNU_NAMESPACE, test $enable_symvers = gnu-versioned-namespace)
+GLIBCXX_CONDITIONAL(ENABLE_SYMVERS_DARWIN, test $enable_symvers = darwin)
+AC_MSG_NOTICE(versioning on shared library symbols is $enable_symvers)
+
+# Now, set up compatibility support, if any.
+# In addition, need this to deal with std::size_t mangling in
+# src/compatibility.cc.  In a perfect world, could use
+# typeid(std::size_t).name()[0] to do direct substitution.
+AC_MSG_CHECKING([for size_t as unsigned int])
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS="-Werror"
+AC_TRY_COMPILE(, [__SIZE_TYPE__* stp; unsigned int* uip; stp = uip;], 
+                [glibcxx_size_t_is_i=yes], [glibcxx_size_t_is_i=no])
+CFLAGS=$ac_save_CFLAGS
+if test "$glibcxx_size_t_is_i" = yes; then
+  AC_DEFINE(_GLIBCXX_SIZE_T_IS_UINT, 1, [Define if size_t is unsigned int.])
+fi
+AC_MSG_RESULT([$glibcxx_size_t_is_i])
+
+AC_MSG_CHECKING([for ptrdiff_t as int])
+ac_save_CFLAGS="$CFLAGS"
+CFLAGS="-Werror"
+AC_TRY_COMPILE(, [__PTRDIFF_TYPE__* ptp; int* ip; ptp = ip;], 
+                [glibcxx_ptrdiff_t_is_i=yes], [glibcxx_ptrdiff_t_is_i=no])
+CFLAGS=$ac_save_CFLAGS
+if test "$glibcxx_ptrdiff_t_is_i" = yes; then
+  AC_DEFINE(_GLIBCXX_PTRDIFF_T_IS_INT, 1, [Define if ptrdiff_t is int.])
+fi
+AC_MSG_RESULT([$glibcxx_ptrdiff_t_is_i])
 ])
-AC_DEFUN(GLIBCPP_CHECK_SETRLIMIT, [
-  setrlimit_have_headers=yes
-  AC_CHECK_HEADERS(sys/resource.h unistd.h,
-                   [],
-                   setrlimit_have_headers=no)
-  # If don't have the headers, then we can't run the tests now, and we
-  # won't be seeing any of these during testsuite compilation.
-  if test $setrlimit_have_headers = yes; then
-    # Can't do these in a loop, else the resulting syntax is wrong.
-    GLIBCPP_CHECK_SETRLIMIT_ancilliary(DATA)
-    GLIBCPP_CHECK_SETRLIMIT_ancilliary(RSS)
-    GLIBCPP_CHECK_SETRLIMIT_ancilliary(VMEM)
-    GLIBCPP_CHECK_SETRLIMIT_ancilliary(AS)
 
-    # Check for rlimit, setrlimit.
-    AC_CACHE_VAL(ac_setrlimit, [
-      AC_TRY_COMPILE([#include <sys/resource.h>
-                     #include <unistd.h>
-                    ], 
-                     [ struct rlimit r; setrlimit(0, &r);], 
-                     [ac_setrlimit=yes], [ac_setrlimit=no])
-    ])
+
+dnl
+dnl Setup to use the gcc gthr.h thread-specific memory and mutex model.
+dnl We must stage the required headers so that they will be installed
+dnl with the library (unlike libgcc, the STL implementation is provided
+dnl solely within headers).  Since we must not inject random user-space
+dnl macro names into user-provided C++ code, we first stage into <file>-in
+dnl and process to <file> with an output command.  The reason for a two-
+dnl stage process here is to correctly handle $srcdir!=$objdir without
+dnl having to write complex code (the sed commands to clean the macro
+dnl namespace are complex and fragile enough as it is).  We must also
+dnl add a relative path so that -I- is supported properly.
+dnl
+dnl Substs:
+dnl  glibcxx_thread_h
+dnl
+dnl Defines:
+dnl  HAVE_GTHR_DEFAULT
+dnl
+AC_DEFUN([GLIBCXX_ENABLE_THREADS], [
+  AC_MSG_CHECKING([for thread model used by GCC])
+  target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
+  AC_MSG_RESULT([$target_thread_file])
+
+  if test $target_thread_file != single; then
+    AC_DEFINE(HAVE_GTHR_DEFAULT, 1,
+              [Define if gthr-default.h exists 
+              (meaning that threading support is enabled).])
   fi
 
-  AC_MSG_CHECKING([for testsuite memory limit support])
-  if test $setrlimit_have_headers = yes && test $ac_setrlimit = yes; then
-    ac_mem_limits=yes
-    AC_DEFINE(_GLIBCPP_MEM_LIMITS)
+  glibcxx_thread_h=gthr-$target_thread_file.h
+
+  dnl Check for __GTHREADS define.
+  gthread_file=${toplevel_srcdir}/gcc/${glibcxx_thread_h}
+  if grep __GTHREADS $gthread_file >/dev/null 2>&1 ; then
+    enable_thread=yes
   else
-    ac_mem_limits=no
+   enable_thread=no
   fi
-  AC_MSG_RESULT($ac_mem_limits)
+
+  AC_SUBST(glibcxx_thread_h)
 ])
 
 
 dnl
-dnl Does any necessary configuration of the testsuite directory.  Generates
-dnl the testsuite_hooks.h header.
+dnl Check if gthread implementation defines the types and functions
+dnl required by the c++0x thread library.  Conforming gthread
+dnl implementations can define __GTHREADS_CXX0X to enable use with c++0x.
 dnl
-dnl GLIBCPP_CONFIGURE_TESTSUITE  [no args]
-AC_DEFUN(GLIBCPP_CONFIGURE_TESTSUITE, [
-  GLIBCPP_CHECK_SETRLIMIT
+AC_DEFUN([GLIBCXX_CHECK_GTHREADS], [
+  AC_LANG_SAVE
+  AC_LANG_CPLUSPLUS
+
+  ac_save_CXXFLAGS="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAGS -fno-exceptions -I${toplevel_srcdir}/gcc"
 
-  # Look for setenv, so that extended locale tests can be performed.
-  GLIBCPP_CHECK_STDLIB_DECL_AND_LINKAGE_3(setenv)
+  target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'`
+  case $target_thread_file in
+    posix)
+      CXXFLAGS="$CXXFLAGS -DSUPPORTS_WEAK -DGTHREAD_USE_WEAK -D_PTHREADS"
+  esac
 
-  # Export file names for ABI checking.
-  baseline_file="${glibcpp_srcdir}/config/abi/${abi_baseline_triplet}/baseline_symbols.txt"
-  AC_SUBST(baseline_file)
+  AC_MSG_CHECKING([for gthreads library])
 
-  # Don't do ABI checking unless native.
-  AM_CONDITIONAL(GLIBCPP_BUILD_ABI_CHECK,
-                 test x"$build" = x"$host" && test -z "$with_cross_host")
-])
+  AC_TRY_COMPILE([#include "gthr.h"],
+    [
+      #ifndef __GTHREADS_CXX0X
+      #error
+      #endif
+
+      // In case of POSIX threads check _POSIX_TIMEOUTS too.
+      #if (defined(_PTHREADS) \
+           && (!defined(_POSIX_TIMEOUTS) || _POSIX_TIMEOUTS <= 0))
+      #error
+      #endif
+    ], [ac_has_gthreads=yes], [ac_has_gthreads=no])
 
+  AC_MSG_RESULT([$ac_has_gthreads])
 
-sinclude(../libtool.m4)
-dnl The lines below arrange for aclocal not to bring an installed
-dnl libtool.m4 into aclocal.m4, while still arranging for automake to
-dnl add a definition of LIBTOOL to Makefile.in.
-ifelse(,,,[AC_SUBST(LIBTOOL)
-AC_DEFUN([AM_PROG_LIBTOOL])
-AC_DEFUN([AC_LIBTOOL_DLOPEN])
-AC_DEFUN([AC_PROG_LD])
+  if test x"$ac_has_gthreads" = x"yes"; then
+    AC_DEFINE(_GLIBCXX_HAS_GTHREADS, 1,
+              [Define if gthreads library is available.])
+  fi
+
+  CXXFLAGS="$ac_save_CXXFLAGS"
+  AC_LANG_RESTORE
 ])
 
 
@@ -2122,143 +2973,18 @@ AC_DEFUN([AC_PROG_LD])
 # be used in projects which are not available under the GNU Public License
 # but which still want to provide support for the GNU gettext functionality.
 # Please note that the actual code is *not* freely available.
-
-# serial 1
-
-AC_DEFUN(AC_LC_MESSAGES, [
+AC_DEFUN([AC_LC_MESSAGES], [
   AC_CHECK_HEADER(locale.h, [
     AC_CACHE_CHECK([for LC_MESSAGES], ac_cv_val_LC_MESSAGES,
-      [AC_TRY_LINK([#include <locale.h>], [return LC_MESSAGES],
+      [AC_TRY_COMPILE([#include <locale.h>], [return LC_MESSAGES],
        ac_cv_val_LC_MESSAGES=yes, ac_cv_val_LC_MESSAGES=no)])
     if test $ac_cv_val_LC_MESSAGES = yes; then
-      AC_DEFINE(HAVE_LC_MESSAGES)
+      AC_DEFINE(HAVE_LC_MESSAGES, 1, 
+                [Define if LC_MESSAGES is available in <locale.h>.])
     fi
   ])
 ])
 
-
-dnl
-dnl Check for whether the Boost-derived checks should be turned on.
-dnl
-dnl GLIBCPP_ENABLE_CONCEPT_CHECKS
-dnl --enable-concept-checks turns them on.
-dnl --disable-concept-checks leaves them off.
-dnl  +  Usage:  GLIBCPP_ENABLE_CONCEPT_CHECKS[(DEFAULT)]
-dnl       Where DEFAULT is either `yes' or `no'.  If ommitted, it
-dnl       defaults to `no'.
-AC_DEFUN(GLIBCPP_ENABLE_CONCEPT_CHECKS, [dnl
-define([GLIBCPP_ENABLE_CONCEPT_CHECKS_DEFAULT], ifelse($1, yes, yes, no))dnl
-AC_ARG_ENABLE(concept-checks,
-changequote(<<, >>)dnl
-<<  --enable-concept-checks use Boost-derived template checks [default=>>GLIBCPP_ENABLE_CONCEPT_CHECKS_DEFAULT],
-changequote([, ])dnl
-[case "$enableval" in
- yes) enable_concept_checks=yes ;;
- no)  enable_concept_checks=no ;;
- *)   AC_MSG_ERROR([Unknown argument to enable/disable concept checks]) ;;
- esac],
-enable_concept_checks=GLIBCPP_ENABLE_CONCEPT_CHECKS_DEFAULT)dnl
-dnl Option parsed, now set things appropriately
-if test x"$enable_concept_checks" = xyes; then
-  AC_DEFINE(_GLIBCPP_CONCEPT_CHECKS)
-fi
-])
-
-
-dnl
-dnl Add version tags to symbols in shared library (or not), additionally
-dnl marking other symbols as private/local (or not).
-dnl
-dnl GLIBCPP_ENABLE_SYMVERS
-dnl --enable-symvers=style adds a version script to the linker call when
-dnl       creating the shared library.  The choice of version script is
-dnl       controlled by 'style'.
-dnl --disable-symvers does not.
-dnl  +  Usage:  GLIBCPP_ENABLE_SYMVERS[(DEFAULT)]
-dnl       Where DEFAULT is either `yes' or `no'.  If ommitted, it
-dnl       defaults to `no'.  Passing `yes' tries to choose a default style
-dnl       based on linker characteristics.  Passing 'no' disables versioning.
-AC_DEFUN(GLIBCPP_ENABLE_SYMVERS, [dnl
-define([GLIBCPP_ENABLE_SYMVERS_DEFAULT], ifelse($1, yes, yes, no))dnl
-AC_ARG_ENABLE(symvers,
-changequote(<<, >>)dnl
-<<  --enable-symvers=style  enables symbol versioning of the shared library [default=>>GLIBCPP_ENABLE_SYMVERS_DEFAULT],
-changequote([, ])dnl
-[case "$enableval" in
- yes) enable_symvers=yes ;;
- no)  enable_symvers=no ;;
- # other names here, just as sanity checks
- #gnu|sun|etcetera) enable_symvers=$enableval ;;
- gnu) enable_symvers=$enableval ;;
- *)   AC_MSG_ERROR([Unknown argument to enable/disable symvers]) ;;
- esac],
-enable_symvers=GLIBCPP_ENABLE_SYMVERS_DEFAULT)dnl
-
-# If we never went through the GLIBCPP_CHECK_LINKER_FEATURES macro, then we
-# don't know enough about $LD to do tricks... 
-if test x$enable_shared = xno || 
-       test "x$LD" = x || 
-       test x$glibcpp_gnu_ld_version = x; then
-  enable_symvers=no
-fi
-
-# Check to see if libgcc_s exists, indicating that shared libgcc is possible.
-AC_MSG_CHECKING([for shared libgcc])
-ac_save_CFLAGS="$CFLAGS"
-CFLAGS=' -lgcc_s'
-AC_TRY_LINK( , [return 0], glibcpp_shared_libgcc=yes, glibcpp_shared_libgcc=no)
-CFLAGS="$ac_save_CFLAGS"
-AC_MSG_RESULT($glibcpp_shared_libgcc)
-
-# For GNU ld, we need at least this version.  It's 2.12 in the same format
-# as the tested-for version.  See GLIBCPP_CHECK_LINKER_FEATURES for more.
-glibcpp_min_gnu_ld_version=21200
-
-# Check to see if unspecified "yes" value can win, given results
-# above.  
-if test $enable_symvers = yes ; then
-  if test $with_gnu_ld = yes &&
-    test $glibcpp_shared_libgcc = yes ;
-  then
-    if test $glibcpp_gnu_ld_version -ge $glibcpp_min_gnu_ld_version ; then
-        enable_symvers=gnu
-    else
-      ac_test_CFLAGS="${CFLAGS+set}"
-      ac_save_CFLAGS="$CFLAGS"
-      CFLAGS='-shared -Wl,--version-script,conftest.map'
-      enable_symvers=no
-      changequote(,)
-      echo 'FOO { global: f[a-z]o; local: *; };' > conftest.map
-      changequote([,])
-      AC_TRY_LINK([int foo;],, enable_symvers=gnu)
-      if test "$ac_test_CFLAGS" = set; then
-       CFLAGS="$ac_save_CFLAGS"
-      else
-       # this is the suspicious part
-       CFLAGS=''
-      fi
-      rm -f conftest.map
-    fi
-  else
-    # just fail for now
-    enable_symvers=no
-  fi
-fi
-
-dnl Everything parsed; figure out what file to use.
-case $enable_symvers in
-  no)
-      LINKER_MAP=config/linker-map.dummy
-      ;;
-  gnu)
-      LINKER_MAP=config/linker-map.gnu
-      AC_DEFINE(_GLIBCPP_SYMVER)       
-      ;;
-esac
-
-AC_LINK_FILES($LINKER_MAP, src/linker.map)
-AM_CONDITIONAL(GLIBCPP_BUILD_VERSIONED_SHLIB, test $enable_symvers != no)
-AC_MSG_CHECKING([versioning on shared library symbols])
-AC_MSG_RESULT($enable_symvers)
-])
+# Macros from the top-level gcc directory.
+m4_include([../config/tls.m4])