From ac28dded3ee7ed420f755e96a2983620d33a37fb Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 15 Feb 2019 09:04:14 +0800 Subject: [PATCH 1/5] [Tools] Add Makefile genernation. --- tools/building.py | 7 ++++- tools/makefile.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tools/makefile.py diff --git a/tools/building.py b/tools/building.py index 978c0f7237..6581369a44 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') AddOption('--genconfig', dest = 'genconfig', action = 'store_true', @@ -228,6 +228,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ 'cb':('keil', 'armcc'), 'ua':('gcc', 'gcc'), 'cdk':('gcc', 'gcc'), + 'makefile':('gcc', 'gcc'), 'ses' : ('gcc', 'gcc')} tgt_name = GetOption('target') @@ -824,6 +825,10 @@ def GenTargetProject(program = None): from ses import SESProject SESProject(Env) + if GetOption('target') == 'makefile': + from makefile import TargetMakefile + TargetMakefile(Env) + def EndBuilding(target, program = None): import rtconfig diff --git a/tools/makefile.py b/tools/makefile.py new file mode 100644 index 0000000000..f6ff4a305b --- /dev/null +++ b/tools/makefile.py @@ -0,0 +1,68 @@ +import os +import sys + +from utils import * +from utils import _make_path_relative +import rtconfig + +def TargetMakefile(env): + project = ProjectInfo(env) + + make = open('config.mk', 'w') + + BSP_ROOT = os.path.abspath(env['BSP_ROOT']) + RTT_ROOT = os.path.abspath(env['RTT_ROOT']) + + 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'] + + path = '' + paths = [_make_path_relative(BSP_ROOT, os.path.normpath(i)) for i in project['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') + + src = open('src.mk', 'w') + files = [_make_path_relative(BSP_ROOT, os.path.normpath(i)) for i in Files] + src.write('SRC_FILES :=\n') + for item in files: + src.write('SRC_FILES +=%s\n' % item) + + return From 4e22be8937f0f240f7889c473503945a0548e579 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Thu, 7 Mar 2019 14:34:52 +0800 Subject: [PATCH 2/5] now makefile works --- bsp/qemu-vexpress-a9/Makefile | 13 ++++ tools/rtthread.mk | 124 ++++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 bsp/qemu-vexpress-a9/Makefile create mode 100644 tools/rtthread.mk diff --git a/bsp/qemu-vexpress-a9/Makefile b/bsp/qemu-vexpress-a9/Makefile new file mode 100644 index 0000000000..f2efa4a561 --- /dev/null +++ b/bsp/qemu-vexpress-a9/Makefile @@ -0,0 +1,13 @@ +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 diff --git a/tools/rtthread.mk b/tools/rtthread.mk new file mode 100644 index 0000000000..bff3b2bbe2 --- /dev/null +++ b/tools/rtthread.mk @@ -0,0 +1,124 @@ +$(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 := RT-THREAD_OBJS +BSP_BUILD_DIR := BSP_OBJS + +################# + +define add_c_file +$(eval COBJ := $(1:%.c=%.o)) \ +$(eval COBJ := $(COBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ +$(eval COBJ := $(COBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ +$(eval VPATH += $(dir $1)) \ +$(eval CSRCS += $1) \ +$(eval LOCALC := $(addprefix $(BUILD_DIR)/,$(COBJ))) \ +$(eval OBJS += $(LOCALC)) \ +$(if $(strip $(LOCALC)),$(eval $(LOCALC): $1 + @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi + @echo cc $$@ + @$(CROSS_COMPILE)gcc $$(CFLAGS) -c $$< -o $$@)) +endef + +define add_cxx_file +$(eval CXXOBJ := $(1:%.cpp=%.o)) \ +$(eval CXXOBJ := $(CXXOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ +$(eval CXXOBJ := $(CXXOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ +$(eval VPATH += $(dir $1)) \ +$(eval CXXSRCS += $1) \ +$(eval LOCALCXX := $(addprefix $(BUILD_DIR)/,$(CXXOBJ))) \ +$(eval OBJS += $(LOCALCXX)) \ +$(if $(strip $(LOCALCXX)),$(eval $(LOCALCXX): $1 + @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi + @echo cc $$@ + @$(CROSS_COMPILE)g++ $$(CXXFLAGS) -c $$< -o $$@)) +endef + +define add_S_file +$(eval SOBJ := $(1:%.S=%.o)) \ +$(eval SOBJ := $(SOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ +$(eval SOBJ := $(SOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ +$(eval VPATH += $(dir $1)) \ +$(eval SSRCS += $(1)) \ +$(eval LOCALS := $(addprefix $(BUILD_DIR)/,$(SOBJ))) \ +$(eval OBJS += $(LOCALS)) \ +$(if $(strip $(LOCALS)),$(eval $(LOCALS): $1 + @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 := +CSRCS := +CXXSRCS := +SSRCS := +VPATH := + +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) From da73aa1a09bf13b93eb79dc0aabe9ee3e946a648 Mon Sep 17 00:00:00 2001 From: BernardXiong Date: Thu, 21 Mar 2019 12:13:00 +0000 Subject: [PATCH 3/5] [Tools] Add RTT_ROOT/BSP_ROOT for CPPPATH and source files --- tools/makefile.py | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/tools/makefile.py b/tools/makefile.py index f6ff4a305b..9292233601 100644 --- a/tools/makefile.py +++ b/tools/makefile.py @@ -8,11 +8,15 @@ import rtconfig def TargetMakefile(env): project = ProjectInfo(env) - make = open('config.mk', 'w') - 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') @@ -39,8 +43,25 @@ def TargetMakefile(env): 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 = [_make_path_relative(BSP_ROOT, os.path.normpath(i)) for i in project['CPPPATH']] + paths = CPPPATH for item in paths: path += '\t-I%s \\\n' % item @@ -59,8 +80,26 @@ def TargetMakefile(env): 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 = [_make_path_relative(BSP_ROOT, os.path.normpath(i)) for i in Files] + files = Files src.write('SRC_FILES :=\n') for item in files: src.write('SRC_FILES +=%s\n' % item) From 3b75e30c8d908ded140e24529502a6b5f97f84f9 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 21 Mar 2019 23:04:37 +0800 Subject: [PATCH 4/5] [Tools] Add eclipse target --- tools/building.py | 3 +- tools/eclipse.py | 299 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 tools/eclipse.py diff --git a/tools/building.py b/tools/building.py index 6581369a44..4da64f6fcf 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/makefile') + help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse') AddOption('--genconfig', dest = 'genconfig', action = 'store_true', @@ -229,6 +229,7 @@ def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components = [ 'ua':('gcc', 'gcc'), 'cdk':('gcc', 'gcc'), 'makefile':('gcc', 'gcc'), + 'eclipse':('gcc', 'gcc'), 'ses' : ('gcc', 'gcc')} tgt_name = GetOption('target') diff --git a/tools/eclipse.py b/tools/eclipse.py new file mode 100644 index 0000000000..dc86c7be5a --- /dev/null +++ b/tools/eclipse.py @@ -0,0 +1,299 @@ +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] + +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 + +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 HandleToolOption(tools, env): + project = ProjectInfo(env) + BSP_ROOT = os.path.abspath(env['BSP_ROOT']) + + CPPDEFINES = project['CPPDEFINES'] + paths = ['${ProjDirPath}/' + _make_path_relative(BSP_ROOT, 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 = '${ProjDirPath}/' + linker_script + + # print('c.linker.scriptfile') + 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 HandleRTTRoot(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('\\', '/') + + 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('\n') + xml_indent(root) + out.write(etree.tostring(root, encoding='utf-8')) + out.close() + + return + +def TargetEclipse(env): + global source_pattern + + print('Update eclipse setting...') + + if not os.path.exists('.cproject'): + print('no eclipse CDT project found!') + return + + HandleRTTRoot(env) + + project = ProjectInfo(env) + + all_paths = [OSPath(path) for path in CollectPaths(project['DIRS'])] + # print(all_paths) + bsp_root = os.path.abspath(env['BSP_ROOT']) + + exclude_paths = ExcludePaths(bsp_root, all_paths) + paths = exclude_paths + exclude_paths = [] + 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 = [_make_path_relative(bsp_root, 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 = [_make_path_relative(bsp_root, file).replace('\\', '/') for file in exclude_files] + env['ExFiles'] = exclude_files + + 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) + + sourceEntries = cconfiguration.find('storageModule/configuration/sourceEntries') + entry = sourceEntries.find('entry') + if entry != None: + sourceEntries.remove(entry) + + excluding = exclude_paths + exclude_files + excluding = sorted(excluding) + value = '' + for item in excluding: + if value == '': + value = item + else: + value += '|' + item + excluding = value + + SubElement(sourceEntries, 'entry', {'excluding': excluding, 'flags': 'VALUE_WORKSPACE_PATH|RESOLVED', 'kind':'sourcePath', 'name':""}) + + # write back to .cproject + out = open('.cproject', 'w') + out.write('\n') + out.write('') + xml_indent(root) + out.write(etree.tostring(root, encoding='utf-8')) + out.close() + + print('done!') + + return From b6055df950cb73127fd45c910d14902bfef7ce4f Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 23 Mar 2019 19:36:40 +0800 Subject: [PATCH 5/5] [Tools] Fix the directory issue for Makefile --- tools/rtthread.mk | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/tools/rtthread.mk b/tools/rtthread.mk index bff3b2bbe2..fdc96d4156 100644 --- a/tools/rtthread.mk +++ b/tools/rtthread.mk @@ -8,50 +8,50 @@ endif $(if $(strip $(BUILD_DIR)),,$(error BUILD_DIR not defined)) -RTT_BUILD_DIR := RT-THREAD_OBJS -BSP_BUILD_DIR := BSP_OBJS +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:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ $(eval COBJ := $(COBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ -$(eval VPATH += $(dir $1)) \ -$(eval CSRCS += $1) \ +$(eval COBJ := $(COBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ $(eval LOCALC := $(addprefix $(BUILD_DIR)/,$(COBJ))) \ $(eval OBJS += $(LOCALC)) \ -$(if $(strip $(LOCALC)),$(eval $(LOCALC): $1 +$(if $(strip $(LOCALC)),$(eval $(LOCALC): $(C_SRC) @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi - @echo cc $$@ + @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:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ $(eval CXXOBJ := $(CXXOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ -$(eval VPATH += $(dir $1)) \ -$(eval CXXSRCS += $1) \ +$(eval CXXOBJ := $(CXXOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ $(eval LOCALCXX := $(addprefix $(BUILD_DIR)/,$(CXXOBJ))) \ $(eval OBJS += $(LOCALCXX)) \ -$(if $(strip $(LOCALCXX)),$(eval $(LOCALCXX): $1 +$(if $(strip $(LOCALCXX)),$(eval $(LOCALCXX): $(CXX_SRC) @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi - @echo cc $$@ + @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:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ $(eval SOBJ := $(SOBJ:$(BSP_ROOT)/%=$(BSP_BUILD_DIR)/%)) \ -$(eval VPATH += $(dir $1)) \ -$(eval SSRCS += $(1)) \ +$(eval SOBJ := $(SOBJ:$(RTT_ROOT)/%=$(RTT_BUILD_DIR)/%)) \ $(eval LOCALS := $(addprefix $(BUILD_DIR)/,$(SOBJ))) \ $(eval OBJS += $(LOCALS)) \ -$(if $(strip $(LOCALS)),$(eval $(LOCALS): $1 +$(if $(strip $(LOCALS)),$(eval $(LOCALS): $(S_SRC) @if [ ! -d $$(@D) ]; then mkdir -p $$(@D); fi - @echo cc $$@ + @echo cc $$< @$(CROSS_COMPILE)gcc $$(AFLAGS) -c $$< -o $$@)) endef @@ -68,10 +68,8 @@ add_def = $(eval CFLAGS += -D$1) \ $(eval CXXFLAGS += -D$1) OBJS := -CSRCS := -CXXSRCS := -SSRCS := -VPATH := +#VPATH := $(BSP_ROOT) $(RTT_ROOT) +VPATH := $(RTT_ROOT) CONFIG_FLG := $(strip $(EXTERN_FLAGS)) $(if $(CONFIG_FLG),$(foreach f,$(CONFIG_FLG),$(call add_flg,$(f))))