Skip to content

[Exporter-gcc_arm] do builds from project directory when --source is specified #2106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions tools/export/gcc_arm_common.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
# 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
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))))
.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:
Expand All @@ -23,19 +24,19 @@ $(OBJDIR): all
Makefile : ;
% :: $(OBJDIR) ; :
clean :
$(RM) $(OBJDIR)
$(call RM,$(OBJDIR))
{% block target_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 %}
Expand Down
23 changes: 19 additions & 4 deletions tools/export/gccarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
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):
Expand Down Expand Up @@ -132,8 +132,9 @@ class GccArm(Exporter):

def generate(self):
# "make" wants Unix paths
if self.sources_relative:
self.resources.relative_to(self.prj_paths[0])
self.resources.win_to_unix()
self.resources.relative_to(curdir)

to_be_compiled = []
for r_type in ['s_sources', 'c_sources', 'cpp_sources']:
Expand All @@ -148,6 +149,7 @@ def generate(self):
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,
Expand All @@ -157,7 +159,20 @@ def generate(self):
'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)
4 changes: 2 additions & 2 deletions tools/toolchains/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def relative_to(self, base, dot=False):
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)
Expand All @@ -160,7 +160,7 @@ def win_to_unix(self):
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('\\', '/')
Expand Down