From 4b7f591d33c4f6ffcc592663489963caef52bd70 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Tue, 5 Jul 2016 10:16:50 -0500 Subject: [PATCH 1/7] Fix the makefile template - Corrects a python barf when something in features is None - Corrects makefile to prevent barf when using make -f --- tools/export/gcc_arm_common.tmpl | 3 ++- tools/toolchains/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/export/gcc_arm_common.tmpl b/tools/export/gcc_arm_common.tmpl index 6b23dd5bca..415fdab4e4 100644 --- a/tools/export/gcc_arm_common.tmpl +++ b/tools/export/gcc_arm_common.tmpl @@ -13,7 +13,8 @@ endif ifeq (,$(filter .build,$(notdir $(CURDIR)))) .SUFFIXES: OBJDIR := .build -MAKETARGET = $(MAKE) --no-print-directory -C $(OBJDIR) -f $(CURDIR)/Makefile \ +mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) +MAKETARGET = $(MAKE) --no-print-directory -C $(OBJDIR) -f $(mkfile_path) \ SRCDIR=$(CURDIR) $(MAKECMDGOALS) .PHONY: $(OBJDIR) clean all: diff --git a/tools/toolchains/__init__.py b/tools/toolchains/__init__.py index 20f1460cb3..5595294506 100644 --- a/tools/toolchains/__init__.py +++ b/tools/toolchains/__init__.py @@ -147,7 +147,7 @@ class Resources: v = [rel_path(f, base, dot) for f in getattr(self, field)] setattr(self, field, v) - self.features = {k: f.relative_to(base, dot) for k, f in self.features.iteritems()} + self.features = {k: f.relative_to(base, dot) for k, f in self.features.iteritems() if f} if self.linker_script is not None: self.linker_script = rel_path(self.linker_script, base, dot) @@ -160,7 +160,7 @@ class Resources: v = [f.replace('\\', '/') for f in getattr(self, field)] setattr(self, field, v) - self.features = {k: f.win_to_unix() for k, f in self.features.iteritems()} + self.features = {k: f.win_to_unix() for k, f in self.features.iteritems() if f} if self.linker_script is not None: self.linker_script = self.linker_script.replace('\\', '/') From fa527cf45e0cc6abf2462c3589e5e6d3695d53a9 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Tue, 5 Jul 2016 11:51:27 -0500 Subject: [PATCH 2/7] Rework vpaths and include file locating --- tools/export/gcc_arm_common.tmpl | 6 +++--- tools/export/gccarm.py | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tools/export/gcc_arm_common.tmpl b/tools/export/gcc_arm_common.tmpl index 415fdab4e4..565c601656 100644 --- a/tools/export/gcc_arm_common.tmpl +++ b/tools/export/gcc_arm_common.tmpl @@ -29,14 +29,14 @@ clean : {% endblock %} else -VPATH = $(SRCDIR) +VPATH = {% for path in vpath %}{{path}} {% endfor %} GCC_BIN = PROJECT = {{name}} OBJECTS = {% for f in to_be_compiled %}{{f}} {% endfor %} SYS_OBJECTS = {% for f in object_files %}{{f}} {% endfor %} -INCLUDE_PATHS = {% for p in include_paths %}-I../{{p}} {% endfor %} -LIBRARY_PATHS = {% for p in library_paths %}-L../{{p}} {% endfor %} +INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %} +LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %} LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %} LINKER_SCRIPT = {{linker_script}} {%- block additional_variables -%}{% endblock %} diff --git a/tools/export/gccarm.py b/tools/export/gccarm.py index 28d9c90a87..ce321443f2 100644 --- a/tools/export/gccarm.py +++ b/tools/export/gccarm.py @@ -15,8 +15,8 @@ See the License for the specific language governing permissions and limitations under the License. """ from exporters import Exporter -from os.path import splitext, basename -from os import curdir +from os.path import splitext, basename, relpath, join, abspath +from os import curdir, getcwd class GccArm(Exporter): @@ -133,7 +133,7 @@ class GccArm(Exporter): def generate(self): # "make" wants Unix paths self.resources.win_to_unix() - self.resources.relative_to(curdir) + self.resources.relative_to(self.prj_paths[0]) to_be_compiled = [] for r_type in ['s_sources', 'c_sources', 'cpp_sources']: @@ -148,6 +148,7 @@ class GccArm(Exporter): l, _ = splitext(basename(lib)) libraries.append(l[3:]) + build_dir = abspath(join(self.inputDir, ".build")) ctx = { 'name': self.program_name, 'to_be_compiled': to_be_compiled, @@ -157,7 +158,20 @@ class GccArm(Exporter): 'linker_script': self.resources.linker_script, 'libraries': libraries, 'symbols': self.get_symbols(), - 'cpu_flags': self.toolchain.cpu + 'cpu_flags': self.toolchain.cpu, + 'vpath': [relpath(s, build_dir) for s in self.prj_paths] if self.sources_relative else ["../"] } + + for key in ['include_paths', 'library_paths', 'linker_script']: + if isinstance(ctx[key], list): + ctx[key] = [ctx['vpath'][0] + "/" + t for t in ctx[key]] + else: + ctx[key] = ctx['vpath'][0] + "/" + ctx[key] + if "../." not in ctx["include_paths"]: + ctx["include_paths"] += ['../.'] ctx.update(self.progen_flags) self.gen_file('gcc_arm_%s.tmpl' % self.target.lower(), ctx, 'Makefile') + + def scan_and_copy_resources(self, prj_paths, trg_path, relative=False): + self.prj_paths = prj_paths + Exporter.scan_and_copy_resources(self, prj_paths, trg_path, relative) From 61ee30efb22d726cada13d60c6f92c0ec44b9ea3 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Tue, 5 Jul 2016 12:04:36 -0500 Subject: [PATCH 3/7] Fix normal export (no --source) --- tools/export/gccarm.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/export/gccarm.py b/tools/export/gccarm.py index ce321443f2..be1b424e44 100644 --- a/tools/export/gccarm.py +++ b/tools/export/gccarm.py @@ -133,7 +133,8 @@ class GccArm(Exporter): def generate(self): # "make" wants Unix paths self.resources.win_to_unix() - self.resources.relative_to(self.prj_paths[0]) + if self.sources_relative: + self.resources.relative_to(self.prj_paths[0]) to_be_compiled = [] for r_type in ['s_sources', 'c_sources', 'cpp_sources']: @@ -159,7 +160,7 @@ class GccArm(Exporter): 'libraries': libraries, 'symbols': self.get_symbols(), 'cpu_flags': self.toolchain.cpu, - 'vpath': [relpath(s, build_dir) for s in self.prj_paths] if self.sources_relative else ["../"] + 'vpath': [relpath(s, build_dir) for s in self.prj_paths] if self.sources_relative else [".."] } for key in ['include_paths', 'library_paths', 'linker_script']: From c2d66865be9ca1b4a27c56d0960e5f320160d04c Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Wed, 6 Jul 2016 11:32:01 -0500 Subject: [PATCH 4/7] Correct batch detection algorimthm There are two shell-like things that we care about bash: does environment varible expansion with $ batch: does environment varible expansion by surrounding something with % so to detect batch, try to expand a variable on the shell with $. If you get a $ back, you are in batch! --- tools/export/gcc_arm_common.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/export/gcc_arm_common.tmpl b/tools/export/gcc_arm_common.tmpl index 565c601656..824434ef04 100644 --- a/tools/export/gcc_arm_common.tmpl +++ b/tools/export/gcc_arm_common.tmpl @@ -2,7 +2,7 @@ # see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded # cross-platform directory manipulation -ifeq ($(OSTYPE),) +ifeq ($(shell echo $$OS),$$OS) MAKEDIR = if not exist "$(1)" mkdir "$(1)" RM = rmdir /S /Q else From fbccf8dfc991ba8f90967101028728a0159198d0 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Wed, 6 Jul 2016 12:49:38 -0500 Subject: [PATCH 5/7] Force shell use when in bash/sh mode --- tools/export/gcc_arm_common.tmpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/export/gcc_arm_common.tmpl b/tools/export/gcc_arm_common.tmpl index 824434ef04..7ae338913c 100644 --- a/tools/export/gcc_arm_common.tmpl +++ b/tools/export/gcc_arm_common.tmpl @@ -4,10 +4,10 @@ # cross-platform directory manipulation ifeq ($(shell echo $$OS),$$OS) MAKEDIR = if not exist "$(1)" mkdir "$(1)" - RM = rmdir /S /Q + RM = rmdir /S /Q "$(1)" else - MAKEDIR = mkdir -p $(1) - RM = rm -rf + MAKEDIR = $(SHELL) -c "mkdir -p $(1)" + RM = $(SHELL) -c "rm -rf $(1)" endif ifeq (,$(filter .build,$(notdir $(CURDIR)))) @@ -24,7 +24,7 @@ $(OBJDIR): all Makefile : ; % :: $(OBJDIR) ; : clean : - $(RM) $(OBJDIR) + $(call RM,$(OBJDIR)) {% block target_clean -%} {% endblock %} else From 3cf8bfbfb7409730e21ef67a444ebcc8afb7c231 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Wed, 6 Jul 2016 12:51:14 -0500 Subject: [PATCH 6/7] Allow spaces in paths passed to mkdir and rm on bash --- tools/export/gcc_arm_common.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/export/gcc_arm_common.tmpl b/tools/export/gcc_arm_common.tmpl index 7ae338913c..db5c9cb92a 100644 --- a/tools/export/gcc_arm_common.tmpl +++ b/tools/export/gcc_arm_common.tmpl @@ -6,8 +6,8 @@ ifeq ($(shell echo $$OS),$$OS) MAKEDIR = if not exist "$(1)" mkdir "$(1)" RM = rmdir /S /Q "$(1)" else - MAKEDIR = $(SHELL) -c "mkdir -p $(1)" - RM = $(SHELL) -c "rm -rf $(1)" + MAKEDIR = $(SHELL) -c "mkdir -p \"$(1)\"" + RM = $(SHELL) -c "rm -rf \"$(1)\"" endif ifeq (,$(filter .build,$(notdir $(CURDIR)))) From 3697dedb78df9b955c140378a94e4f537fa3633d Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Wed, 6 Jul 2016 13:54:33 -0500 Subject: [PATCH 7/7] Reverse order of relativizing paths and unixifing paths 'cause windows silly path separator is the same as the escape character --- tools/export/gccarm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/export/gccarm.py b/tools/export/gccarm.py index be1b424e44..88efe21b59 100644 --- a/tools/export/gccarm.py +++ b/tools/export/gccarm.py @@ -132,9 +132,9 @@ class GccArm(Exporter): def generate(self): # "make" wants Unix paths - self.resources.win_to_unix() if self.sources_relative: self.resources.relative_to(self.prj_paths[0]) + self.resources.win_to_unix() to_be_compiled = [] for r_type in ['s_sources', 'c_sources', 'cpp_sources']: