summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/building.py14
-rw-r--r--tools/cmake.py140
-rw-r--r--tools/file_check.py1
-rw-r--r--tools/formatting.py135
-rw-r--r--tools/makefile.py8
-rw-r--r--tools/mkdist.py3
-rw-r--r--tools/rtthread.mk4
7 files changed, 119 insertions, 186 deletions
diff --git a/tools/building.py b/tools/building.py
index bfdd1ff55a..e078c1626c 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -258,6 +258,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'eclipse':('gcc', 'gcc'),
'ses' : ('gcc', 'gcc'),
'cmake':('gcc', 'gcc'),
+ 'cmake-armclang':('keil', 'armclang'),
'codelite' : ('gcc', 'gcc')}
tgt_name = GetOption('target')
@@ -883,7 +884,7 @@ def GenTargetProject(program = None):
from codelite import TargetCodelite
TargetCodelite(Projects, program)
- if GetOption('target') == 'cmake':
+ if GetOption('target') == 'cmake' or GetOption('target') == 'cmake-armclang':
from cmake import CMakeProject
CMakeProject(Env,Projects)
@@ -925,14 +926,11 @@ def EndBuilding(target, program = None):
project_name = GetOption('project-name')
if not isinstance(project_path, str) or len(project_path) == 0 :
- print("\nwarning : --project-path=your_project_path parameter is required.")
- print("\nstop!")
- exit(0)
-
+ project_path = os.path.join(BSP_ROOT, 'dist_ide_project')
+ print("\nwarning : --project-path not specified, use default path: {0}.".format(project_path))
if not isinstance(project_name, str) or len(project_name) == 0:
- print("\nwarning : --project-name=your_project_name parameter is required.")
- print("\nstop!")
- exit(0)
+ project_name = "dist_ide_project"
+ print("\nwarning : --project-name not specified, use default project name: {0}.".format(project_name))
rtt_ide = {'project_path' : project_path, 'project_name' : project_name}
MkDist(program, BSP_ROOT, Rtt_Root, Env, rtt_ide)
diff --git a/tools/cmake.py b/tools/cmake.py
index 645bdbb229..811b6693cb 100644
--- a/tools/cmake.py
+++ b/tools/cmake.py
@@ -4,6 +4,7 @@ Author: https://github.com/klivelinux
"""
import os
+import sys
import re
import utils
import rtconfig
@@ -13,73 +14,132 @@ def GenerateCFiles(env,project):
"""
Generate CMakeLists.txt files
"""
-
info = utils.ProjectInfo(env)
-
- CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC)
- CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX)
- AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS)
- AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR)
- LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK)
- SIZE = os.path.join(rtconfig.EXEC_PATH, rtconfig.SIZE)
- OBJDUMP = os.path.join(rtconfig.EXEC_PATH, rtconfig.OBJDUMP)
- OBJCOPY = os.path.join(rtconfig.EXEC_PATH, rtconfig.OBJCPY)
+
+ CC = os.path.join(rtconfig.EXEC_PATH, rtconfig.CC).replace('\\', "/")
+ if 'CXX' in dir(rtconfig):
+ CXX = os.path.join(rtconfig.EXEC_PATH, rtconfig.CXX).replace('\\', "/")
+ else:
+ CXX = ''
+ AS = os.path.join(rtconfig.EXEC_PATH, rtconfig.AS).replace('\\', "/")
+ AR = os.path.join(rtconfig.EXEC_PATH, rtconfig.AR).replace('\\', "/")
+ LINK = os.path.join(rtconfig.EXEC_PATH, rtconfig.LINK).replace('\\', "/")
+ if rtconfig.PLATFORM == 'gcc':
+ SIZE = os.path.join(rtconfig.EXEC_PATH, rtconfig.SIZE).replace('\\', "/")
+ OBJDUMP = os.path.join(rtconfig.EXEC_PATH, rtconfig.OBJDUMP).replace('\\', "/")
+ OBJCOPY = os.path.join(rtconfig.EXEC_PATH, rtconfig.OBJCPY).replace('\\', "/")
+ elif rtconfig.CROSS_TOOL == 'keil':
+ FROMELF = os.path.join(rtconfig.EXEC_PATH, 'fromelf').replace('\\', "/")
+
+ CFLAGS = rtconfig.CFLAGS.replace('\\', "/").replace('\"', "\\\"")
+ if 'CXXFLAGS' in dir(rtconfig):
+ CXXFLAGS = rtconfig.CXXFLAGS.replace('\\', "/").replace('\"', "\\\"")
+ else:
+ CXXFLAGS = CFLAGS
+ AFLAGS = rtconfig.AFLAGS.replace('\\', "/").replace('\"', "\\\"")
+ LFLAGS = rtconfig.LFLAGS.replace('\\', "/").replace('\"', "\\\"")
+
+ if "win32" in sys.platform:
+ CC += ".exe"
+ if CXX != '':
+ CXX += ".exe"
+ AS += ".exe"
+ AR += ".exe"
+ LINK += ".exe"
+ if rtconfig.PLATFORM == 'gcc':
+ SIZE += ".exe"
+ OBJDUMP += ".exe"
+ OBJCOPY += ".exe"
+ elif rtconfig.CROSS_TOOL == 'keil':
+ FROMELF += ".exe"
+
+ if not os.path.exists(CC) or not os.path.exists(AS) or not os.path.exists(AR) or not os.path.exists(LINK):
+ print("'Cannot found toolchain directory, please check RTT_CC and RTT_EXEC_PATH'")
+ sys.exit(-1)
cm_file = open('CMakeLists.txt', 'w')
if cm_file:
cm_file.write("CMAKE_MINIMUM_REQUIRED(VERSION 3.10)\n\n")
cm_file.write("SET(CMAKE_SYSTEM_NAME Generic)\n")
+ cm_file.write("SET(CMAKE_SYSTEM_PROCESSOR " + rtconfig.CPU +")\n")
cm_file.write("#SET(CMAKE_VERBOSE_MAKEFILE ON)\n\n")
cm_file.write("SET(CMAKE_C_COMPILER \""+ CC + "\")\n")
- cm_file.write("SET(CMAKE_CXX_COMPILER \""+ CXX + "\")\n")
cm_file.write("SET(CMAKE_ASM_COMPILER \""+ AS + "\")\n")
- cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n")
- cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n")
+ cm_file.write("SET(CMAKE_C_FLAGS \""+ CFLAGS + "\")\n")
+ cm_file.write("SET(CMAKE_ASM_FLAGS \""+ AFLAGS + "\")\n")
+ cm_file.write("SET(CMAKE_C_COMPILER_WORKS TRUE)\n\n")
+
+ if CXX != '':
+ cm_file.write("SET(CMAKE_CXX_COMPILER \""+ CXX + "\")\n")
+ cm_file.write("SET(CMAKE_CXX_FLAGS \""+ CXXFLAGS + "\")\n")
+ cm_file.write("SET(CMAKE_CXX_COMPILER_WORKS TRUE)\n\n")
+
+ if rtconfig.PLATFORM == 'gcc':
+ cm_file.write("SET(CMAKE_OBJCOPY \""+ OBJCOPY + "\")\n")
+ cm_file.write("SET(CMAKE_SIZE \""+ SIZE + "\")\n\n")
+ elif rtconfig.CROSS_TOOL == 'keil':
+ cm_file.write("SET(CMAKE_FROMELF \""+ FROMELF + "\")\n\n")
+ LINKER_FLAGS = ''
+ LINKER_LIBS = ''
+ if rtconfig.PLATFORM == 'gcc':
+ LINKER_FLAGS += '-T'
+ elif rtconfig.CROSS_TOOL == 'keil':
+ LINKER_FLAGS += '--scatter'
+ for group in project:
+ if 'LIBPATH' in group.keys():
+ for f in group['LIBPATH']:
+ LINKER_LIBS += ' --userlibpath ' + f.replace("\\", "/")
+ for group in project:
+ if 'LIBS' in group.keys():
+ for f in group['LIBS']:
+ LINKER_LIBS += ' ' + f.replace("\\", "/") + '.lib'
+ cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub(LINKER_FLAGS + '(\s*)', LINKER_FLAGS + ' ${CMAKE_SOURCE_DIR}/', LFLAGS) + LINKER_LIBS + "\")\n\n")
+
+ if CXX != '':
+ cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n")
+ cm_file.write("PROJECT(rtthread C CXX ASM)\n")
+ else:
+ cm_file.write("PROJECT(rtthread C ASM)\n")
- cm_file.write("SET(CMAKE_C_FLAGS \""+ rtconfig.CFLAGS + "\")\n")
- cm_file.write("SET(CMAKE_CXX_FLAGS \""+ rtconfig.CXXFLAGS + "\")\n")
- cm_file.write("SET(CMAKE_ASM_FLAGS \""+ rtconfig.AFLAGS + "\")\n")
- cm_file.write("SET(CMAKE_EXE_LINKER_FLAGS \""+ re.sub('-T(\s*)', '-T ${CMAKE_SOURCE_DIR}/',rtconfig.LFLAGS) + "\")\n\n")
-
- cm_file.write("SET(CMAKE_CXX_STANDARD 14)\n")
- cm_file.write("PROJECT(rtthread C CXX ASM)\n")
-
cm_file.write("INCLUDE_DIRECTORIES(\n")
for i in info['CPPPATH']:
- cm_file.write( "\t" +i + "\n")
+ cm_file.write( "\t" + i.replace("\\", "/") + "\n")
cm_file.write(")\n\n")
-
cm_file.write("ADD_DEFINITIONS(\n")
for i in info['CPPDEFINES']:
- cm_file.write("\t-D" + i + "\n")
+ cm_file.write("\t-D" + i + "\n")
cm_file.write(")\n\n")
cm_file.write("SET(PROJECT_SOURCES\n")
for group in project:
for f in group['src']:
- cm_file.write( "\t"+os.path.normpath(f.rfile().abspath)+"\n" )
- cm_file.write(")\n\n")
-
- cm_file.write("LINK_DIRECTORIES(\n")
- for group in project:
- if 'LIBPATH' in group.keys():
- for f in group['LIBPATH']:
- cm_file.write( "\t"+ f + "\n" )
+ cm_file.write( "\t" + os.path.normpath(f.rfile().abspath).replace("\\", "/") + "\n" )
cm_file.write(")\n\n")
- cm_file.write("LINK_LIBRARIES(\n")
- for group in project:
- if 'LIBS' in group.keys():
- for f in group['LIBS']:
- cm_file.write( "\t"+ "{}\n".format(f))
- cm_file.write(")\n\n")
+ if rtconfig.PLATFORM == 'gcc':
+ cm_file.write("LINK_DIRECTORIES(\n")
+ for group in project:
+ if 'LIBPATH' in group.keys():
+ for f in group['LIBPATH']:
+ cm_file.write( "\t"+ f.replace("\\", "/") + "\n" )
+ cm_file.write(")\n\n")
+
+ cm_file.write("LINK_LIBRARIES(\n")
+ for group in project:
+ if 'LIBS' in group.keys():
+ for f in group['LIBS']:
+ cm_file.write( "\t"+ "{}\n".format(f.replace("\\", "/")))
+ cm_file.write(")\n\n")
- cm_file.write("ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})\n")
- cm_file.write("ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD \nCOMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)")
+ cm_file.write("ADD_EXECUTABLE(${CMAKE_PROJECT_NAME}.elf ${PROJECT_SOURCES})\n")
+ cm_file.write("ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME}.elf POST_BUILD \nCOMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_SIZE} ${CMAKE_PROJECT_NAME}.elf)")
+ elif rtconfig.CROSS_TOOL == 'keil':
+ cm_file.write("ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} ${PROJECT_SOURCES})\n")
+ cm_file.write("ADD_CUSTOM_COMMAND(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD \nCOMMAND ${CMAKE_FROMELF} --bin ${CMAKE_PROJECT_NAME}.elf --output ${CMAKE_PROJECT_NAME}.bin COMMAND ${CMAKE_FROMELF} -z ${CMAKE_PROJECT_NAME}.elf)")
cm_file.close()
diff --git a/tools/file_check.py b/tools/file_check.py
index 046b2a009f..63767782b5 100644
--- a/tools/file_check.py
+++ b/tools/file_check.py
@@ -84,6 +84,7 @@ class CheckOut:
try:
os.system('git remote add rtt_repo {}'.format(self.rtt_repo))
os.system('git fetch rtt_repo')
+ os.system('git merge rtt_repo/{}'.format(self.rtt_branch))
os.system('git reset rtt_repo/{} --soft'.format(self.rtt_branch))
os.system('git status > git.txt')
except Exception as e:
diff --git a/tools/formatting.py b/tools/formatting.py
deleted file mode 100644
index 0b63e031fa..0000000000
--- a/tools/formatting.py
+++ /dev/null
@@ -1,135 +0,0 @@
-#
-# File : formatting.py
-# This file is part of RT-Thread RTOS
-# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
-#
-# This program 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 2 of the License, or
-# (at your option) any later version.
-#
-# This program 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.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Change Logs:
-# Date Author Notes
-# 2021-03-02 Meco Man The first version
-# 2021-03-04 Meco Man 增加统一转换成UTF-8编码格式功能
-
-
-#本文件会自动对指定路径下的所有文件包括子文件夹的文件(仅针对.c.h)进行扫描
-# 1)将源文件编码统一为UTF-8;
-# 2)将TAB键替换为空格;
-# 3)将每行末尾多余的空格删除,并统一换行符为'\n';
-#使用时只需要双击本文件,输入要扫描的文件夹路径即可
-#不能保证100%全部成功转换为UTF-8,有一些编码特殊或识别不准确会在终端打印信息,需人工转换
-
-#欢迎对本文件的功能继续做出补充,欢迎提交PR
-
-import os
-import chardet
-
-#用空格代替TAB键
-#这里并不是简单的将TAB替换成4个空格
-#空格个数到底是多少需要计算,因为TAB制表本身有自动对齐的功能
-def tab2spaces(line):
- list_str = list(line) #字符串打散成列表,放边操作
- i = list_str.count('\t')
-
- while i > 0:
- ptr = list_str.index('\t')
- del list_str[ptr]
- space_need_to_insert = 4 - (ptr%4)
- j = 0
- while j < space_need_to_insert:
- list_str.insert(ptr,' ')
- j = j+1
-
- i = i-1
-
- line = ''.join(list_str) #列表恢复成字符串
- return line
-
-#删除每行末尾多余的空格 统一使用\n作为结尾
-def formattail(line):
- line = line.rstrip()
- line = line + '\n'
- return line
-
-#对单个文件进行格式整理
-def format_codes(filename):
- try:
- file=open(filename,'r',encoding = 'utf-8')
- file_temp=open('temp','w',encoding = 'utf-8')
- for line in file:
- line = tab2spaces(line)
- line = formattail(line)
- file_temp.write(line)
- file_temp.close()
- file.close()
- os.remove(filename)
- os.rename('temp',filename)
-
-def get_encode_info(file):
- with open(file, 'rb') as f:
- code = chardet.detect(f.read())['encoding']
- #charde库有一定几率对当前文件的编码识别不准确
- if code == 'EUC-JP': #容易将含着少量中文的英文字符文档识别为日语编码格式
- code = 'GB2312'
- elif code == 'ISO-8859-1': #部分文件GB2312码会被识别成ISO-8859-1
- code = 'GB2312'
-
- if not (code == 'ascii' or code == 'utf-8' or code == 'GB2312' #编码识别正确
- or code == 'Windows-1252'): # Windows-1252 是由于意法半导体是法国企业's的'是法语的'导致的
- if code != None:
- print('未处理,需人工确认:'+code+':'+file) #需要人工确认
- code = None
-
- return code
-
-#将单个文件转为UTF-8编码
-def conver_to_utf_8 (path):
- try:
- info = get_encode_info(path)
- if info == None:
- return 0 #0 失败
-
- file=open(path,'rb+')
- data = file.read()
- string = data.decode(info)
- utf = string.encode('utf-8')
- file.seek(0)
- file.write(utf)
- file.close()
- return 1 #1成功
- except UnicodeDecodeError:
- print("UnicodeDecodeError未处理,需人工确认"+path)
- return 0
- except UnicodeEncodeError:
- print("UnicodeEncodeError未处理,需人工确认"+path)
- return 0
-
-# 递归扫描目录下的所有文件
-def traversalallfile(path):
- filelist=os.listdir(path)
- for file in filelist:
- filepath=os.path.join(path,file)
- if os.path.isdir(filepath):
- traversalallfile(filepath)
- elif os.path.isfile(filepath):
- if filepath.endswith(".c") == True or filepath.endswith(".h") == True: #只处理.c和.h文件
- if conver_to_utf_8(filepath) == 1: #先把这个文件转为UTF-8编码,1成功
- format_codes(filepath) #再对这个文件进行格式整理
-
-def formatfiles():
- workpath = input('enter work path: ')
- traversalallfile(workpath)
-
-if __name__ == '__main__':
- formatfiles()
diff --git a/tools/makefile.py b/tools/makefile.py
index 655e294575..97001892c9 100644
--- a/tools/makefile.py
+++ b/tools/makefile.py
@@ -51,6 +51,14 @@ def TargetMakefile(env):
if 'CXXFLAGS' in dir(rtconfig):
make.write('CXXFLAGS :=%s' % (rtconfig.CXXFLAGS))
make.write('\n')
+ if env.has_key('LIBS'):
+ make.write('EXTERN_LIB := ')
+ for tlib in env['LIBS']:
+ make.write('-l%s ' % (tlib))
+ if env.has_key('LIBPATH'):
+ for tlibpath in env['LIBPATH']:
+ make.write('-L%s ' % (tlibpath))
+ make.write('\n')
make.write('\n')
diff --git a/tools/mkdist.py b/tools/mkdist.py
index a29db7b080..e2c2b8da50 100644
--- a/tools/mkdist.py
+++ b/tools/mkdist.py
@@ -176,7 +176,8 @@ def bs_update_ide_project(bsp_root, rtt_root, rttide = None):
'iar':('iar', 'iar'),
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
- 'cdk':('gcc', 'gcc')}
+ 'cdk':('gcc', 'gcc'),
+ 'eclipse':('eclipse', 'gcc')}
else:
item = 'eclipse --project-name=' + rttide['project_name']
tgt_dict = {item:('gcc', 'gcc')}
diff --git a/tools/rtthread.mk b/tools/rtthread.mk
index 7cf018cb52..4bb3e2754d 100644
--- a/tools/rtthread.mk
+++ b/tools/rtthread.mk
@@ -122,10 +122,10 @@ $(TARGET): $(OBJS)
@echo ar $(TARGET)
@$(CROSS_COMPILE)ar -rv $@ $(OBJS)
else
-$(TARGET): $(OBJS) $(EXTERN_LIB)
+$(TARGET): $(OBJS)
@echo ------------------------------------------------
@echo link $(TARGET)
- @$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB) -lc -lm
+ @$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB)
@echo ------------------------------------------------
@$(CROSS_COMPILE)objcopy -O binary $@ rtthread.bin
@$(CROSS_COMPILE)size $@