[2/2] newlib: esp: add dirent.h header file

Message ID 3b049789c21d116d5378f48dd907c8160062b481.camel@espressif.com
State New
Headers
Series refactor xtensa code and support *-esp-* triplet |

Commit Message

Alexey Lapshin Aug. 2, 2024, 9:22 a.m. UTC
  Support dirent in *-esp-* toolchains

---
 newlib/Makefile.am                       |  8 ++--
 newlib/Makefile.in                       |  8 ++--
 newlib/configure                         |  2 +-
 newlib/configure.host                    | 12 ++++--
 newlib/libc/sys/esp/include/sys/dirent.h | 49 ++++++++++++++++++++++++
 5 files changed, 67 insertions(+), 12 deletions(-)
 create mode 100644 newlib/libc/sys/esp/include/sys/dirent.h

-- 
2.43.0
  

Patch

diff --git a/newlib/Makefile.am b/newlib/Makefile.am
index 87a7f8597..00088b6c3 100644
--- a/newlib/Makefile.am
+++ b/newlib/Makefile.am
@@ -312,10 +312,10 @@  install-data-local: install-toollibLIBRARIES install-multi $(INSTALL_DATA_LOCAL)
 	     $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/sys/`basename $$i`; \
 	    else true; fi ; \
 	  done ; \
-	  for i in $(srcdir)/libc/machine/$(machine_dir)/include/*.h; do \
-	    if [ -f $$i ]; then \
-	     $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \
-	    else true; fi ; \
+	  for i in $(call rwildcard,$(srcdir)/libc/machine/$(machine_dir)/include/,*.h); do \
+	    f=`echo $$i | sed s:^$(srcdir)/libc/machine/$(machine_dir)/::`; \
+	    $(MKDIR_P) $(DESTDIR)$(tooldir)/`dirname $$f`; \
+	    $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/`dirname $$f`; \
 	  done ; \
 	  for i in $(srcdir)/libc/sys/$(sys_dir)/sys/*.h; do \
 	    if [ -f $$i ]; then \
diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index 3fc98c66a..f417f64d5 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -50746,10 +50746,10 @@  install-data-local: install-toollibLIBRARIES install-multi $(INSTALL_DATA_LOCAL)
 	     $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/sys/`basename $$i`; \
 	    else true; fi ; \
 	  done ; \
-	  for i in $(srcdir)/libc/machine/$(machine_dir)/include/*.h; do \
-	    if [ -f $$i ]; then \
-	     $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/include/`basename $$i`; \
-	    else true; fi ; \
+	  for i in $(call rwildcard,$(srcdir)/libc/machine/$(machine_dir)/include/,*.h); do \
+	    f=`echo $$i | sed s:^$(srcdir)/libc/machine/$(machine_dir)/::`; \
+	    $(MKDIR_P) $(DESTDIR)$(tooldir)/`dirname $$f`; \
+	    $(INSTALL_DATA) $$i $(DESTDIR)$(tooldir)/`dirname $$f`; \
 	  done ; \
 	  for i in $(srcdir)/libc/sys/$(sys_dir)/sys/*.h; do \
 	    if [ -f $$i ]; then \
diff --git a/newlib/configure b/newlib/configure
index c0be656a6..cf667c7d8 100755
--- a/newlib/configure
+++ b/newlib/configure
@@ -6254,7 +6254,7 @@  else
 /* end confdefs.h.  */
 #define _LIBM
 // targ-include does not exist yet, use relative path
-#include "../sys/xtensa/include/xtensa/config/core-isa.h"
+#include "../machine/xtensa/include/xtensa/config/core-isa.h"
 #if (!XCHAL_HAVE_FP_SQRT)
 # error "Have not XCHAL_HAVE_FP_SQRT"
 #endif
diff --git a/newlib/configure.host b/newlib/configure.host
index 386183466..0f47a4769 100644
--- a/newlib/configure.host
+++ b/newlib/configure.host
@@ -443,6 +443,15 @@  case "${host}" in
 	sys_dir=tirtos
 	have_crt0="no"
 	;;
+  *-esp-*)
+	sys_dir=esp
+    have_crt0="no"
+	posix_dir=posix
+	newlib_cflags="${newlib_cflags} -D_NO_GLOB -D_NO_EXECVE -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT"
+	newlib_cflags="${newlib_cflags} -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -D_NO_POSIX_SPAWN"
+	newlib_cflags="${newlib_cflags} -DHAVE_FCNTL -DHAVE_BLKSIZE -DHAVE_OPENDIR -DHAVE_RENAME"
+	newlib_cflags="${newlib_cflags} -DGETREENT_PROVIDED -DSIGNAL_PROVIDED"
+	;;
   a29k-*-*)
 	sys_dir=a29khif
 	signal_dir=
@@ -576,9 +585,6 @@  case "${host}" in
   w65-*-*)
 	sys_dir=w65
 	;;
-  xtensa*-*-*)
-	sys_dir=xtensa
-	;;
   z8k-*-coff)
 	sys_dir=z8ksim
 	;;
diff --git a/newlib/libc/sys/esp/include/sys/dirent.h b/newlib/libc/sys/esp/include/sys/dirent.h
new file mode 100644
index 000000000..0e0c2f5fe
--- /dev/null
+++ b/newlib/libc/sys/esp/include/sys/dirent.h
@@ -0,0 +1,49 @@ 
+#ifndef _SYS_DIRENT_H
+#define _SYS_DIRENT_H
+
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _INO_T_DECLARED
+typedef	__ino_t ino_t;
+#define	_INO_T_DECLARED
+#endif
+
+struct dirent {
+    ino_t d_ino;            /* file number */
+    __uint8_t d_type;       /* file type, see below */
+    char d_name[255 + 1];   /* zero-terminated file name */
+};
+
+typedef struct {
+    __uint16_t dd_vfs_idx; /*!< VFS index, not to be used by applications */
+    __uint16_t dd_rsv;     /*!< field reserved for future extension */
+    /* remaining fields are defined by VFS implementation */
+} DIR;
+
+#if __BSD_VISIBLE
+#define MAXNAMLEN	 255
+
+/* File types */
+#define	DT_UNKNOWN	 0
+#define	DT_REG		 1
+#define	DT_DIR		 2
+
+/* File types which are not defined for ESP.
+ * But must be present to build libstd++ */
+#define	DT_CHR		 4
+#define	DT_BLK		 6
+#define	DT_FIFO		 8
+#define	DT_LNK		10
+#define	DT_SOCK		12
+#define	DT_WHT		14
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif