ソースを参照

[newlib] 处理newlib版本不一致导致的问题

Meco Man 3 年 前
コミット
29b73ecb6f

+ 3 - 3
components/libc/compilers/common/nogcc/sys/select.h

@@ -6,6 +6,7 @@
  * Change Logs:
  * Date           Author       Notes
  * 2021-07-21     Meco Man     The first version
+ * 2021-12-25     Meco Man     Handle newlib 2.2.0 or lower version
  */
 
 #ifndef __SYS_SELECT_H__
@@ -33,13 +34,12 @@
 typedef long    fd_mask;
 
 #ifndef _WIN32
-#ifndef _SYS_TYPES_FD_SET /* MIPS */
-
+#ifndef _SYS_TYPES_FD_SET /* Newlib 2.2.0 or lower version */
 #define   NBBY    8       /* number of bits in a byte */
 #define   NFDBITS (sizeof (fd_mask) * NBBY)   /* bits per mask */
 #ifndef   howmany
 #define   howmany(x,y)    (((x)+((y)-1))/(y))
-#endif
+#endif /* howmany */
 
 typedef struct _types_fd_set {
     fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];

+ 12 - 0
components/libc/compilers/gcc/newlib/SConscript

@@ -1,4 +1,6 @@
+import os
 from building import *
+from gcc import *
 Import('rtconfig')
 
 src = []
@@ -14,9 +16,19 @@ if rtconfig.PLATFORM == 'gcc':
     else:
         src += ['syscalls.c']
 
+    #report newlib version
+    print('Newlib version:' + GetNewLibVersion(rtconfig))
+
     # identify this is Newlib, and only enable POSIX.1-1990
     CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1']
 
     group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
 
+
+list = os.listdir(cwd)
+for d in list:
+    path = os.path.join(cwd, d)
+    if os.path.isfile(os.path.join(path, 'SConscript')):
+        group = group + SConscript(os.path.join(d, 'SConscript'))
+
 Return('group')

+ 0 - 0
components/libc/compilers/gcc/partial/SConscript → components/libc/compilers/gcc/newlib/legacy/SConscript


+ 20 - 0
components/libc/compilers/gcc/newlib/legacy/_select/SConscript

@@ -0,0 +1,20 @@
+from shutil import copy
+from building import *
+from gcc import *
+Import('rtconfig')
+
+src   = []
+cwd   = GetCurrentDir()
+CPPPATH = [cwd]
+group = []
+
+# sys/select.h does not exist in newlib 2.1.0 or lower version
+if rtconfig.PLATFORM == 'gcc' and (CheckHeader(rtconfig, 'sys/select.h') == False):
+    try:
+        copy("../../../../common/nogcc/sys/select.h", "./sys/select.h") # copy from 'nogcc/sys/select.h'
+    except:
+        pass
+
+    group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
+
+Return('group')

+ 2 - 0
components/libc/compilers/gcc/newlib/legacy/_select/readme.md

@@ -0,0 +1,2 @@
+Newlib 2.2.0 or lower version does not provide `sys/select.h`, and `fd_set` is defined in `sys/types.h`. It will be generated by scons automatically, and **DO NOT** change it.
+

+ 9 - 3
components/libc/compilers/gcc/partial/mips/sys/select.h → components/libc/compilers/gcc/newlib/legacy/_select/sys/select.h

@@ -15,6 +15,10 @@
 #include <sys/types.h>
 #include <sys/time.h>
 
+#ifdef _WIN32
+#include <winsock.h>
+#endif
+
 #ifndef  FD_SETSIZE
 #define  FD_SETSIZE  32
 #endif
@@ -26,16 +30,17 @@
 #define FD_SETSIZE      DFS_FD_MAX
 #endif /* SAL_USING_POSIX */
 
-#define   NBBY    8       /* number of bits in a byte */
-
 typedef long    fd_mask;
 
+#ifndef _WIN32
+#ifndef _SYS_TYPES_FD_SET /* MIPS */
+
+#define   NBBY    8       /* number of bits in a byte */
 #define   NFDBITS (sizeof (fd_mask) * NBBY)   /* bits per mask */
 #ifndef   howmany
 #define   howmany(x,y)    (((x)+((y)-1))/(y))
 #endif
 
-#ifndef _SYS_TYPES_FD_SET /* MIPS */
 typedef struct _types_fd_set {
     fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
 } _types_fd_set;
@@ -48,5 +53,6 @@ typedef struct _types_fd_set {
 #endif /* _SYS_TYPES_FD_SET */
 
 int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
+#endif /* _WIN32 */
 
 #endif /* __SYS_SELECT_H__ */

+ 0 - 20
components/libc/compilers/gcc/partial/mips/SConscript

@@ -1,20 +0,0 @@
-from shutil import copy
-from building import *
-
-Import('rtconfig')
-
-src   = []
-cwd   = GetCurrentDir()
-CPPPATH = [cwd]
-group = []
-
-if rtconfig.PLATFORM == 'gcc' and ('mips' in rtconfig.PREFIX): # identify mips gcc tool chain
-    try:
-        # There is no 'sys/select.h' in tthe mips gcc toolchain; it will be copied from 'nogcc/sys/select.h'
-        copy("../../../common/nogcc/sys/select.h", "./sys/select.h")
-    except:
-        pass
-
-    group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
-
-Return('group')

+ 0 - 4
components/libc/compilers/gcc/partial/mips/readme.md

@@ -1,4 +0,0 @@
-These files don't exist in the mips gcc toolchain. They will be generated by scons automatically , and **DO NOT** change them:
-
-- sys/select.h
-

+ 0 - 2
components/libc/compilers/gcc/partial/readme.md

@@ -1,2 +0,0 @@
-This folder is for some particular targets.
-