diff options
| author | cliff-cmc <[email protected]> | 2021-02-26 11:09:27 +0800 |
|---|---|---|
| committer | Cliff Chen <[email protected]> | 2021-02-26 11:45:19 +0800 |
| commit | eea0c3d74a40f73235da45c6f77e8b411ac94cf2 (patch) | |
| tree | a6906f1aed7118ab53dbe18f2ee4727a754583af /tools | |
| parent | 1a9ecf27f31277750d92c921b62503f75275e122 (diff) | |
| parent | fae0fa8eea4c0e797940bf1eddc8ee6c1711734a (diff) | |
Add memtrace command for memheap.c
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/WCS.py | 440 | ||||
| -rw-r--r-- | tools/building.py | 22 | ||||
| -rw-r--r-- | tools/codelite.py | 215 | ||||
| -rw-r--r-- | tools/codelite_template.project | 61 | ||||
| -rw-r--r-- | tools/codelite_template.workspace | 10 | ||||
| -rw-r--r-- | tools/eclipse.py | 133 | ||||
| -rw-r--r-- | tools/menuconfig.py | 43 | ||||
| -rw-r--r-- | tools/rt_studio.py | 351 | ||||
| -rw-r--r-- | tools/rtthread.mk | 17 |
9 files changed, 1235 insertions, 57 deletions
diff --git a/tools/WCS.py b/tools/WCS.py new file mode 100644 index 0000000000..8625d6fff5 --- /dev/null +++ b/tools/WCS.py @@ -0,0 +1,440 @@ +import re +import pprint +import os +from subprocess import check_output +from optparse import OptionParser + +# Constants +rtl_ext_end = ".dfinish" +rtl_ext = None # e.g. '.c.270r.dfinish'. The number '270' will change with gcc version and is auto-detected by the + # function find_rtl_ext +dir = r'.' # Working directory +su_ext = '.su' +obj_ext = '.o' +manual_ext = '.msu' +read_elf_path = "arm-none-eabi-readelf.exe" # You may need to enter the full path here +stdout_encoding = "utf-8" # System dependant + + +class Printable: + def __repr__(self): + return "<" + type(self).__name__ + "> " + pprint.pformat(vars(self), indent=4, width=1) + + +class Symbol(Printable): + pass + + +def read_symbols(file): + from subprocess import check_output + + def to_symbol(read_elf_line): + v = read_elf_line.split() + + s2 = Symbol() + s2.value = int(v[1], 16) + s2.size = int(v[2]) + s2.type = v[3] + s2.binding = v[4] + if len(v) >= 8: + s2.name = v[7] + else: + s2.name = "" + + return s2 + + output = check_output([read_elf_path, "-s", "-W", file]).decode(stdout_encoding) + lines = output.splitlines()[3:] + return [to_symbol(line) for line in lines] + + +def read_obj(tu, call_graph): + """ + Reads the file tu.o and gets the binding (global or local) for each function + :param tu: name of the translation unit (e.g. for main.c, this would be 'main') + :param call_graph: a object used to store information about each function, results go here + """ + symbols = read_symbols(tu[0:tu.rindex(".")] + obj_ext) + + for s in symbols: + + if s.type == 'FUNC': + if s.binding == 'GLOBAL': + # Check for multiple declarations + if s.name in call_graph['globals'] or s.name in call_graph['locals']: + raise Exception('Multiple declarations of {}'.format(s.name)) + call_graph['globals'][s.name] = {'tu': tu, 'name': s.name, 'binding': s.binding} + elif s.binding == 'LOCAL': + # Check for multiple declarations + if s.name in call_graph['locals'] and tu in call_graph['locals'][s.name]: + raise Exception('Multiple declarations of {}'.format(s.name)) + + if s.name not in call_graph['locals']: + call_graph['locals'][s.name] = {} + + call_graph['locals'][s.name][tu] = {'tu': tu, 'name': s.name, 'binding': s.binding} + elif s.binding == 'WEAK': + if s.name in call_graph['weak']: + raise Exception('Multiple declarations of {}'.format(s.name)) + call_graph['weak'][s.name] = {'tu': tu, 'name': s.name, 'binding': s.binding} + else: + raise Exception('Error Unknown Binding "{}" for symbol: {}'.format(s.binding, s.name)) + + +def find_fxn(tu, fxn, call_graph): + """ + Looks up the dictionary associated with the function. + :param tu: The translation unit in which to look for locals functions + :param fxn: The function name + :param call_graph: a object used to store information about each function + :return: the dictionary for the given function or None + """ + + if fxn in call_graph['globals']: + return call_graph['globals'][fxn] + else: + try: + return call_graph['locals'][fxn][tu] + except KeyError: + return None + + +def find_demangled_fxn(tu, fxn, call_graph): + """ + Looks up the dictionary associated with the function. + :param tu: The translation unit in which to look for locals functions + :param fxn: The function name + :param call_graph: a object used to store information about each function + :return: the dictionary for the given function or None + """ + for f in call_graph['globals'].values(): + if 'demangledName' in f: + if f['demangledName'] == fxn: + return f + for f in call_graph['locals'].values(): + if tu in f: + if 'demangledName' in f[tu]: + if f[tu]['demangledName'] == fxn: + return f[tu] + return None + + +def read_rtl(tu, call_graph): + """ + Read an RTL file and finds callees for each function and if there are calls via function pointer. + :param tu: the translation unit + :param call_graph: a object used to store information about each function, results go here + """ + + # Construct A Call Graph + function = re.compile(r'^;; Function (.*) \((\S+), funcdef_no=\d+(, [a-z_]+=\d+)*\)( \([a-z ]+\))?$') + static_call = re.compile(r'^.*\(call.*"(.*)".*$') + other_call = re.compile(r'^.*call .*$') + + for line_ in open(tu + rtl_ext).readlines(): + m = function.match(line_) + if m: + fxn_name = m.group(2) + fxn_dict2 = find_fxn(tu, fxn_name, call_graph) + if not fxn_dict2: + pprint.pprint(call_graph) + raise Exception("Error locating function {} in {}".format(fxn_name, tu)) + + fxn_dict2['demangledName'] = m.group(1) + fxn_dict2['calls'] = set() + fxn_dict2['has_ptr_call'] = False + continue + + m = static_call.match(line_) + if m: + fxn_dict2['calls'].add(m.group(1)) + # print("Call: {0} -> {1}".format(current_fxn, m.group(1))) + continue + + m = other_call.match(line_) + if m: + fxn_dict2['has_ptr_call'] = True + continue + + +def read_su(tu, call_graph): + """ + Reads the 'local_stack' for each function. Local stack ignores stack used by callees. + :param tu: the translation unit + :param call_graph: a object used to store information about each function, results go here + :return: + """ + + su_line = re.compile(r'^([^ :]+):([\d]+):([\d]+):(.+)\t(\d+)\t(\S+)$') + i = 1 + + for line in open(tu[0:tu.rindex(".")] + su_ext).readlines(): + m = su_line.match(line) + if m: + fxn = m.group(4) + fxn_dict2 = find_demangled_fxn(tu, fxn, call_graph) + fxn_dict2['local_stack'] = int(m.group(5)) + else: + print("error parsing line {} in file {}".format(i, tu)) + i += 1 + + +def read_manual(file, call_graph): + """ + reads the manual stack useage files. + :param file: the file name + :param call_graph: a object used to store information about each function, results go here + """ + + for line in open(file).readlines(): + fxn, stack_sz = line.split() + if fxn in call_graph: + raise Exception("Redeclared Function {}".format(fxn)) + call_graph['globals'][fxn] = {'wcs': int(stack_sz), + 'calls': set(), + 'has_ptr_call': False, + 'local_stack': int(stack_sz), + 'is_manual': True, + 'name': fxn, + 'tu': '#MANUAL', + 'binding': 'GLOBAL'} + + +def validate_all_data(call_graph): + """ + Check that every entry in the call graph has the following fields: + .calls, .has_ptr_call, .local_stack, .scope, .src_line + """ + + def validate_dict(d): + if not ('calls' in d and 'has_ptr_call' in d and 'local_stack' in d + and 'name' in d and 'tu' in d): + print("Error data is missing in fxn dictionary {}".format(d)) + + # Loop through every global and local function + # and resolve each call, save results in r_calls + for fxn_dict2 in call_graph['globals'].values(): + validate_dict(fxn_dict2) + + for l_dict in call_graph['locals'].values(): + for fxn_dict2 in l_dict.values(): + validate_dict(fxn_dict2) + +def resolve_all_calls(call_graph): + def resolve_calls(fxn_dict2): + fxn_dict2['r_calls'] = [] + fxn_dict2['unresolved_calls'] = set() + + for call in fxn_dict2['calls']: + call_dict = find_fxn(fxn_dict2['tu'], call, call_graph) + if call_dict: + fxn_dict2['r_calls'].append(call_dict) + else: + fxn_dict2['unresolved_calls'].add(call) + + # Loop through every global and local function + # and resolve each call, save results in r_calls + for fxn_dict in call_graph['globals'].values(): + resolve_calls(fxn_dict) + + for l_dict in call_graph['locals'].values(): + for fxn_dict in l_dict.values(): + resolve_calls(fxn_dict) + + +def calc_all_wcs(call_graph): + def calc_wcs(fxn_dict2, call_graph1, parents): + """ + Calculates the worst case stack for a fxn that is declared (or called from) in a given file. + :param parents: This function gets called recursively through the call graph. If a function has recursion the + tuple file, fxn will be in the parents stack and everything between the top of the stack and the matching entry + has recursion. + :return: + """ + + # If the wcs is already known, then nothing to do + if 'wcs' in fxn_dict2: + return + + # Check for pointer calls + if fxn_dict2['has_ptr_call']: + fxn_dict2['wcs'] = 'unbounded' + return + + # Check for recursion + if fxn_dict2 in parents: + fxn_dict2['wcs'] = 'unbounded' + return + + # Calculate WCS + call_max = 0 + for call_dict in fxn_dict2['r_calls']: + + # Calculate the WCS for the called function + parents.append(fxn_dict2) + calc_wcs(call_dict, call_graph1, parents) + parents.pop() + + # If the called function is unbounded, so is this function + if call_dict['wcs'] == 'unbounded': + fxn_dict2['wcs'] = 'unbounded' + return + + # Keep track of the call with the largest stack use + call_max = max(call_max, call_dict['wcs']) + + # Propagate Unresolved Calls + for unresolved_call in call_dict['unresolved_calls']: + fxn_dict2['unresolved_calls'].add(unresolved_call) + + fxn_dict2['wcs'] = call_max + fxn_dict2['local_stack'] + + # Loop through every global and local function + # and resolve each call, save results in r_calls + for fxn_dict in call_graph['globals'].values(): + calc_wcs(fxn_dict, call_graph, []) + + for l_dict in call_graph['locals'].values(): + for fxn_dict in l_dict.values(): + calc_wcs(fxn_dict, call_graph, []) + + +def print_all_fxns(call_graph): + + def print_fxn(row_format, fxn_dict2): + unresolved = fxn_dict2['unresolved_calls'] + stack = str(fxn_dict2['wcs']) + if unresolved: + unresolved_str = '({})'.format(' ,'.join(unresolved)) + if stack != 'unbounded': + stack = "unbounded:" + stack + else: + unresolved_str = '' + + print(row_format.format(fxn_dict2['tu'], fxn_dict2['demangledName'], stack, unresolved_str)) + + def get_order(val): + if val == 'unbounded': + return 1 + else: + return -val + + # Loop through every global and local function + # and resolve each call, save results in r_calls + d_list = [] + for fxn_dict in call_graph['globals'].values(): + d_list.append(fxn_dict) + + for l_dict in call_graph['locals'].values(): + for fxn_dict in l_dict.values(): + d_list.append(fxn_dict) + + d_list.sort(key=lambda item: get_order(item['wcs'])) + + # Calculate table width + tu_width = max(max([len(d['tu']) for d in d_list]), 16) + name_width = max(max([len(d['name']) for d in d_list]), 13) + row_format = "{:<" + str(tu_width + 2) + "} {:<" + str(name_width + 2) + "} {:>14} {:<17}" + + # Print out the table + print("") + print(row_format.format('Translation Unit', 'Function Name', 'Stack', 'Unresolved Dependencies')) + for d in d_list: + print_fxn(row_format, d) + + +def find_rtl_ext(): + # Find the rtl_extension + global rtl_ext + + for root, directories, filenames in os.walk('.'): + for f in filenames: + if (f.endswith(rtl_ext_end)): + rtl_ext = f[f[:-len(rtl_ext_end)].rindex("."):] + print("rtl_ext = " + rtl_ext) + return + + print("Could not find any files ending with '.dfinish'. Check that the script is being run from the correct " + "directory. Check that the code was compiled with the correct flags") + exit(-1) + + +def find_files(): + tu = [] + manual = [] + all_files = [] + for root, directories, filenames in os.walk(dir): + for filename in filenames: + all_files.append(os.path.join(root,filename)) + + files = [f for f in all_files if os.path.isfile(f) and f.endswith(rtl_ext)] + for f in files: + base = f[0:-len(rtl_ext)] + short_base = base[0:base.rindex(".")] + if short_base + su_ext in all_files and short_base + obj_ext in all_files: + tu.append(base) + print('Reading: {}{}, {}{}, {}{}'.format(base, rtl_ext, short_base, su_ext, short_base, obj_ext)) + + files = [f for f in all_files if os.path.isfile(f) and f.endswith(manual_ext)] + for f in files: + manual.append(f) + print('Reading: {}'.format(f)) + + # Print some diagnostic messages + if not tu: + print("Could not find any translation units to analyse") + exit(-1) + + return tu, manual + + +def main(): + + # Find the appropriate RTL extension + find_rtl_ext() + + # Find all input files + call_graph = {'locals': {}, 'globals': {}, 'weak': {}} + tu_list, manual_list = find_files() + + # Read the input files + for tu in tu_list: + read_obj(tu, call_graph) # This must be first + + for fxn in call_graph['weak'].values(): + if fxn['name'] not in call_graph['globals'].keys(): + call_graph['globals'][fxn['name']] = fxn + + for tu in tu_list: + read_rtl(tu, call_graph) + for tu in tu_list: + read_su(tu, call_graph) + + # Read manual files + for m in manual_list: + read_manual(m, call_graph) + + # Validate Data + validate_all_data(call_graph) + + # Resolve All Function Calls + resolve_all_calls(call_graph) + + # Calculate Worst Case Stack For Each Function + calc_all_wcs(call_graph) + + # Print A Nice Message With Each Function and the WCS + print_all_fxns(call_graph) + + + + +def ThreadStackStaticAnalysis(env): + print('Start thread stack static analysis...') + + import rtconfig + read_elf_path = rtconfig.EXEC_PATH + r'\readelf.exe' + main() + + print('\nThread stack static analysis done!') + return
\ No newline at end of file diff --git a/tools/building.py b/tools/building.py index 2ddeb9669b..ba995af278 100644 --- a/tools/building.py +++ b/tools/building.py @@ -208,7 +208,12 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ AddOption('--target', dest = 'target', type = 'string', - help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse') + help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse/codelite') + AddOption('--stackanalysis', + dest = 'stackanalysis', + action = 'store_true', + default = False, + help = 'thread stack static analysis') AddOption('--genconfig', dest = 'genconfig', action = 'store_true', @@ -251,7 +256,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ 'cdk':('gcc', 'gcc'), 'makefile':('gcc', 'gcc'), 'eclipse':('gcc', 'gcc'), - 'ses' : ('gcc', 'gcc')} + 'ses' : ('gcc', 'gcc'), + 'codelite' : ('gcc', 'gcc')} tgt_name = GetOption('target') if tgt_name: @@ -270,9 +276,6 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ except KeyError: print ('Unknow target: '+ tgt_name+'. Avaible targets: ' +', '.join(tgt_dict.keys())) sys.exit(1) - elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \ - and rtconfig.PLATFORM == 'gcc': - AddDepend('RT_USING_MINILIBC') # auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed if not os.path.exists(rtconfig.EXEC_PATH): @@ -363,6 +366,11 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ genconfig() exit(0) + if GetOption('stackanalysis'): + from WCS import ThreadStackStaticAnalysis + ThreadStackStaticAnalysis(Env) + exit(0) + if env['PLATFORM'] != 'win32': AddOption('--menuconfig', dest = 'menuconfig', @@ -862,6 +870,10 @@ def GenTargetProject(program = None): if GetOption('target') == 'eclipse': from eclipse import TargetEclipse TargetEclipse(Env, GetOption('reset-project-config'), GetOption('project-name')) + + if GetOption('target') == 'codelite': + from codelite import TargetCodelite + TargetCodelite(Projects, program) def EndBuilding(target, program = None): diff --git a/tools/codelite.py b/tools/codelite.py new file mode 100644 index 0000000000..9b2060dfa5 --- /dev/null +++ b/tools/codelite.py @@ -0,0 +1,215 @@ +# +# File : codelite.py +# This file is part of RT-Thread RTOS +# COPYRIGHT (C) 2006 - 2020, 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 +# 2020-10-14 LiuMin Add copyright information +# + +import os +import sys +import string +import building +import rtconfig + +import xml.etree.ElementTree as etree +from xml.etree.ElementTree import SubElement +from utils import _make_path_relative +from utils import xml_indent + +import utils + +fs_encoding = sys.getfilesystemencoding() + +def CLSetCFlags(root, flags): + node = root.find('Settings').find('Configuration').find('Compiler') + node.attrib['C_Options'] = flags + +def CLSetCxxFlags(root, flags): + node = root.find('Settings').find('Configuration').find('Compiler') + node.attrib['Options'] = flags + +def CLSetAsFlags(root, flags): + node = root.find('Settings').find('Configuration').find('Compiler') + node.attrib['Assembler'] = flags + +def CLAddIncludePath(root, path): + node = root.find('Settings').find('Configuration').find('Compiler') + node = SubElement(node, 'IncludePath') + node.attrib['Value'] = path + +def CLAddPreprocessor(root, value): + node = root.find('Settings').find('Configuration').find('Compiler') + node = SubElement(node, 'Preprocessor') + node.attrib['Value'] = value + + +def CLSetLdFlags(root, flags): + node = root.find('Settings').find('Configuration').find('Linker') + node.attrib['Options'] = flags + +def CLAddLibrary_path(root, path): + node = root.find('Settings').find('Configuration').find('Linker') + node = SubElement(node, 'LibraryPath') + node.attrib['Value'] = path + +def CLAddLibrary(root, lib): + node = root.find('Settings').find('Configuration').find('Linker') + node = SubElement(node, 'Library') + node.attrib['Value'] = lib + +def CLAddFile(root, file_path): + file_path = file_path.replace('\\', '/') + + dir_list = file_path.split('/') + dir_list.pop() + if not len(dir_list): + dir_list.append(os.path.abspath('.').replace('\\', '/').split('/')[-1]) + + parent = root + for dir_name in dir_list: + if dir_name == '..': + continue + + node = None + nodes = parent.findall('VirtualDirectory') + for iter in nodes: + if iter.attrib['Name'] == dir_name: + node = iter + break + if node is None: + node = SubElement(parent, 'VirtualDirectory') + node.attrib['Name'] = dir_name + parent = node + + if parent != root: + node = SubElement(parent, 'File') + node.attrib['Name'] = file_path + +def CLAddHeaderFiles(parent, program, project_path): + utils.source_ext = [] + utils.source_ext = ["h"] + for item in program: + utils.walk_children(item) + utils.source_list.sort() + + for f in utils.source_list: + path = _make_path_relative(project_path, f) + CLAddFile(parent, path) + +def CLAddCFiles(parent, files, project_path): + for f in files: + fn = f.rfile() + name = fn.name + path = os.path.dirname(fn.abspath) + + path = _make_path_relative(project_path, path) + path = os.path.join(path, name) + CLAddFile(parent, path) + + + +def CLGenWorkspace(project_name, project_path): + if os.path.isfile('codelite_template.workspace'): + tree = etree.parse('codelite_template.workspace') + else: + tree = etree.parse(os.path.join(os.path.dirname(__file__), 'codelite_template.workspace')) + + root = tree.getroot() + root.attrib['Name'] = project_name + + node = root.find('Project') + node.attrib['Name'] = project_name + node.attrib['Path'] = project_name + '.project' + + node = root.find('BuildMatrix').find('WorkspaceConfiguration').find('Project') + node.attrib['Name'] = project_name + + out = open(project_name + '.workspace', 'w') + out.write('<?xml version="1.0" encoding="UTF-8"?>\n') + xml_indent(root) + out.write(etree.tostring(root, encoding='utf-8')) + out.close() + +def TargetCodelite(script, program): + project_name = os.path.abspath('.').replace('\\', '/').split('/')[-1] + #project_name.replace('-', '_') + project_path = os.path.abspath('.') + CLGenWorkspace(project_name, project_path) + + if os.path.isfile('codelite_template.project'): + tree = etree.parse('codelite_template.project') + else: + tree = etree.parse(os.path.join(os.path.dirname(__file__), 'codelite_template.project')) + + root = tree.getroot() + root.attrib['Name'] = project_name + + out = open(project_name + '.project', 'w') + out.write('<?xml version="1.0" encoding="UTF-8"?>\n') + + # add files + for group in script: + CLAddCFiles(root, group['src'], project_path) + # add header file + CLAddHeaderFiles(root, program, project_path) + + # SECTION 2. + # write head include path + + if 'CPPPATH' in building.Env: + cpp_path = building.Env['CPPPATH'] + paths = set() + for path in cpp_path: + inc = _make_path_relative(project_path, os.path.normpath(path)) + paths.add(inc) #.replace('\\', '/') + + paths = [i for i in paths] + paths.sort() + + # write include path, definitions + for elem in tree.iter(tag='Compiler'): + break + + for path in paths: + CLAddIncludePath(root, path) + + + #print building.Env.get('LIBPATH', []) + #print building.Env.get('LIBS', []) + + CLSetCFlags(root, building.Env.get('CCFLAGS', [])) + CLSetCxxFlags(root, building.Env.get('CCFLAGS', [])) + + asflags = building.Env.get('ASFLAGS', []) + asflags = asflags.replace('-ffunction-sections', '') + asflags = asflags.replace('-fdata-sections', '') + asflags = asflags.replace('-x', '') + asflags = asflags.replace('-Wa,', '') + asflags = asflags.replace('assembler-with-cpp', '') + CLSetAsFlags(root, asflags) + CLSetLdFlags(root, building.Env.get('LINKFLAGS', [])) + + for macro in building.Env.get('CPPDEFINES', []): + for d in macro: + CLAddPreprocessor(root, d) + + xml_indent(root) + out.write(etree.tostring(root, encoding='utf-8')) + out.close() diff --git a/tools/codelite_template.project b/tools/codelite_template.project new file mode 100644 index 0000000000..0aa0ecc4c7 --- /dev/null +++ b/tools/codelite_template.project @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="UTF-8"?> +<CodeLite_Project Name="project" Version="11000" InternalType=""> + <Description/> + <Dependencies/> + <Settings Type="Executable"> + <GlobalSettings> + <Compiler Options="" C_Options="" Assembler=""> + <IncludePath Value="."/> + </Compiler> + <Linker Options=""> + <LibraryPath Value="."/> + </Linker> + <ResourceCompiler Options=""/> + </GlobalSettings> + <Configuration Name="Debug" CompilerType="Cross GCC ( arm-none-eabi )" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append"> + <Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0"> + </Compiler> + <Linker Options="" Required="yes"> + </Linker> + <ResourceCompiler Options="" Required="no"/> + <General OutputFile="$(IntermediateDirectory)/$(ProjectName).elf" IntermediateDirectory="$(ConfigurationName)" Command="$(OutputFile)" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/> + <BuildSystem Name="Default"/> + <Environment EnvVarSetName="<Use Defaults>" DbgSetName="<Use Defaults>"> + <![CDATA[]]> + </Environment> + <Debugger IsRemote="yes" RemoteHostName="127.0.0.1" RemoteHostPort="2331" DebuggerPath="" IsExtended="no"> + <DebuggerSearchPaths/> + <PostConnectCommands>monitor reset +monitor halt +load</PostConnectCommands> + <StartupCommands/> + </Debugger> + <PreBuild/> + <PostBuild> + <Command Enabled="yes">arm-none-eabi-objcopy -O ihex $(IntermediateDirectory)/$(ProjectName).elf $(IntermediateDirectory)/$(ProjectName).hex</Command> + <Command Enabled="yes">arm-none-eabi-objcopy -I ihex -O binary $(IntermediateDirectory)/$(ProjectName).hex $(IntermediateDirectory)/$(ProjectName).bin</Command> + <Command Enabled="yes">arm-none-eabi-size $(IntermediateDirectory)/$(ProjectName).elf</Command> + </PostBuild> + <CustomBuild Enabled="no"> + <RebuildCommand/> + <CleanCommand/> + <BuildCommand/> + <PreprocessFileCommand/> + <SingleFileCommand/> + <MakefileGenerationCommand/> + <ThirdPartyToolName/> + <WorkingDirectory/> + </CustomBuild> + <AdditionalRules> + <CustomPostBuild/> + <CustomPreBuild/> + </AdditionalRules> + <Completion EnableCpp11="no" EnableCpp14="no"> + <ClangCmpFlagsC/> + <ClangCmpFlags/> + <ClangPP/> + <SearchPaths/> + </Completion> + </Configuration> + </Settings> +</CodeLite_Project> diff --git a/tools/codelite_template.workspace b/tools/codelite_template.workspace new file mode 100644 index 0000000000..8f06e0ce2b --- /dev/null +++ b/tools/codelite_template.workspace @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<CodeLite_Workspace Name="project" Database="" Version="10000"> + <Project Name="project" Path="project.project" Active="Yes"/> + <BuildMatrix> + <WorkspaceConfiguration Name="Debug" Selected="yes"> + <Environment/> + <Project Name="project" ConfigName="Debug"/> + </WorkspaceConfiguration> + </BuildMatrix> +</CodeLite_Workspace> diff --git a/tools/eclipse.py b/tools/eclipse.py index ef546fb15a..4f3cda92b8 100644 --- a/tools/eclipse.py +++ b/tools/eclipse.py @@ -9,23 +9,21 @@ # 2019-04-15 armink fix project update error # -import os -import sys import glob - -from utils import * -from utils import _make_path_relative -from utils import xml_indent - import xml.etree.ElementTree as etree from xml.etree.ElementTree import SubElement +import rt_studio from building import * +from utils import * +from utils import _make_path_relative +from utils import xml_indent -MODULE_VER_NUM = 3 +MODULE_VER_NUM = 6 source_pattern = ['*.c', '*.cpp', '*.cxx', '*.s', '*.S', '*.asm'] + def OSPath(path): import platform @@ -60,9 +58,12 @@ def CollectPaths(paths): all_paths = list(set(all_paths)) return sorted(all_paths) + ''' Collect all of files under paths ''' + + def CollectFiles(paths, pattern): files = [] for path in paths: @@ -75,6 +76,7 @@ def CollectFiles(paths, pattern): return sorted(files) + def CollectAllFilesinPath(path, pattern): files = [] @@ -93,11 +95,14 @@ def CollectAllFilesinPath(path, pattern): files = files + CollectAllFilesinPath(os.path.join(path, item), pattern) return files + ''' Exclude files from infiles ''' + + def ExcludeFiles(infiles, files): - in_files = set([OSPath(file) for file in infiles]) + in_files = set([OSPath(file) for file in infiles]) exl_files = set([OSPath(file) for file in files]) exl_files = in_files - exl_files @@ -136,14 +141,29 @@ def ConverToRttEclipsePathFormat(path): def IsRttEclipsePathFormat(path): if path.startswith(rtt_path_prefix): return True - else : + else: return False - - + + +# all libs added by scons should be ends with five whitespace as a flag +rtt_lib_flag = 5 * " " + + +def ConverToRttEclipseLibFormat(lib): + return str(lib) + str(rtt_lib_flag) + + +def IsRttEclipseLibFormat(path): + if path.endswith(rtt_lib_flag): + return True + else: + return False + + def IsCppProject(): return GetDepend('RT_USING_CPLUSPLUS') - + def HandleToolOption(tools, env, project, reset): is_cpp_prj = IsCppProject() BSP_ROOT = os.path.abspath(env['BSP_ROOT']) @@ -189,7 +209,7 @@ def HandleToolOption(tools, env, project, reset): linker_script_option = option elif option.get('id').find('linker.nostart') != -1: linker_nostart_option = option - elif option.get('id').find('linker.libs') != -1 and env.has_key('LIBS'): + elif option.get('id').find('linker.libs') != -1: linker_libs_option = option elif option.get('id').find('linker.paths') != -1 and env.has_key('LIBPATH'): linker_paths_option = option @@ -288,16 +308,22 @@ def HandleToolOption(tools, env, project, reset): else: option.set('value', 'false') # update libs - if linker_libs_option is not None : + if linker_libs_option is not None: option = linker_libs_option # remove old libs for item in option.findall('listOptionValue'): - option.remove(item) + if IsRttEclipseLibFormat(item.get("value")): + option.remove(item) + # add new libs - for lib in env['LIBS']: - SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': lib}) + if env.has_key('LIBS'): + for lib in env['LIBS']: + formatedLib = ConverToRttEclipseLibFormat(lib) + SubElement(option, 'listOptionValue', { + 'builtIn': 'false', 'value': formatedLib}) + # update lib paths - if linker_paths_option is not None : + if linker_paths_option is not None: option = linker_paths_option # remove old lib paths for item in option.findall('listOptionValue'): @@ -338,7 +364,7 @@ def UpdateProjectStructure(env, prj_name): out = open('.project', 'w') out.write('<?xml version="1.0" encoding="UTF-8"?>\n') xml_indent(root) - out.write(etree.tostring(root, encoding = 'utf-8')) + out.write(etree.tostring(root, encoding='utf-8')) out.close() return @@ -348,12 +374,13 @@ def GenExcluding(env, project): rtt_root = os.path.abspath(env['RTT_ROOT']) bsp_root = os.path.abspath(env['BSP_ROOT']) coll_dirs = CollectPaths(project['DIRS']) - all_paths = [OSPath(path) for path in coll_dirs] + all_paths_temp = [OSPath(path) for path in coll_dirs] + all_paths = [] - # remove unused path - for path in all_paths: - if not path.startswith(rtt_root) and not path.startswith(bsp_root): - all_paths.remove(path) + # add used path + for path in all_paths_temp: + if path.startswith(rtt_root) or path.startswith(bsp_root): + all_paths.append(path) if bsp_root.startswith(rtt_root): # bsp folder is in the RT-Thread root folder, such as the RT-Thread source code on GitHub @@ -363,8 +390,8 @@ def GenExcluding(env, project): check_path = [] exclude_paths = [] # analyze the primary folder which relative to BSP_ROOT and in all_paths - for path in all_paths : - if path.startswith(bsp_root) : + for path in all_paths: + if path.startswith(bsp_root): folders = RelativeProjectPath(env, path).split('\\') if folders[0] != '.' and '\\' + folders[0] not in check_path: check_path += ['\\' + folders[0]] @@ -399,16 +426,16 @@ def GenExcluding(env, project): env['ExPaths'] = exclude_paths env['ExFiles'] = exclude_files - return exclude_paths + exclude_files + return exclude_paths + exclude_files def RelativeProjectPath(env, path): project_root = os.path.abspath(env['BSP_ROOT']) rtt_root = os.path.abspath(env['RTT_ROOT']) - + if path.startswith(project_root): return _make_path_relative(project_root, path) - + if path.startswith(rtt_root): return 'rt-thread/' + _make_path_relative(rtt_root, path) @@ -426,9 +453,9 @@ def HandleExcludingOption(entry, sourceEntries, excluding): value = '' for item in old_excluding: - if item.startswith('//') : + if item.startswith('//'): old_excluding.remove(item) - else : + else: if value == '': value = item else: @@ -477,14 +504,50 @@ def UpdateCproject(env, project, excluding, reset, prj_name): out.close() -def TargetEclipse(env, reset = False, prj_name = None): +def TargetEclipse(env, reset=False, prj_name=None): global source_pattern print('Update eclipse setting...') + # generate cproject file if not os.path.exists('.cproject'): - print('no eclipse CDT project found!') - return + if rt_studio.gen_cproject_file(os.path.abspath(".cproject")) is False: + print('Fail!') + return + + # generate project file + if not os.path.exists('.project'): + if rt_studio.gen_project_file(os.path.abspath(".project")) is False: + print('Fail!') + return + + # generate projcfg.ini file + if not os.path.exists('.settings/projcfg.ini'): + # if search files with uvprojx or uvproj suffix + file = "" + items = os.listdir(".") + if len(items) > 0: + for item in items: + if item.endswith(".uvprojx") or item.endswith(".uvproj"): + file = os.path.abspath(item) + break + chip_name = rt_studio.get_mcu_info(file) + if rt_studio.gen_projcfg_ini_file(chip_name, prj_name, os.path.abspath(".settings/projcfg.ini")) is False: + print('Fail!') + return + + # enable lowwer .s file compiled in eclipse cdt + if not os.path.exists('.settings/org.eclipse.core.runtime.prefs'): + if rt_studio.gen_org_eclipse_core_runtime_prefs( + os.path.abspath(".settings/org.eclipse.core.runtime.prefs")) is False: + print('Fail!') + return + + # add clean2 target to fix issues when files too many + if not os.path.exists('makefile.targets'): + if rt_studio.gen_makefile_targets(os.path.abspath("makefile.targets")) is False: + print('Fail!') + return project = ProjectInfo(env) diff --git a/tools/menuconfig.py b/tools/menuconfig.py index b49a2e7120..c0a33718de 100644 --- a/tools/menuconfig.py +++ b/tools/menuconfig.py @@ -27,6 +27,8 @@ import os import re import sys import shutil +import hashlib +import operator # make rtconfig.h from .config @@ -38,7 +40,6 @@ def is_pkg_special_config(config_str): return True return False - def mk_rtconfig(filename): try: config = open(filename, 'r') @@ -97,6 +98,14 @@ def mk_rtconfig(filename): rtconfig.write('#endif\n') rtconfig.close() + +def get_file_md5(file): + MD5 = hashlib.new('md5') + with open(file, 'r') as fp: + MD5.update(fp.read().encode('utf8')) + fp_md5 = MD5.hexdigest() + return fp_md5 + def config(): mk_rtconfig('.config') @@ -219,22 +228,22 @@ def menuconfig(RTT_ROOT): os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages') fn = '.config' - - if os.path.isfile(fn): - mtime = os.path.getmtime(fn) - else: - mtime = -1 + fn_old = '.config.old' kconfig_cmd = os.path.join(RTT_ROOT, 'tools', 'kconfig-frontends', 'kconfig-mconf') os.system(kconfig_cmd + ' Kconfig') if os.path.isfile(fn): - mtime2 = os.path.getmtime(fn) + if os.path.isfile(fn_old): + diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old)) + else: + diff_eq = False else: - mtime2 = -1 + sys.exit(-1) # make rtconfig.h - if mtime != mtime2: + if diff_eq == False: + shutil.copyfile(fn, fn_old) mk_rtconfig(fn) # guiconfig for windows and linux @@ -249,22 +258,22 @@ def guiconfig(RTT_ROOT): os.environ['PKGS_ROOT'] = os.path.join(env_dir, 'packages') fn = '.config' - - if os.path.isfile(fn): - mtime = os.path.getmtime(fn) - else: - mtime = -1 + fn_old = '.config.old' sys.argv = ['guiconfig', 'Kconfig']; pyguiconfig._main() if os.path.isfile(fn): - mtime2 = os.path.getmtime(fn) + if os.path.isfile(fn_old): + diff_eq = operator.eq(get_file_md5(fn), get_file_md5(fn_old)) + else: + diff_eq = False else: - mtime2 = -1 + sys.exit(-1) # make rtconfig.h - if mtime != mtime2: + if diff_eq == False: + shutil.copyfile(fn, fn_old) mk_rtconfig(fn) diff --git a/tools/rt_studio.py b/tools/rt_studio.py new file mode 100644 index 0000000000..414b911645 --- /dev/null +++ b/tools/rt_studio.py @@ -0,0 +1,351 @@ +import os +import re +from string import Template + +import rtconfig +import shutil + +# version +MODULE_VER_NUM = 1 + +cproject_temp = """<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage"> + <storageModule moduleId="org.eclipse.cdt.core.settings"> + <cconfiguration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.553091094"> + <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.553091094" moduleId="org.eclipse.cdt.core.settings" name="Debug"> + <externalSettings/> + <extensions> + <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/> + <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/> + <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/> + </extensions> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <configuration artifactName="rtthread" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="${cross_rm} -rf" description="" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.553091094" name="Debug" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug"> + <folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.553091094." name="/" resourcePath=""> + <toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug.1201710416" name="ARM Cross GCC" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createflash.251260409" name="Create flash image" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createflash" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createlisting.1365878149" name="Create extended listing" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.createlisting" useByScannerDiscovery="false"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize.709136944" name="Print size" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.addtools.printsize" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.1986446770" name="Optimization Level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.none" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength.1312975261" name="Message length (-fmessage-length=0)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.messagelength" useByScannerDiscovery="true" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar.1538128212" name="'char' is signed (-fsigned-char)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.signedchar" useByScannerDiscovery="true" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections.2136804218" name="Function sections (-ffunction-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.functionsections" useByScannerDiscovery="true" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.datasections.244767666" name="Data sections (-fdata-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.datasections" useByScannerDiscovery="true" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.level.1055848773" name="Debug level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.level" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.level.default" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format.501941135" name="Debug format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.debugging.format.dwarf2" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name.1696308067" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.name" useByScannerDiscovery="false" value="GNU Tools for ARM Embedded Processors" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.1558403188" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.architecture" useByScannerDiscovery="false" value="ilg.gnuarmeclipse.managedbuild.cross.option.architecture.arm" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family.749415257" name="ARM family" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.family" useByScannerDiscovery="false" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.mcpu.cortex-m4" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.2114153533" name="Instruction set" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset" useByScannerDiscovery="false" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.instructionset.thumb" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix.1600865811" name="Prefix" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.prefix" useByScannerDiscovery="false" value="arm-none-eabi-" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.c.1109963929" name="C compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.c" useByScannerDiscovery="false" value="gcc" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.cpp.1040883831" name="C++ compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.cpp" useByScannerDiscovery="false" value="g++" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.ar.1678200391" name="Archiver" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.ar" useByScannerDiscovery="false" value="ar" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.objcopy.1171840296" name="Hex/Bin converter" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.objcopy" useByScannerDiscovery="false" value="objcopy" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.objdump.342604837" name="Listing generator" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.objdump" useByScannerDiscovery="false" value="objdump" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.size.898269225" name="Size command" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.size" useByScannerDiscovery="false" value="size" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.make.2016398076" name="Build command" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.make" useByScannerDiscovery="false" value="make" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.command.rm.1606171496" name="Remove command" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.command.rm" useByScannerDiscovery="false" value="rm" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.id.540792084" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.toolchain.id" useByScannerDiscovery="false" value="1287942917" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.architecture.430121817" name="Architecture" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.architecture" useByScannerDiscovery="false" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.arch.none" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.fpu.abi.966735324" name="Float ABI" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.fpu.abi" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.fpu.abi.hard" valueType="enumerated"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.allwarn.1381561249" name="Enable all common warnings (-Wall)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.warnings.allwarn" useByScannerDiscovery="true" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.target.other.2041717463" name="Other target flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.target.other" useByScannerDiscovery="true" value="" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.fpu.unit.1463655269" name="FPU Type" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.fpu.unit" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.arm.target.fpu.unit.fpv4spd16" valueType="enumerated"/> + <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform.1798638225" isAbstract="false" osList="all" superClass="ilg.gnuarmeclipse.managedbuild.cross.targetPlatform"/> + <builder buildPath="${workspace_loc:/${ProjName}/Debug" cleanBuildTarget="clean2" id="ilg.gnuarmeclipse.managedbuild.cross.builder.1736709688" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="ilg.gnuarmeclipse.managedbuild.cross.builder"/> + <tool commandLinePattern="${COMMAND} ${FLAGS} -c ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.1810966071" name="GNU ARM Cross Assembler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor.1072524326" name="Use preprocessor" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.usepreprocessor" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.include.paths.161242639" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.include.paths" useByScannerDiscovery="true"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs.1521934876" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs" useByScannerDiscovery="true"/> + <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.flags.1325367962" name="Assembler flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.flags" useByScannerDiscovery="false" valueType="stringList"> + <listOptionValue builtIn="false" value="-mimplicit-it=thumb"/> + </option> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.other.647856572" name="Other assembler flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.assembler.other" useByScannerDiscovery="false" value="a_misc_flag" valueType="string"/> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input.1843333483" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.assembler.input"/> + </tool> + <tool commandLinePattern="${COMMAND} ${FLAGS} -c ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.1570350559" name="GNU ARM Cross C Compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths.634882052" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.paths" useByScannerDiscovery="true"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs.100549972" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.defs" useByScannerDiscovery="true"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.other.2133065240" name="Other compiler flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.other" useByScannerDiscovery="true" value="c_misc_flag" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.files.714348818" name="Include files (-include)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.compiler.include.files" useByScannerDiscovery="true"/> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input.992053063" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input"/> + </tool> + <tool commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.869072473" name="Cross ARM C Linker" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.gcsections.1167322178" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.nostart.351692886" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.nostart" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.nostdlibs.1009243715" name="No startup or default libs (-nostdlib)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.nostdlibs" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.nodeflibs.2016026082" name="Do not use default libraries (-nodefaultlibs)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.nodeflibs" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.usenewlibnano.923990336" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.usenewlibnano" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option defaultValue="true" id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.shared.548869459" name="Shared (-shared)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.shared" useByScannerDiscovery="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.scriptfile.1818777301" name="Script files (-T)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.scriptfile" useByScannerDiscovery="false"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.libs.1135656995" name="Libraries (-l)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.libs" useByScannerDiscovery="false"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.paths.36884122" name="Library search path (-L)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.paths" useByScannerDiscovery="false"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.other.396049466" name="Other linker flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.other" useByScannerDiscovery="false" value="c_link_misc_flag" valueType="string"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.cref.1645737861" name="Cross reference (-Xlinker --cref)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.c.linker.cref" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input.334732222" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.c.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.linker.1601059928" name="GNU ARM Cross C++ Linker" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.linker"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.gcsections.437759352" name="Remove unused sections (-Xlinker --gc-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.gcsections" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.scriptfile.1101974459" name="Script files (-T)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.scriptfile" useByScannerDiscovery="false"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.cref.2007675975" name="Cross reference (-Xlinker --cref)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.cref" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.usenewlibnano.2105838438" name="Use newlib-nano (--specs=nano.specs)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.usenewlibnano" useByScannerDiscovery="false" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.libs.934137837" name="Libraries (-l)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.libs" useByScannerDiscovery="false"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.nostart.2118356996" name="Do not use standard start files (-nostartfiles)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.nostart" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.nodeflibs.1427884346" name="Do not use default libraries (-nodefaultlibs)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.nodeflibs" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.nostdlibs.1433863653" name="No startup or default libs (-nostdlib)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.nostdlibs" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.printgcsections.1387745410" name="Print removed sections (-Xlinker --print-gc-sections)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.printgcsections" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.strip.1230158061" name="Omit all symbol information (-s)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.strip" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.printmap.1307581821" name="Print link map (-Xlinker --print-map)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.printmap" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.useprintffloat.960778920" name="Use float with nano printf (-u _printf_float)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.useprintffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.usescanffloat.637205035" name="Use float with nano scanf (-u _scanf_float)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.usescanffloat" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.usenewlibnosys.1948314201" name="Do not use syscalls (--specs=nosys.specs)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.usenewlibnosys" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.verbose.273162112" name="Verbose (-v)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.verbose" useByScannerDiscovery="false" value="false" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.paths.1399535143" name="Library search path (-L)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.paths" useByScannerDiscovery="false"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.other.882307902" name="Other linker flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.linker.other" useByScannerDiscovery="false" value="cpp_link_misc_flag" valueType="string"/> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.linker.input.262373798" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.linker.input"> + <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> + <additionalInput kind="additionalinput" paths="$(LIBS)"/> + </inputType> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.archiver.506412204" name="GNU ARM Cross Archiver" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.archiver"/> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.createflash.1461589245" name="GNU ARM Cross Create Flash Image" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.createflash"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createflash.choice.1937707052" name="Output file format (-O)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createflash.choice" useByScannerDiscovery="false" value="ilg.gnuarmeclipse.managedbuild.cross.option.createflash.choice.binary" valueType="enumerated"/> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.createlisting.82359725" name="GNU ARM Cross Create Listing" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.createlisting"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.source.601724476" name="Display source (--source|-S)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.source" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.allheaders.692505279" name="Display all headers (--all-headers|-x)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.allheaders" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.demangle.97345172" name="Demangle names (--demangle|-C)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.demangle" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.linenumbers.1342893377" name="Display line numbers (--line-numbers|-l)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.linenumbers" value="true" valueType="boolean"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.wide.1533725981" name="Wide lines (--wide|-w)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.createlisting.wide" value="true" valueType="boolean"/> + </tool> + <tool id="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize.1073550295" name="GNU ARM Cross Print Size" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.printsize"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format.946451386" name="Size format" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.printsize.format" useByScannerDiscovery="false"/> + </tool> + <tool commandLinePattern="${COMMAND} ${FLAGS} -c ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.1302177015" name="GNU ARM Cross C++ Compiler" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler"> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.defs.704468062" name="Defined symbols (-D)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.defs" useByScannerDiscovery="true"/> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.include.paths.302877723" name="Include paths (-I)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.include.paths" useByScannerDiscovery="true"/> + <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.include.files.343249373" name="Include files (-include)" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"> + <listOptionValue builtIn="false" value=""${workspace_loc:/${ProjName}/rtconfig_preinc.h}""/> + </option> + <option id="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.other.465079095" name="Other compiler flags" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.cpp.compiler.other" useByScannerDiscovery="true" value="cpp_misc_flag" valueType="string"/> + <inputType id="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.input.45918001" superClass="ilg.gnuarmeclipse.managedbuild.cross.tool.cpp.compiler.input"/> + </tool> + </toolChain> + </folderInfo> + <sourceEntries> + <entry excluding="|" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/> + </sourceEntries> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/> + </cconfiguration> + </storageModule> + <storageModule moduleId="cdtBuildSystem" version="4.0.0"> + <project id="qemu-vexpress-a9.ilg.gnuarmeclipse.managedbuild.cross.target.elf.860020518" name="Executable" projectType="ilg.gnuarmeclipse.managedbuild.cross.target.elf"/> + </storageModule> + <storageModule moduleId="scannerConfiguration"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + <scannerConfigBuildInfo instanceId="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.553091094;ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.553091094.;ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.1570350559;ilg.gnuarmeclipse.managedbuild.cross.tool.c.compiler.input.992053063"> + <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/> + </scannerConfigBuildInfo> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/> + <storageModule moduleId="refreshScope" versionNumber="2"> + <configuration configurationName="Debug"> + <resource resourceType="PROJECT" workspacePath="/f429_tmp"/> + </configuration> + </storageModule> + <storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/> + <storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"> + <doc-comment-owner id="org.eclipse.cdt.ui.doxygen"> + <path value=""/> + </doc-comment-owner> + </storageModule> +</cproject>""" + +project_temp = """<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>__project_name_flag__</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> + <triggers>clean,full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> + <triggers>full,incremental,</triggers> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.cdt.core.cnature</nature> + <nature>org.rt-thread.studio.rttnature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> + <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> + </natures> +</projectDescription>""" + +projcfg_ini_temp = """#RT-Thread Studio Project Configuration +#Sat Jan 16 15:18:32 CST 2021 +project_type=rtt +chip_name=${chip_name} +cpu_name=None +target_freq= +clock_source= +dvendor_name= +rx_pin_name= +rtt_path= +source_freq= +csp_path= +sub_series_name= +selected_rtt_version=latest +cfg_version=v3.0 +tool_chain=gcc +uart_name= +tx_pin_name= +rtt_nano_path= +output_project_path= +hardware_adapter=J-Link +project_name=${project_name}""" + +eclipse_core_runtime_temp = """content-types/enabled=true +content-types/org.eclipse.cdt.core.asmSource/file-extensions=s +eclipse.preferences.version=1""" + +makefile_targets_temp = """clean2: +\t-$(RM) $(CC_DEPS)$(C++_DEPS)$(C_UPPER_DEPS)$(CXX_DEPS)$(SECONDARY_FLASH)$(SECONDARY_SIZE)$(ASM_DEPS)$(S_UPPER_DEPS)$(C_DEPS)$(CPP_DEPS) +\t-$(RM) $(OBJS) *.elf +\t-@echo ' ' + +*.elf: $(wildcard ../linkscripts/*/*.lds) $(wildcard ../linkscripts/*/*/*.lds)""" + + +def get_mcu_info(uvproj_file_path): + if os.path.exists(uvproj_file_path): + with open(uvproj_file_path, mode='r') as f: + data = f.read() + result = re.search("<Device>(.*)</Device>", data) + if result: + return result.group(1) + else: + return "unknown" + else: + return "unknown" + + +def gen_makefile_targets(output_file_path): + try: + w_str = makefile_targets_temp + dir_name = os.path.dirname(output_file_path) + if not os.path.exists(dir_name): + os.makedirs(dir_name) + with open(output_file_path, 'w') as f: + f.write(w_str) + return True + except Exception as e: + print(e) + return False + + +def gen_org_eclipse_core_runtime_prefs(output_file_path): + try: + w_str = eclipse_core_runtime_temp + dir_name = os.path.dirname(output_file_path) + if not os.path.exists(dir_name): + os.makedirs(dir_name) + with open(output_file_path, 'w') as f: + f.write(w_str) + return True + except Exception as e: + print(e) + return False + + +def gen_cproject_file(output_file_path): + template_file_path = os.path.join(os.path.dirname(output_file_path), "template.cproject") + if os.path.exists(template_file_path): + try: + shutil.copy(template_file_path, output_file_path) + except Exception as e: + print(e) + return True + else: + CFLAGS = rtconfig.CFLAGS + AFLAGS = rtconfig.AFLAGS + LFLAGS = rtconfig.LFLAGS + if 'CXXFLAGS' in dir(rtconfig): + CXXFLAGS = rtconfig.CXXFLAGS + else: + CXXFLAGS = "" + + if "-T" in LFLAGS: + items = str(LFLAGS).split() + t_index = items.index("-T") + items[t_index] = "" + items[t_index + 1] = "" + LFLAGS = " ".join(items) + + try: + w_str = cproject_temp + if "a_misc_flag" in w_str: + w_str = w_str.replace("a_misc_flag", AFLAGS) + if "c_misc_flag" in w_str: + w_str = w_str.replace("c_misc_flag", CFLAGS) + if "cpp_misc_flag" in w_str: + w_str = w_str.replace("cpp_misc_flag", CXXFLAGS) + if "c_link_misc_flag" in w_str: + w_str = w_str.replace("c_link_misc_flag", LFLAGS) + if "cpp_link_misc_flag" in w_str: + w_str = w_str.replace("cpp_link_misc_flag", LFLAGS) + + dir_name = os.path.dirname(output_file_path) + if not os.path.exists(dir_name): + os.makedirs(dir_name) + with open(output_file_path, 'w') as f: + f.write(w_str) + return True + except Exception as e: + return False + + +def gen_project_file(output_file_path): + try: + w_str = project_temp + dir_name = os.path.dirname(output_file_path) + if not os.path.exists(dir_name): + os.makedirs(dir_name) + with open(output_file_path, 'w') as f: + f.write(w_str) + return True + except Exception as e: + return False + + +def gen_projcfg_ini_file(chip_name, project_name, output_file_path): + try: + projcfg_file_tmp = Template(projcfg_ini_temp) + w_str = projcfg_file_tmp.substitute(project_name=project_name, + chip_name=(chip_name)) + + dir_name = os.path.dirname(output_file_path) + if not os.path.exists(dir_name): + os.makedirs(dir_name) + with open(output_file_path, 'w') as f: + f.write(w_str) + return True + except Exception as e: + return False diff --git a/tools/rtthread.mk b/tools/rtthread.mk index fdc96d4156..7cf018cb52 100644 --- a/tools/rtthread.mk +++ b/tools/rtthread.mk @@ -55,6 +55,20 @@ $(if $(strip $(LOCALS)),$(eval $(LOCALS): $(S_SRC) @$(CROSS_COMPILE)gcc $$(AFLAGS) -c $$< -o $$@)) endef +define add_s_file +$(eval S_SRC := $(1:$(BSP_ROOT)/%=%)) \ +$(eval S_SRC := $(S_SRC:$(RTT_ROOT)/%=%)) \ +$(eval SOBJ := $(1:%.s=%.o)) \ +$(eval SOBJ := $(SOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ +$(eval SOBJ := $(SOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ +$(eval LOCALS := $(addprefix $(BUILD_DIR)/,$(SOBJ))) \ +$(eval OBJS += $(LOCALS)) \ +$(if $(strip $(LOCALS)),$(eval $(LOCALS): $(S_SRC) + @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi + @echo cc $$< + @$(CROSS_COMPILE)gcc $$(AFLAGS) -c $$< -o $$@)) +endef + add_flg = $(eval CFLAGS += $1) \ $(eval AFLAGS += $1) \ $(eval CXXFLAGS += $1) @@ -89,6 +103,9 @@ $(if $(SRCS),$(foreach f,$(SRCS),$(call add_cxx_file,$(f)))) SRCS := $(strip $(filter %.S,$(SRC_FILES))) $(if $(SRCS),$(foreach f,$(SRCS),$(call add_S_file,$(f)))) +SRCS := $(strip $(filter %.s,$(SRC_FILES))) +$(if $(SRCS),$(foreach f,$(SRCS),$(call add_s_file,$(f)))) + CFLAGS += $(CPPPATHS) CXXFLAGS += $(CPPPATHS) AFLAGS += $(CPPPATHS) |
