From 9058ec6e3b9c2234bfb3692bdce1afa6069cf766 Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Fri, 16 Apr 2021 23:40:18 +0800 Subject: [PATCH] [libc] add libc.a checking in musl --- components/libc/compilers/musl/SConscript | 23 +++++---- components/libc/compilers/musl/init.c | 16 ------- components/libc/compilers/musl/libc_syms.c | 54 ---------------------- components/libc/compilers/musl/stdio.c | 13 ++++-- 4 files changed, 23 insertions(+), 83 deletions(-) delete mode 100644 components/libc/compilers/musl/init.c delete mode 100644 components/libc/compilers/musl/libc_syms.c diff --git a/components/libc/compilers/musl/SConscript b/components/libc/compilers/musl/SConscript index c6c88edb5a..6d5e8fc021 100644 --- a/components/libc/compilers/musl/SConscript +++ b/components/libc/compilers/musl/SConscript @@ -1,3 +1,4 @@ +import os from building import * Import('rtconfig') @@ -5,14 +6,20 @@ src = Glob('*.c') cwd = GetCurrentDir() group = [] -CFLAGS = ' -nostdinc' -CPPPATH = [cwd, cwd + '/libc/include'] -CPPDEFINES = ['__STDC_ISO_10646__=201206L', '_STDC_PREDEF_H'] -LIBS = ['c', 'gcc'] -LIBPATH = [cwd + '/libc/lib'] +if rtconfig.PLATFORM == 'gcc' and GetDepend('RT_USING_MUSL'): + CPPDEFINES = ['__STDC_ISO_10646__=201206L', '_STDC_PREDEF_H'] + LIBS = ['c', 'gcc'] -if rtconfig.PLATFORM == 'gcc': - group = DefineGroup('musl', src, depend = ['RT_USING_LIBC', 'RT_USING_MUSL'], CFLAGS = CFLAGS, - CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS, LIBPATH = LIBPATH) + if os.path.exists(os.path.join(cwd, 'libc', 'lib', 'libc.a')): + CFLAGS = ' -nostdinc' + CPPPATH = [cwd, cwd + '/libc/include'] + LIBPATH = [cwd + '/libc/lib'] + + group = DefineGroup('musl', src, depend = ['RT_USING_LIBC', 'RT_USING_MUSL'], CFLAGS = CFLAGS, + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS, LIBPATH = LIBPATH) + else: + LINKFLAGS = ' --specs=kernel.specs' + group = DefineGroup('musl', src, depend = ['RT_USING_LIBC', 'RT_USING_MUSL'], LINKFLAGS = LINKFLAGS, + CPPDEFINES = CPPDEFINES, LIBS = LIBS) Return('group') diff --git a/components/libc/compilers/musl/init.c b/components/libc/compilers/musl/init.c deleted file mode 100644 index eb6cdcfa81..0000000000 --- a/components/libc/compilers/musl/init.c +++ /dev/null @@ -1,16 +0,0 @@ -extern char **__environ; - -#if 0 -void __init_libc(char **envp, char *pn) -{ - __environ = envp; -} -#endif - -void __libc_exit_fini(void) -{ -} - -void __libc_start_init(void) -{ -} diff --git a/components/libc/compilers/musl/libc_syms.c b/components/libc/compilers/musl/libc_syms.c deleted file mode 100644 index 8a0cbcdcf3..0000000000 --- a/components/libc/compilers/musl/libc_syms.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2006-2018, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include -#include - -#include -#include -#include - -RTM_EXPORT(strcpy); -RTM_EXPORT(strncpy); -RTM_EXPORT(strlen); -RTM_EXPORT(strcat); -RTM_EXPORT(strstr); -RTM_EXPORT(strchr); -RTM_EXPORT(strcmp); -RTM_EXPORT(strtol); -RTM_EXPORT(strtoul); -RTM_EXPORT(strncmp); - -RTM_EXPORT(memcpy); -RTM_EXPORT(memcmp); -RTM_EXPORT(memmove); -RTM_EXPORT(memset); -RTM_EXPORT(memchr); - -RTM_EXPORT(putchar); -RTM_EXPORT(puts); -RTM_EXPORT(printf); -RTM_EXPORT(sprintf); -RTM_EXPORT(snprintf); - -RTM_EXPORT(fwrite); - -#include -RTM_EXPORT(localtime); -RTM_EXPORT(time); - -#include -RTM_EXPORT(longjmp); -RTM_EXPORT(setjmp); - -RTM_EXPORT(exit); -RTM_EXPORT(abort); - -RTM_EXPORT(rand); - diff --git a/components/libc/compilers/musl/stdio.c b/components/libc/compilers/musl/stdio.c index 962dfb0e71..7b77ca9cf4 100644 --- a/components/libc/compilers/musl/stdio.c +++ b/components/libc/compilers/musl/stdio.c @@ -12,7 +12,6 @@ #include #include "libc.h" -#include "dfs.h" #define STDIO_DEVICE_NAME_MAX 32 @@ -61,9 +60,13 @@ int libc_stdio_set_console(const char* device_name, int mode) return -1; } -int libc_stdio_get_console(void) { +int libc_stdio_get_console(void) +{ + int ret = -1; if (std_console) - return fileno(std_console); - else - return -1; + { + ret = fileno(std_console); + } + + return ret; } -- Gitee