diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
index ec32980aa0d..6d51c5f6a11 100644
--- a/libstdc++-v3/configure.host
+++ b/libstdc++-v3/configure.host
@@ -56,9 +56,6 @@
 #   cpu_opt_ext_random     path name of random.h containing CPU-specific
 #                          optimizations for extensions
 #
-#   error_constants_dir    location of error_constants.h
-#                          defaults to os/generic.
-#
 # It possibly modifies the following variables:
 #
 #   OPT_LDFLAGS            extra flags to pass when linking the library, of
@@ -93,7 +90,6 @@ cpu_defines_dir="cpu/generic"
 try_cpu=generic
 abi_baseline_subdir_switch=--print-multi-directory
 abi_tweaks_dir="cpu/generic"
-error_constants_dir="os/generic"
 tmake_file=
 
 # HOST-SPECIFIC OVERRIDES
@@ -247,7 +243,6 @@ case "${host_os}" in
     ;;
   *djgpp*)      # leading * picks up "msdosdjgpp"
     os_include_dir="os/djgpp"
-    error_constants_dir="os/djgpp"
     ;;
   dragonfly*)
     os_include_dir="os/bsd/dragonfly"
@@ -274,11 +269,9 @@ case "${host_os}" in
     case "$host" in
       *-w64-*)
         os_include_dir="os/mingw32-w64"
-        error_constants_dir="os/mingw32-w64"
         ;;
       *)
         os_include_dir="os/mingw32"
-        error_constants_dir="os/mingw32"
         ;;
     esac
     OPT_LDFLAGS="${OPT_LDFLAGS} \$(lt_host_flags)"
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 97542524a69..28c5b3c4453 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -1033,7 +1033,6 @@ host_headers = \
 	${glibcxx_srcdir}/$(ATOMIC_WORD_SRCDIR)/atomic_word.h \
 	${glibcxx_srcdir}/$(ABI_TWEAKS_SRCDIR)/cxxabi_tweaks.h \
 	${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h \
-	${glibcxx_srcdir}/$(ERROR_CONSTANTS_SRCDIR)/error_constants.h \
 	${glibcxx_srcdir}/include/precompiled/stdc++.h \
 	${glibcxx_srcdir}/include/precompiled/stdtr1c++.h \
 	${glibcxx_srcdir}/include/precompiled/extc++.h
@@ -1051,6 +1050,7 @@ host_headers_extra = \
 	${host_builddir}/c++allocator.h \
 	${host_builddir}/c++io.h \
 	${host_builddir}/c++locale.h \
+	${host_builddir}/error_constants.h \
 	${host_builddir}/messages_members.h \
 	${host_builddir}/time_members.h
 
@@ -1106,6 +1106,7 @@ allstamped = \
 # catenation.
 allcreated = \
 	${host_builddir}/c++config.h \
+	${host_builddir}/error_constants.h \
 	${host_builddir}/largefile-config.h \
 	${thread_host_headers} \
 	${pch_build}
@@ -1404,6 +1405,9 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \
 	echo "" >> $@ ;\
 	echo "#endif // _GLIBCXX_CXX_CONFIG_H" >> $@
 
+${host_builddir}/error_constants.h: ${glibcxx_srcdir}/scripts/make_errc.sh
+	${glibcxx_srcdir}/scripts/make_errc.sh $@ "${CXXCPP}" ${AM_CPPFLAGS}
+
 # Host includes for threads
 uppercase = [ABCDEFGHIJKLMNOPQRSTUVWXYZ_]
 
diff --git a/libstdc++-v3/scripts/make_errc.sh b/libstdc++-v3/scripts/make_errc.sh
new file mode 100755
index 00000000000..10cdfb1b3d4
--- /dev/null
+++ b/libstdc++-v3/scripts/make_errc.sh
@@ -0,0 +1,168 @@
+#!/bin/sh
+
+[ -z "$1" ] && exit 1
+target=$1
+shift
+CXXCPP="$@"
+
+{
+  dir=`(umask 077 && mktemp -d "$target.XXXXXX") 2>/dev/null` &&
+  test -d "$dir"
+} || {
+  dir=$target.$RANDOM$$
+  (umask 077 && mkdir "$dir")
+} || exit $?
+
+output_h=$dir/output.h
+constants_h=$dir/constants.h
+
+cat > "$output_h" << EOT
+// Definition of std::errc enumeration type  -*- C++ -*-
+
+// Copyright The GNU Toolchain Authors.
+//
+// This file is part of the GNU ISO C++ Library.  This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file bits/errc.h
+ *  This is an internal header file, included by other library headers.
+ *  Do not attempt to use it directly. @headername{system_error}
+ */
+
+// This is a generated file. Do not edit directly.
+
+#ifndef _GLIBCXX_ERRC_H
+#define _GLIBCXX_ERRC_H 1
+
+#if __cplusplus >= 201103L
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+  enum class errc
+    {
+EOT
+
+cat > "$constants_h" <<EOT
+#if __has_include (<errno.h>)
+#include <errno.h>
+#endif
+#include <bits/c++config.h>
+#ifndef _GLIBCXX_ERRC_ORIGIN
+# define _GLIBCXX_ERRC_ORIGIN 9999
+#endif
+GLIBCXX ERROR CONSTANTS BELOW HERE
+line _GLIBCXX_ERRC_ORIGIN
+      address_family_not_supported = EAFNOSUPPORT,
+      address_in_use = EADDRINUSE,
+      address_not_available = EADDRNOTAVAIL,
+      already_connected = EISCONN,
+      argument_out_of_domain = EDOM,
+      bad_address = EFAULT,
+      bad_file_descriptor = EBADF,
+      bad_message = EBADMSG,
+      broken_pipe = EPIPE,
+      connection_aborted = ECONNABORTED,
+      connection_already_in_progress = EALREADY,
+      connection_refused = ECONNREFUSED,
+      connection_reset = ECONNRESET,
+      cross_device_link = EXDEV,
+      destination_address_required = EDESTADDRREQ,
+      device_or_resource_busy = EBUSY,
+      directory_not_empty = ENOTEMPTY,
+      executable_format_error = ENOEXEC,
+      file_exists = EEXIST,
+      file_too_large = EFBIG,
+      filename_too_long = ENAMETOOLONG,
+      function_not_supported = ENOSYS,
+      host_unreachable = EHOSTUNREACH,
+      identifier_removed = EIDRM,
+      illegal_byte_sequence = EILSEQ,
+      inappropriate_io_control_operation = ENOTTY,
+      interrupted = EINTR,
+      invalid_argument = EINVAL,
+      invalid_seek = ESPIPE,
+      io_error = EIO,
+      is_a_directory = EISDIR,
+      message_size = EMSGSIZE,
+      network_down = ENETDOWN,
+      network_reset = ENETRESET,
+      network_unreachable = ENETUNREACH,
+      no_buffer_space = ENOBUFS,
+      no_child_process = ECHILD,
+      no_link = ENOLINK,
+      no_lock_available = ENOLCK,
+      no_message_available = ENODATA,
+      no_message = ENOMSG,
+      no_protocol_option = ENOPROTOOPT,
+      no_space_on_device = ENOSPC,
+      no_stream_resources = ENOSR,
+      no_such_device_or_address = ENXIO,
+      no_such_device = ENODEV,
+      no_such_file_or_directory = ENOENT,
+      no_such_process = ESRCH,
+      not_a_directory = ENOTDIR,
+      not_a_socket = ENOTSOCK,
+      not_a_stream = ENOSTR,
+      not_connected = ENOTCONN,
+      not_enough_memory = ENOMEM,
+      not_supported = ENOTSUP,
+      operation_canceled = ECANCELED,
+      operation_in_progress = EINPROGRESS,
+      operation_not_permitted = EPERM,
+      operation_not_supported = EOPNOTSUPP,
+      operation_would_block = EWOULDBLOCK,
+      owner_dead = EOWNERDEAD,
+      permission_denied = EACCES,
+      protocol_error = EPROTO,
+      protocol_not_supported = EPROTONOSUPPORT,
+      read_only_file_system = EROFS,
+      resource_deadlock_would_occur = EDEADLK,
+      resource_unavailable_try_again = EAGAIN,
+      result_out_of_range = ERANGE,
+      state_not_recoverable = ENOTRECOVERABLE,
+      stream_timeout = ETIME,
+      text_file_busy = ETXTBSY,
+      timed_out = ETIMEDOUT,
+      too_many_files_open_in_system = ENFILE,
+      too_many_files_open = EMFILE,
+      too_many_links = EMLINK,
+      too_many_symbolic_link_levels = ELOOP,
+      value_too_large = EOVERFLOW,
+      wrong_protocol_type = EPROTOTYPE,
+EOT
+
+${CXXCPP} -P -D_POSIX_C_SOURCE=200809L -x c++ "$constants_h" \
+  | sed -e '1,/^GLIBCXX ERROR CONSTANTS BELOW HERE$/d' \
+	-e 's/^line [[:digit:]]*$/#&/' \
+	-e 's/ = E.*,/ = __LINE__,/' \
+  | ${CXXCPP} -P -x c++ - \
+  >> "$output_h" || exit $?
+
+cat >> "$output_h" << EOT
+    };
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+#endif // C++11
+#endif // _GLIBCXX_ERRC_H
+EOT
+
+mv "$output_h" "$target"
+rm -r $dir
