From 48c99156898ee7b5b1c5ee8b87c06df74787ebce Mon Sep 17 00:00:00 2001
From: Chris Johns <chrisj@rtems.org>
Date: Fri, 30 May 2025 16:14:02 -0500
Subject: [PATCH v1] libstdc++-v3: Enable features for RTEMS (based on GCC 15)

libstdc++-v3/ChangeLog:

	* configure: Regenerate.
	* configure.ac (newlib, *-rtems*): Add HAVE_SYS_IOCTL_H,
	HAVE_SYS_STAT_H, HAVE_SYS_TYPES_H, HAVE_S_ISREG, HAVE_UNISTD_H,
	HAVE_UNLINKAT, _GLIBCXX_USE_CHMOD, _GLIBCXX_USE_MKDIR,
        _GLIBCXX_USE_CHDIR, _GLIBCXX_USE_GETCWD, _GLIBCXX_USE_UTIME,
        _GLIBCXX_USE_LINK, _GLIBCXX_USE_READLINK, _GLIBCXX_USE_SYMLINK,
        _GLIBCXX_USE_TRUNCATE and _GLIBCXX_USE_FDOPENDIR.
---
 libstdc++-v3/configure    | 72 ++++++++++++++++++++++++++++++++++-----
 libstdc++-v3/configure.ac | 21 ++++++++++++
 2 files changed, 84 insertions(+), 9 deletions(-)

diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
index 819a1d82876..abf568cde14 100755
--- a/libstdc++-v3/configure
+++ b/libstdc++-v3/configure
@@ -893,6 +893,7 @@ infodir
 docdir
 oldincludedir
 includedir
+runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -1027,6 +1028,7 @@ datadir='${datarootdir}'
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1279,6 +1281,15 @@ do
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+    ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+    runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1416,7 +1427,7 @@ fi
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir
+		libdir localedir mandir runstatedir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1569,6 +1580,7 @@ Fine tuning of the installation directories:
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -12280,7 +12292,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12283 "configure"
+#line 12295 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12386,7 +12398,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12389 "configure"
+#line 12401 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16182,7 +16194,7 @@ $as_echo "$glibcxx_cv_atomic_long_long" >&6; }
   # Fake what AC_TRY_COMPILE does.
 
     cat > conftest.$ac_ext << EOF
-#line 16185 "configure"
+#line 16197 "configure"
 int main()
 {
   typedef bool atomic_type;
@@ -16217,7 +16229,7 @@ $as_echo "$glibcxx_cv_atomic_bool" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 16220 "configure"
+#line 16232 "configure"
 int main()
 {
   typedef short atomic_type;
@@ -16252,7 +16264,7 @@ $as_echo "$glibcxx_cv_atomic_short" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 16255 "configure"
+#line 16267 "configure"
 int main()
 {
   // NB: _Atomic_word not necessarily int.
@@ -16288,7 +16300,7 @@ $as_echo "$glibcxx_cv_atomic_int" >&6; }
     rm -f conftest*
 
     cat > conftest.$ac_ext << EOF
-#line 16291 "configure"
+#line 16303 "configure"
 int main()
 {
   typedef long long atomic_type;
@@ -16445,7 +16457,7 @@ $as_echo "mutex" >&6; }
   # unnecessary for this test.
 
     cat > conftest.$ac_ext << EOF
-#line 16448 "configure"
+#line 16460 "configure"
 int main()
 {
   _Decimal32 d1;
@@ -16487,7 +16499,7 @@ ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
   # unnecessary for this test.
 
   cat > conftest.$ac_ext << EOF
-#line 16490 "configure"
+#line 16502 "configure"
 template<typename T1, typename T2>
   struct same
   { typedef T2 type; };
@@ -28619,6 +28631,14 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
         $as_echo "#define HAVE_LINK 1" >>confdefs.h
 
+        $as_echo "#define HAVE_SYS_IOCT4YL_H 1" >>confdefs.h
+
+        $as_echo "#define HAVE_SYS_STAT_H 1" >>confdefs.h
+
+        $as_echo "#define HAVE_SYS_TYPES_H 1" >>confdefs.h
+
+        $as_echo "#define HAVE_S_ISREG 1" >>confdefs.h
+
         $as_echo "#define HAVE_QUICK_EXIT 1" >>confdefs.h
 
         $as_echo "#define HAVE_READLINK 1" >>confdefs.h
@@ -28633,8 +28653,42 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 
         $as_echo "#define HAVE_SYMLINK 1" >>confdefs.h
 
+        $as_echo "#define HAVE_SYS_IOCT4YL_H 1" >>confdefs.h
+
+        $as_echo "#define HAVE_SYS_STAT_H 1" >>confdefs.h
+
+        $as_echo "#define HAVE_SYS_TYPES_H 1" >>confdefs.h
+
+        $as_echo "#define HAVE_S_ISREG 1" >>confdefs.h
+
         $as_echo "#define HAVE_TRUNCATE 1" >>confdefs.h
 
+        $as_echo "#define HAVE_UNISTD_H 1" >>confdefs.h
+
+        $as_echo "#define HAVE_UNLINKAT 1" >>confdefs.h
+
+        $as_echo "#define HAVE_USLEEP 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_CHMOD 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_MKDIR 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_CHDIR 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_GETCWD 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_UTIME 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_LINK 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_READLINK 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_SYMLINK 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_TRUNCATE 1" >>confdefs.h
+
+        $as_echo "#define _GLIBCXX_USE_FDOPENDIR 1" >>confdefs.h
+
         $as_echo "#define HAVE_USLEEP 1" >>confdefs.h
 
 
diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac
index a6c01b29e94..1d96de3bd6b 100644
--- a/libstdc++-v3/configure.ac
+++ b/libstdc++-v3/configure.ac
@@ -399,6 +399,10 @@ dnl # rather than hardcoding that information.
         AC_DEFINE(HAVE_ALIGNED_ALLOC)
         AC_DEFINE(HAVE_AT_QUICK_EXIT)
         AC_DEFINE(HAVE_LINK)
+        AC_DEFINE(HAVE_SYS_IOCT4YL_H)
+        AC_DEFINE(HAVE_SYS_STAT_H)
+        AC_DEFINE(HAVE_SYS_TYPES_H)
+        AC_DEFINE(HAVE_S_ISREG)
         AC_DEFINE(HAVE_QUICK_EXIT)
         AC_DEFINE(HAVE_READLINK)
         AC_DEFINE(HAVE_SETENV)
@@ -406,7 +410,24 @@ dnl # rather than hardcoding that information.
         AC_DEFINE(HAVE_SOCKATMARK)
         AC_DEFINE(HAVE_STRERROR_L)
         AC_DEFINE(HAVE_SYMLINK)
+        AC_DEFINE(HAVE_SYS_IOCT4YL_H)
+        AC_DEFINE(HAVE_SYS_STAT_H)
+        AC_DEFINE(HAVE_SYS_TYPES_H)
+        AC_DEFINE(HAVE_S_ISREG)
         AC_DEFINE(HAVE_TRUNCATE)
+        AC_DEFINE(HAVE_UNISTD_H)
+        AC_DEFINE(HAVE_UNLINKAT)
+        AC_DEFINE(HAVE_USLEEP)
+        AC_DEFINE(_GLIBCXX_USE_CHMOD)
+        AC_DEFINE(_GLIBCXX_USE_MKDIR)
+        AC_DEFINE(_GLIBCXX_USE_CHDIR)
+        AC_DEFINE(_GLIBCXX_USE_GETCWD)
+        AC_DEFINE(_GLIBCXX_USE_UTIME)
+        AC_DEFINE(_GLIBCXX_USE_LINK)
+        AC_DEFINE(_GLIBCXX_USE_READLINK)
+        AC_DEFINE(_GLIBCXX_USE_SYMLINK)
+        AC_DEFINE(_GLIBCXX_USE_TRUNCATE)
+        AC_DEFINE(_GLIBCXX_USE_FDOPENDIR)
         AC_DEFINE(HAVE_USLEEP)
 
         # These functions are defined in librtemscpu.  We don't use
-- 
2.43.5

