summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2019-05-20 20:33:07 +0800
committerGitHub <[email protected]>2019-05-20 20:33:07 +0800
commitb2ae7d72f923e1638f72d8eba5c2131389b741b0 (patch)
treeab526e2e216f5f656b9c6a53221382d07c7bac2e /tools
parentd778c9df25cbbd8e202a0133453e4c8b8e179eff (diff)
parent35eff9a85dd1e922f98d36deed84bdfb3c8319f7 (diff)
Merge pull request #2703 from armink/lts-v3.1.x
Lts v3.1.x
Diffstat (limited to 'tools')
-rw-r--r--tools/building.py12
-rw-r--r--tools/eclipse.py351
-rw-r--r--tools/keil.py11
-rw-r--r--tools/makefile.py126
-rw-r--r--tools/menuconfig.py3
-rw-r--r--tools/rtthread.mk122
-rw-r--r--tools/utils.py12
7 files changed, 627 insertions, 10 deletions
diff --git a/tools/building.py b/tools/building.py
index 978c0f7237..c037c2d068 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -187,7 +187,7 @@ 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')
+ help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse')
AddOption('--genconfig',
dest = 'genconfig',
action = 'store_true',
@@ -228,6 +228,8 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [
'cb':('keil', 'armcc'),
'ua':('gcc', 'gcc'),
'cdk':('gcc', 'gcc'),
+ 'makefile':('gcc', 'gcc'),
+ 'eclipse':('gcc', 'gcc'),
'ses' : ('gcc', 'gcc')}
tgt_name = GetOption('target')
@@ -824,6 +826,14 @@ def GenTargetProject(program = None):
from ses import SESProject
SESProject(Env)
+ if GetOption('target') == 'makefile':
+ from makefile import TargetMakefile
+ TargetMakefile(Env)
+
+ if GetOption('target') == 'eclipse':
+ from eclipse import TargetEclipse
+ TargetEclipse(Env)
+
def EndBuilding(target, program = None):
import rtconfig
diff --git a/tools/eclipse.py b/tools/eclipse.py
new file mode 100644
index 0000000000..78acc8904e
--- /dev/null
+++ b/tools/eclipse.py
@@ -0,0 +1,351 @@
+#
+# Copyright (c) 2006-2019, RT-Thread Development Team
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Change Logs:
+# Date Author Notes
+# 2019-03-21 Bernard the first version
+# 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
+
+source_pattern = ['*.c', '*.cpp', '*.cxx', '*.s', '*.S', '*.asm']
+
+def OSPath(path):
+ import platform
+
+ if type(path) == type('str'):
+ if platform.system() == 'Windows':
+ return path.replace('/', '\\')
+ else:
+ return path.replace('\\', '/')
+ else:
+ if platform.system() == 'Windows':
+ return [item.replace('/', '\\') for item in path]
+ else:
+ return [item.replace('\\', '/') for item in path]
+
+
+# collect the build source code path and parent path
+def CollectPaths(paths):
+ all_paths = []
+
+ def ParentPaths(path):
+ ret = os.path.dirname(path)
+ if ret == path or ret == '':
+ return []
+
+ return [ret] + ParentPaths(ret)
+
+ for path in paths:
+ # path = os.path.abspath(path)
+ path = path.replace('\\', '/')
+ all_paths = all_paths + [path] + ParentPaths(path)
+
+ 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:
+ if type(pattern) == type(''):
+ files = files + glob.glob(path + '/' + pattern)
+ else:
+ for item in pattern:
+ # print('--> %s' % (path + '/' + item))
+ files = files + glob.glob(path + '/' + item)
+
+ return sorted(files)
+
+def CollectAllFilesinPath(path, pattern):
+ files = []
+
+ for item in pattern:
+ files += glob.glob(path + '/' + item)
+
+ list = os.listdir(path)
+ if len(list):
+ for item in list:
+ if item.startswith('.'):
+ continue
+ if item == 'bsp':
+ continue
+
+ if os.path.isdir(os.path.join(path, item)):
+ 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])
+ exl_files = set([OSPath(file) for file in files])
+
+ exl_files = in_files - exl_files
+
+ return exl_files
+
+
+# caluclate the exclude path for project
+def ExcludePaths(filepath, paths):
+ ret = []
+
+ files = os.listdir(filepath)
+ for file in files:
+ if file.startswith('.'):
+ continue
+
+ fullname = os.path.join(filepath, file)
+
+ if os.path.isdir(fullname):
+ # print(fullname)
+ if not fullname in paths:
+ ret = ret + [fullname]
+ else:
+ ret = ret + ExcludePaths(fullname, paths)
+
+ return ret
+
+
+def ConverToEclipsePathFormat(path):
+ if path.startswith('.'):
+ path = path[1:]
+ return '"${workspace_loc:/${ProjName}/' + path + '}"'
+
+
+def HandleToolOption(tools, env, project):
+ BSP_ROOT = os.path.abspath(env['BSP_ROOT'])
+
+ CPPDEFINES = project['CPPDEFINES']
+ paths = [ConverToEclipsePathFormat(RelativeProjectPath(env, os.path.normpath(i)).replace('\\', '/')) for i in project['CPPPATH']]
+
+ for tool in tools:
+ if tool.get('id').find('c.compile') != 1:
+ options = tool.findall('option')
+ for option in options:
+ if option.get('id').find('c.compiler.include.paths') != -1:
+ # find all of paths in this project
+ include_paths = option.findall('listOptionValue')
+ project_paths = []
+ for item in include_paths:
+ project_paths += [item.get('value')]
+
+ if len(project_paths) > 0:
+ cproject_paths = set(paths) - set(project_paths)
+ else:
+ cproject_paths = paths
+
+ # print('c.compiler.include.paths')
+ cproject_paths = sorted(cproject_paths)
+ for item in cproject_paths:
+ SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
+
+ if option.get('id').find('c.compiler.defs') != -1:
+ defs = option.findall('listOptionValue')
+ project_defs = []
+ for item in defs:
+ project_defs += [item.get('value')]
+ if len(project_defs) > 0:
+ cproject_defs = set(CPPDEFINES) - set(project_defs)
+ else:
+ cproject_defs = CPPDEFINES
+
+ # print('c.compiler.defs')
+ cproject_defs = sorted(cproject_defs)
+ for item in cproject_defs:
+ SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': item})
+
+ if tool.get('id').find('c.linker') != -1:
+ options = tool.findall('option')
+ for option in options:
+ if option.get('id').find('c.linker.scriptfile') != -1:
+ linker_script = 'link.lds'
+ items = env['LINKFLAGS'].split(' ')
+ if '-T' in items:
+ linker_script = items[items.index('-T') + 1]
+ linker_script = ConverToEclipsePathFormat(linker_script)
+
+ listOptionValue = option.find('listOptionValue')
+ if listOptionValue != None:
+ listOptionValue.set('value', linker_script)
+ else:
+ SubElement(option, 'listOptionValue', {'builtIn': 'false', 'value': linker_script})
+
+ if option.get('id').find('c.linker.nostart') != -1:
+ if env['LINKFLAGS'].find('-nostartfiles') != -1:
+ option.set('value', 'true')
+ else:
+ option.set('value', 'false')
+
+ return
+
+def UpdateProjectStructure(env):
+ bsp_root = env['BSP_ROOT']
+ rtt_root = env['RTT_ROOT']
+
+ if not rtt_root.startswith(bsp_root):
+ to_SubElement = True
+ # print('handle virtual root')
+
+ # always use '/' path separator
+ rtt_root = rtt_root.replace('\\', '/')
+
+ # TODO create the virtual folder
+
+# project = etree.parse('.project')
+# root = project.getroot()
+#
+# linkedResources = root.find('linkedResources')
+# if linkedResources == None:
+# # add linkedResources
+# linkedResources = SubElement(root, 'linkedResources')
+# # print('add linkedResources')
+# else:
+# links = linkedResources.findall('link')
+# # search exist 'rt-thread' virtual folder
+# for link in links:
+# if link.find('name').text == 'rt-thread':
+# # handle location
+# to_SubElement = False
+# location = link.find('location')
+# location.text = rtt_root
+#
+# if to_SubElement:
+# # print('to subelement for virtual folder')
+# link = SubElement(linkedResources, 'link')
+# name = SubElement(link, 'name')
+# name.text = 'rt-thread'
+# type = SubElement(link, 'type')
+# type.text = '2'
+# location = SubElement(link, 'location')
+# location.text = rtt_root
+#
+# 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.close()
+
+ return
+
+def GenExcluding(env, project):
+ rtt_root = os.path.abspath(env['RTT_ROOT'])
+ coll_dirs = CollectPaths(project['DIRS'])
+ all_paths = [OSPath(path) for path in coll_dirs]
+
+ exclude_paths = ExcludePaths(rtt_root, all_paths)
+
+ paths = exclude_paths
+ exclude_paths = []
+ # remove the folder which not has source code by source_pattern
+ for path in paths:
+ # add bsp and libcpu folder and not collect source files (too more files)
+ if path.endswith('rt-thread\\bsp') or path.endswith('rt-thread\\libcpu'):
+ exclude_paths += [path]
+ continue
+
+ set = CollectAllFilesinPath(path, source_pattern)
+ if len(set):
+ exclude_paths += [path]
+
+ exclude_paths = [RelativeProjectPath(env, path).replace('\\', '/') for path in exclude_paths]
+ env['ExPaths'] = exclude_paths
+
+ all_files = CollectFiles(all_paths, source_pattern)
+ src_files = project['FILES']
+
+ exclude_files = ExcludeFiles(all_files, src_files)
+ exclude_files = [RelativeProjectPath(env, file).replace('\\', '/') for file in exclude_files]
+ env['ExFiles'] = 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)
+
+ # TODO add others folder
+ print('ERROR: the ' + path + 'not support')
+
+ return path
+
+
+def UpdateCproject(env, project, excluding):
+ excluding = sorted(excluding)
+
+ cproject = etree.parse('.cproject')
+
+ root = cproject.getroot()
+ cconfigurations = root.findall('storageModule/cconfiguration')
+ for cconfiguration in cconfigurations:
+ tools = cconfiguration.findall('storageModule/configuration/folderInfo/toolChain/tool')
+ HandleToolOption(tools, env, project)
+
+ sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries')
+ entry = sourceEntries.find('entry')
+ if entry != None:
+ sourceEntries.remove(entry)
+
+ value = ''
+ for item in excluding:
+ if value == '':
+ value = item
+ else:
+ value += '|' + item
+
+ SubElement(sourceEntries, 'entry', {'excluding': value, 'flags': 'VALUE_WORKSPACE_PATH|RESOLVED', 'kind':'sourcePath', 'name':""})
+
+ # write back to .cproject
+ out = open('.cproject', 'w')
+ out.write('<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n')
+ out.write('<?fileVersion 4.0.0?>')
+ xml_indent(root)
+ out.write(etree.tostring(root, encoding='utf-8'))
+ out.close()
+
+
+def TargetEclipse(env):
+ global source_pattern
+
+ print('Update eclipse setting...')
+
+ if not os.path.exists('.cproject'):
+ print('no eclipse CDT project found!')
+ return
+
+ project = ProjectInfo(env)
+
+ # update the project file structure info on '.project' file
+ UpdateProjectStructure(env)
+
+ # generate the exclude paths and files
+ excluding = GenExcluding(env, project)
+
+ # update the project configuration on '.cproject' file
+ UpdateCproject(env, project, excluding)
+
+ print('done!')
+
+ return
diff --git a/tools/keil.py b/tools/keil.py
index 59da254430..b096917a42 100644
--- a/tools/keil.py
+++ b/tools/keil.py
@@ -56,6 +56,7 @@ def _get_filetype(fn):
def MDK4AddGroupForFN(ProjectFiles, parent, name, filename, project_path):
group = SubElement(parent, 'Group')
+ group.text = name
group_name = SubElement(group, 'GroupName')
group_name.text = name
@@ -244,9 +245,13 @@ def MDK45Project(tree, target, script):
lib_path = full_path
if lib_path != '':
- if (group_tree != None):
- MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path)
- else:
+ need_create = 1
+ for neighbor in groups.iter('Group'):
+ if neighbor.text == group['name']:
+ MDK4AddLibToGroup(ProjectFiles, neighbor, group['name'], lib_path, project_path)
+ need_create = 0
+ break
+ if (need_create != 0):
MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path)
# write include path, definitions and link flags
diff --git a/tools/makefile.py b/tools/makefile.py
new file mode 100644
index 0000000000..655e294575
--- /dev/null
+++ b/tools/makefile.py
@@ -0,0 +1,126 @@
+import os
+import sys
+
+from utils import *
+from utils import _make_path_relative
+import rtconfig
+
+makefile = '''phony := all
+all:
+
+include config.mk
+
+ifneq ($(MAKE_LIB),1)
+TARGET := rtthread.elf
+include src.mk
+endif
+
+$(if $(strip $(RTT_ROOT)),,$(error RTT_ROOT not defined))
+
+include $(RTT_ROOT)/tools/rtthread.mk
+'''
+
+def TargetMakefile(env):
+ project = ProjectInfo(env)
+
+ BSP_ROOT = os.path.abspath(env['BSP_ROOT'])
+ RTT_ROOT = os.path.abspath(env['RTT_ROOT'])
+
+ match_bsp = False
+ if BSP_ROOT.startswith(RTT_ROOT):
+ match_bsp = True
+
+ make = open('config.mk', 'w')
+
+ make.write('BSP_ROOT ?= %s\n' % BSP_ROOT.replace('\\', '/'))
+ make.write('RTT_ROOT ?= %s\n' % RTT_ROOT.replace('\\', '/'))
+ make.write('\n')
+
+ cross = os.path.abspath(rtconfig.EXEC_PATH)
+ cross = os.path.join(cross, rtconfig.PREFIX)
+ make.write('CROSS_COMPILE ?=%s' % cross.replace('\\', '\\\\'))
+ make.write('\n')
+ make.write('\n')
+
+ make.write('CFLAGS :=%s' % (rtconfig.CFLAGS))
+ make.write('\n')
+ make.write('AFLAGS :=%s' % (rtconfig.AFLAGS))
+ make.write('\n')
+ make.write('LFLAGS :=%s' % (rtconfig.LFLAGS))
+ make.write('\n')
+ if 'CXXFLAGS' in dir(rtconfig):
+ make.write('CXXFLAGS :=%s' % (rtconfig.CXXFLAGS))
+ make.write('\n')
+
+ make.write('\n')
+
+ Files = project['FILES']
+ Headers = project['HEADERS']
+ CPPDEFINES = project['CPPDEFINES']
+
+ paths = [os.path.normpath(i) for i in project['CPPPATH']]
+ CPPPATH = []
+ for path in paths:
+ fn = os.path.normpath(path)
+ if match_bsp:
+ if fn.startswith(BSP_ROOT):
+ fn = '$(BSP_ROOT)' + fn.replace(BSP_ROOT, '')
+ elif fn.startswith(RTT_ROOT):
+ fn = '$(RTT_ROOT)' + fn.replace(RTT_ROOT, '')
+ else:
+ if fn.startswith(RTT_ROOT):
+ fn = '$(RTT_ROOT)' + fn.replace(RTT_ROOT, '')
+ elif fn.startswith(BSP_ROOT):
+ fn = '$(BSP_ROOT)' + fn.replace(BSP_ROOT, '')
+
+ CPPPATH.append(fn)
+
+ path = ''
+ paths = CPPPATH
+ for item in paths:
+ path += '\t-I%s \\\n' % item
+
+ make.write('CPPPATHS :=')
+ if path[0] == '\t': path = path[1:]
+ length = len(path)
+ if path[length - 2] == '\\': path = path[:length - 2]
+ make.write(path)
+ make.write('\n')
+ make.write('\n')
+
+ defines = ''
+ for item in project['CPPDEFINES']:
+ defines += ' -D%s' % item
+ make.write('DEFINES :=')
+ make.write(defines)
+ make.write('\n')
+
+ files = Files
+ Files = []
+ for file in files:
+ fn = os.path.normpath(file)
+ if match_bsp:
+ if fn.startswith(BSP_ROOT):
+ fn = '$(BSP_ROOT)' + fn.replace(BSP_ROOT, '')
+ elif fn.startswith(RTT_ROOT):
+ fn = '$(RTT_ROOT)' + fn.replace(RTT_ROOT, '')
+ else:
+ if fn.startswith(RTT_ROOT):
+ fn = '$(RTT_ROOT)' + fn.replace(RTT_ROOT, '')
+ elif fn.startswith(BSP_ROOT):
+ fn = '$(BSP_ROOT)' + fn.replace(BSP_ROOT, '')
+
+ Files.append(fn)
+ # print(fn)
+
+ src = open('src.mk', 'w')
+ files = Files
+ src.write('SRC_FILES :=\n')
+ for item in files:
+ src.write('SRC_FILES +=%s\n' % item.replace('\\', '/'))
+
+ make = open('Makefile', 'w')
+ make.write(makefile)
+ make.close()
+
+ return
diff --git a/tools/menuconfig.py b/tools/menuconfig.py
index 2550424802..049bc4f2ac 100644
--- a/tools/menuconfig.py
+++ b/tools/menuconfig.py
@@ -23,6 +23,7 @@
# 2018-07-31 weety Support pyconfig
import os
+import re
import sys
import shutil
@@ -75,7 +76,7 @@ def mk_rtconfig(filename):
if setting[1] == 'y':
rtconfig.write('#define %s\n' % setting[0])
else:
- rtconfig.write('#define %s %s\n' % (setting[0], setting[1]))
+ rtconfig.write('#define %s %s\n' % (setting[0], re.findall(r"^.*?=(.*)$",line)[0]))
if os.path.isfile('rtconfig_project.h'):
rtconfig.write('#include "rtconfig_project.h"\n')
diff --git a/tools/rtthread.mk b/tools/rtthread.mk
new file mode 100644
index 0000000000..fdc96d4156
--- /dev/null
+++ b/tools/rtthread.mk
@@ -0,0 +1,122 @@
+$(if $(strip $(TARGET)),,$(error TARGET not defined))
+$(if $(strip $(SRC_FILES)),,$(error No source files))
+$(if $(strip $(BSP_ROOT)),,$(error BSP_ROOT not defined))
+
+ifneq ($(MAKE_LIB),1)
+BUILD_DIR := $(BSP_ROOT)/build
+endif
+
+$(if $(strip $(BUILD_DIR)),,$(error BUILD_DIR not defined))
+
+RTT_BUILD_DIR := .
+BSP_BUILD_DIR := bsp
+
+#################
+
+define add_c_file
+$(eval C_SRC := $(1:$(BSP_ROOT)/%=%)) \
+$(eval C_SRC := $(C_SRC:$(RTT_ROOT)/%=%)) \
+$(eval COBJ := $(1:%.c=%.o)) \
+$(eval COBJ := $(COBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \
+$(eval COBJ := $(COBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \
+$(eval LOCALC := $(addprefix $(BUILD_DIR)/,$(COBJ))) \
+$(eval OBJS += $(LOCALC)) \
+$(if $(strip $(LOCALC)),$(eval $(LOCALC): $(C_SRC)
+ @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
+ @echo cc $$<
+ @$(CROSS_COMPILE)gcc $$(CFLAGS) -c $$< -o $$@))
+endef
+
+define add_cxx_file
+$(eval CXX_SRC := $(1:$(BSP_ROOT)/%=%)) \
+$(eval CXX_SRC := $(CXX_SRC:$(RTT_ROOT)/%=%)) \
+$(eval CXXOBJ := $(1:%.cpp=%.o)) \
+$(eval CXXOBJ := $(CXXOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \
+$(eval CXXOBJ := $(CXXOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \
+$(eval LOCALCXX := $(addprefix $(BUILD_DIR)/,$(CXXOBJ))) \
+$(eval OBJS += $(LOCALCXX)) \
+$(if $(strip $(LOCALCXX)),$(eval $(LOCALCXX): $(CXX_SRC)
+ @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi
+ @echo cc $$<
+ @$(CROSS_COMPILE)g++ $$(CXXFLAGS) -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)
+
+add_inc = $(eval CFLAGS += -I$1) \
+ $(eval AFLAGS += -I$1) \
+ $(eval CXXFLAGS += -I$1)
+
+add_def = $(eval CFLAGS += -D$1) \
+ $(eval AFLAGS += -D$1) \
+ $(eval CXXFLAGS += -D$1)
+
+OBJS :=
+#VPATH := $(BSP_ROOT) $(RTT_ROOT)
+VPATH := $(RTT_ROOT)
+
+CONFIG_FLG := $(strip $(EXTERN_FLAGS))
+$(if $(CONFIG_FLG),$(foreach f,$(CONFIG_FLG),$(call add_flg,$(f))))
+
+CONFIG_DEF := $(strip $(PROJECT_DEFS))
+$(if $(CONFIG_DEF),$(foreach d,$(CONFIG_DEF),$(call add_def,$(d))))
+
+CONFIG_INC := $(strip $(INCLUDE_PATH))
+$(if $(CONFIG_INC),$(foreach i,$(CONFIG_INC),$(call add_inc,$(i))))
+
+SRCS := $(strip $(filter %.c,$(SRC_FILES)))
+$(if $(SRCS),$(foreach f,$(SRCS),$(call add_c_file,$(f))))
+
+SRCS := $(strip $(filter %.cpp,$(SRC_FILES)))
+$(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))))
+
+CFLAGS += $(CPPPATHS)
+CXXFLAGS += $(CPPPATHS)
+AFLAGS += $(CPPPATHS)
+
+CFLAGS += $(DEFINES)
+CXXFLAGS += $(DEFINES)
+AFLAGS += $(DEFINES)
+
+all: $(TARGET)
+
+ifeq ($(MAKE_LIB),1)
+$(TARGET): $(OBJS)
+ @echo ------------------------------------------------
+ @echo ar $(TARGET)
+ @$(CROSS_COMPILE)ar -rv $@ $(OBJS)
+else
+$(TARGET): $(OBJS) $(EXTERN_LIB)
+ @echo ------------------------------------------------
+ @echo link $(TARGET)
+ @$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB) -lc -lm
+ @echo ------------------------------------------------
+ @$(CROSS_COMPILE)objcopy -O binary $@ rtthread.bin
+ @$(CROSS_COMPILE)size $@
+endif
+
+phony += clean
+clean:
+ @echo clean
+ @rm -rf $(TARGET) $(BUILD_DIR)
+
+.PHONY: $(phony)
diff --git a/tools/utils.py b/tools/utils.py
index 6dc56322a5..9459396544 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -24,6 +24,7 @@
import sys
import os
+import re
def splitall(loc):
"""
@@ -245,10 +246,11 @@ def ProjectInfo(env):
return proj
def VersionCmp(ver1, ver2):
- la=[];
+ la=[]
if ver1:
- la = ver1.split('.')
- lb = ver2.split('.')
+ la = re.split("[. ]", ver1)
+ lb = re.split("[. ]", ver2)
+
f = 0
if len(la) > len(lb):
f = len(la)
@@ -262,7 +264,7 @@ def VersionCmp(ver1, ver2):
continue
else:
return -1
- except IndexError as e:
+ except (IndexError, ValueError) as e:
if len(la) > len(lb):
return 1
else:
@@ -274,7 +276,7 @@ def GCCC99Patch(cflags):
gcc_version = building.GetDepend('GCC_VERSION')
if gcc_version:
gcc_version = gcc_version.replace('"', '')
- if VersionCmp(gcc_version, "4.8.0"):
+ if VersionCmp(gcc_version, "4.8.0") == 1:
# remove -std=c99 after GCC 4.8.x
cflags = cflags.replace('-std=c99', '')