mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #2106 from theotherjimmy/fix-makefile
[Exporter-gcc_arm] do builds from project directory when --source is specifiedpull/2047/head
commit
36ff1f73ce
|
|
@ -2,18 +2,19 @@
|
||||||
# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded
|
# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded
|
||||||
|
|
||||||
# cross-platform directory manipulation
|
# cross-platform directory manipulation
|
||||||
ifeq ($(OSTYPE),)
|
ifeq ($(shell echo $$OS),$$OS)
|
||||||
MAKEDIR = if not exist "$(1)" mkdir "$(1)"
|
MAKEDIR = if not exist "$(1)" mkdir "$(1)"
|
||||||
RM = rmdir /S /Q
|
RM = rmdir /S /Q "$(1)"
|
||||||
else
|
else
|
||||||
MAKEDIR = mkdir -p $(1)
|
MAKEDIR = $(SHELL) -c "mkdir -p \"$(1)\""
|
||||||
RM = rm -rf
|
RM = $(SHELL) -c "rm -rf \"$(1)\""
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq (,$(filter .build,$(notdir $(CURDIR))))
|
ifeq (,$(filter .build,$(notdir $(CURDIR))))
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
OBJDIR := .build
|
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)
|
SRCDIR=$(CURDIR) $(MAKECMDGOALS)
|
||||||
.PHONY: $(OBJDIR) clean
|
.PHONY: $(OBJDIR) clean
|
||||||
all:
|
all:
|
||||||
|
|
@ -23,19 +24,19 @@ $(OBJDIR): all
|
||||||
Makefile : ;
|
Makefile : ;
|
||||||
% :: $(OBJDIR) ; :
|
% :: $(OBJDIR) ; :
|
||||||
clean :
|
clean :
|
||||||
$(RM) $(OBJDIR)
|
$(call RM,$(OBJDIR))
|
||||||
{% block target_clean -%}
|
{% block target_clean -%}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
else
|
else
|
||||||
|
|
||||||
VPATH = $(SRCDIR)
|
VPATH = {% for path in vpath %}{{path}} {% endfor %}
|
||||||
|
|
||||||
GCC_BIN =
|
GCC_BIN =
|
||||||
PROJECT = {{name}}
|
PROJECT = {{name}}
|
||||||
OBJECTS = {% for f in to_be_compiled %}{{f}} {% endfor %}
|
OBJECTS = {% for f in to_be_compiled %}{{f}} {% endfor %}
|
||||||
SYS_OBJECTS = {% for f in object_files %}{{f}} {% endfor %}
|
SYS_OBJECTS = {% for f in object_files %}{{f}} {% endfor %}
|
||||||
INCLUDE_PATHS = {% for p in include_paths %}-I../{{p}} {% endfor %}
|
INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %}
|
||||||
LIBRARY_PATHS = {% for p in library_paths %}-L../{{p}} {% endfor %}
|
LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %}
|
||||||
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
|
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
|
||||||
LINKER_SCRIPT = {{linker_script}}
|
LINKER_SCRIPT = {{linker_script}}
|
||||||
{%- block additional_variables -%}{% endblock %}
|
{%- block additional_variables -%}{% endblock %}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
from exporters import Exporter
|
from exporters import Exporter
|
||||||
from os.path import splitext, basename
|
from os.path import splitext, basename, relpath, join, abspath
|
||||||
from os import curdir
|
from os import curdir, getcwd
|
||||||
|
|
||||||
|
|
||||||
class GccArm(Exporter):
|
class GccArm(Exporter):
|
||||||
|
|
@ -132,8 +132,9 @@ class GccArm(Exporter):
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
# "make" wants Unix paths
|
# "make" wants Unix paths
|
||||||
|
if self.sources_relative:
|
||||||
|
self.resources.relative_to(self.prj_paths[0])
|
||||||
self.resources.win_to_unix()
|
self.resources.win_to_unix()
|
||||||
self.resources.relative_to(curdir)
|
|
||||||
|
|
||||||
to_be_compiled = []
|
to_be_compiled = []
|
||||||
for r_type in ['s_sources', 'c_sources', 'cpp_sources']:
|
for r_type in ['s_sources', 'c_sources', 'cpp_sources']:
|
||||||
|
|
@ -148,6 +149,7 @@ class GccArm(Exporter):
|
||||||
l, _ = splitext(basename(lib))
|
l, _ = splitext(basename(lib))
|
||||||
libraries.append(l[3:])
|
libraries.append(l[3:])
|
||||||
|
|
||||||
|
build_dir = abspath(join(self.inputDir, ".build"))
|
||||||
ctx = {
|
ctx = {
|
||||||
'name': self.program_name,
|
'name': self.program_name,
|
||||||
'to_be_compiled': to_be_compiled,
|
'to_be_compiled': to_be_compiled,
|
||||||
|
|
@ -157,7 +159,20 @@ class GccArm(Exporter):
|
||||||
'linker_script': self.resources.linker_script,
|
'linker_script': self.resources.linker_script,
|
||||||
'libraries': libraries,
|
'libraries': libraries,
|
||||||
'symbols': self.get_symbols(),
|
'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)
|
ctx.update(self.progen_flags)
|
||||||
self.gen_file('gcc_arm_%s.tmpl' % self.target.lower(), ctx, 'Makefile')
|
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)
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ class Resources:
|
||||||
v = [rel_path(f, base, dot) for f in getattr(self, field)]
|
v = [rel_path(f, base, dot) for f in getattr(self, field)]
|
||||||
setattr(self, field, v)
|
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:
|
if self.linker_script is not None:
|
||||||
self.linker_script = rel_path(self.linker_script, base, dot)
|
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)]
|
v = [f.replace('\\', '/') for f in getattr(self, field)]
|
||||||
setattr(self, field, v)
|
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:
|
if self.linker_script is not None:
|
||||||
self.linker_script = self.linker_script.replace('\\', '/')
|
self.linker_script = self.linker_script.replace('\\', '/')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue