Skip to content

Commit 36ff1f7

Browse files
authored
Merge pull request #2106 from theotherjimmy/fix-makefile
[Exporter-gcc_arm] do builds from project directory when --source is specified
2 parents b547856 + 3697ded commit 36ff1f7

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

tools/export/gcc_arm_common.tmpl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded
33

44
# cross-platform directory manipulation
5-
ifeq ($(OSTYPE),)
5+
ifeq ($(shell echo $$OS),$$OS)
66
MAKEDIR = if not exist "$(1)" mkdir "$(1)"
7-
RM = rmdir /S /Q
7+
RM = rmdir /S /Q "$(1)"
88
else
9-
MAKEDIR = mkdir -p $(1)
10-
RM = rm -rf
9+
MAKEDIR = $(SHELL) -c "mkdir -p \"$(1)\""
10+
RM = $(SHELL) -c "rm -rf \"$(1)\""
1111
endif
1212

1313
ifeq (,$(filter .build,$(notdir $(CURDIR))))
1414
.SUFFIXES:
1515
OBJDIR := .build
16-
MAKETARGET = $(MAKE) --no-print-directory -C $(OBJDIR) -f $(CURDIR)/Makefile \
16+
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
17+
MAKETARGET = $(MAKE) --no-print-directory -C $(OBJDIR) -f $(mkfile_path) \
1718
SRCDIR=$(CURDIR) $(MAKECMDGOALS)
1819
.PHONY: $(OBJDIR) clean
1920
all:
@@ -23,19 +24,19 @@ $(OBJDIR): all
2324
Makefile : ;
2425
% :: $(OBJDIR) ; :
2526
clean :
26-
$(RM) $(OBJDIR)
27+
$(call RM,$(OBJDIR))
2728
{% block target_clean -%}
2829
{% endblock %}
2930
else
3031

31-
VPATH = $(SRCDIR)
32+
VPATH = {% for path in vpath %}{{path}} {% endfor %}
3233

3334
GCC_BIN =
3435
PROJECT = {{name}}
3536
OBJECTS = {% for f in to_be_compiled %}{{f}} {% endfor %}
3637
SYS_OBJECTS = {% for f in object_files %}{{f}} {% endfor %}
37-
INCLUDE_PATHS = {% for p in include_paths %}-I../{{p}} {% endfor %}
38-
LIBRARY_PATHS = {% for p in library_paths %}-L../{{p}} {% endfor %}
38+
INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %}
39+
LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %}
3940
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
4041
LINKER_SCRIPT = {{linker_script}}
4142
{%- block additional_variables -%}{% endblock %}

tools/export/gccarm.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
limitations under the License.
1616
"""
1717
from exporters import Exporter
18-
from os.path import splitext, basename
19-
from os import curdir
18+
from os.path import splitext, basename, relpath, join, abspath
19+
from os import curdir, getcwd
2020

2121

2222
class GccArm(Exporter):
@@ -132,8 +132,9 @@ class GccArm(Exporter):
132132

133133
def generate(self):
134134
# "make" wants Unix paths
135+
if self.sources_relative:
136+
self.resources.relative_to(self.prj_paths[0])
135137
self.resources.win_to_unix()
136-
self.resources.relative_to(curdir)
137138

138139
to_be_compiled = []
139140
for r_type in ['s_sources', 'c_sources', 'cpp_sources']:
@@ -148,6 +149,7 @@ def generate(self):
148149
l, _ = splitext(basename(lib))
149150
libraries.append(l[3:])
150151

152+
build_dir = abspath(join(self.inputDir, ".build"))
151153
ctx = {
152154
'name': self.program_name,
153155
'to_be_compiled': to_be_compiled,
@@ -157,7 +159,20 @@ def generate(self):
157159
'linker_script': self.resources.linker_script,
158160
'libraries': libraries,
159161
'symbols': self.get_symbols(),
160-
'cpu_flags': self.toolchain.cpu
162+
'cpu_flags': self.toolchain.cpu,
163+
'vpath': [relpath(s, build_dir) for s in self.prj_paths] if self.sources_relative else [".."]
161164
}
165+
166+
for key in ['include_paths', 'library_paths', 'linker_script']:
167+
if isinstance(ctx[key], list):
168+
ctx[key] = [ctx['vpath'][0] + "/" + t for t in ctx[key]]
169+
else:
170+
ctx[key] = ctx['vpath'][0] + "/" + ctx[key]
171+
if "../." not in ctx["include_paths"]:
172+
ctx["include_paths"] += ['../.']
162173
ctx.update(self.progen_flags)
163174
self.gen_file('gcc_arm_%s.tmpl' % self.target.lower(), ctx, 'Makefile')
175+
176+
def scan_and_copy_resources(self, prj_paths, trg_path, relative=False):
177+
self.prj_paths = prj_paths
178+
Exporter.scan_and_copy_resources(self, prj_paths, trg_path, relative)

tools/toolchains/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def relative_to(self, base, dot=False):
147147
v = [rel_path(f, base, dot) for f in getattr(self, field)]
148148
setattr(self, field, v)
149149

150-
self.features = {k: f.relative_to(base, dot) for k, f in self.features.iteritems()}
150+
self.features = {k: f.relative_to(base, dot) for k, f in self.features.iteritems() if f}
151151

152152
if self.linker_script is not None:
153153
self.linker_script = rel_path(self.linker_script, base, dot)
@@ -160,7 +160,7 @@ def win_to_unix(self):
160160
v = [f.replace('\\', '/') for f in getattr(self, field)]
161161
setattr(self, field, v)
162162

163-
self.features = {k: f.win_to_unix() for k, f in self.features.iteritems()}
163+
self.features = {k: f.win_to_unix() for k, f in self.features.iteritems() if f}
164164

165165
if self.linker_script is not None:
166166
self.linker_script = self.linker_script.replace('\\', '/')

0 commit comments

Comments
 (0)