Skip to content
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
10 changes: 9 additions & 1 deletion tools/export/makefile/Makefile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ CC = {{cc_cmd}}
CPP = {{cppc_cmd}}
LD = {{ld_cmd}}
ELF2BIN = {{elf2bin_cmd}}
{% if pp_cmd -%}
PREPROC = {{pp_cmd}}
{%- endif %}
{% if hex_files %}
SREC_CAT = srec_cat
{%- endif %}
Expand Down Expand Up @@ -119,8 +122,13 @@ all: $(PROJECT).bin $(PROJECT).hex size
+@echo "Compile: $(notdir $<)"
@$(CPP) $(CXX_FLAGS) $(INCLUDE_PATHS) -o $@ $<

{% if pp_cmd %}
$(PROJECT).link_script{{link_script_ext}}: $(LINKER_SCRIPT)
@$(PREPROC) $< -o $@
{% endif %}

{% block target_project_elf %}
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LINKER_SCRIPT)
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) {% if pp_cmd -%} $(PROJECT).link_script{{link_script_ext}} {% else%} $(LINKER_SCRIPT) {% endif %}
+@echo "link: $(notdir $@)"
@$(LD) $(LD_FLAGS) {{link_script_option}} $(filter %{{link_script_ext}}, $^) $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES) $(LD_SYS_LIBS)
{% endblock %}
Expand Down
8 changes: 8 additions & 0 deletions tools/export/makefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def generate(self):
'user_library_flag': self.USER_LIBRARY_FLAG,
}

if hasattr(self.toolchain, "preproc"):
ctx['pp_cmd'] = " ".join(["\'" + part + "\'" for part
in ([basename(self.toolchain.preproc[0])] +
self.toolchain.preproc[1:] +
self.toolchain.ld[1:])])
else:
ctx['pp_cmd'] = None

for key in ['include_paths', 'library_paths', 'linker_script',
'hex_files']:
if isinstance(ctx[key], list):
Expand Down
12 changes: 11 additions & 1 deletion tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
"""
import re
from os.path import join, basename, splitext
from os.path import join, basename, splitext, dirname

from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
from tools.hooks import hook_tool
Expand Down Expand Up @@ -93,6 +93,7 @@ def __init__(self, target, notify=None, macros=None,
self.flags['ld'] += self.cpu
self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld']
self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"]
self.preproc = [join(tool_path, "arm-none-eabi-cpp"), "-E", "-P"]

self.ar = join(tool_path, "arm-none-eabi-ar")
self.elf2bin = join(tool_path, "arm-none-eabi-objcopy")
Expand Down Expand Up @@ -213,6 +214,15 @@ def link(self, output, objects, libraries, lib_dirs, mem_map):
libs.append("-l%s" % name[3:])
libs.extend(["-l%s" % l for l in self.sys_libs])

# Preprocess
if mem_map:
preproc_output = join(dirname(output), ".link_script.ld")
cmd = (self.preproc + [mem_map] + self.ld[1:] +
[ "-o", preproc_output])
self.cc_verbose("Preproc: %s" % ' '.join(cmd))
self.default_cmd(cmd)
mem_map = preproc_output

# Build linker command
map_file = splitext(output)[0] + ".map"
cmd = self.ld + ["-o", output, "-Wl,-Map=%s" % map_file] + objects + ["-Wl,--start-group"] + libs + ["-Wl,--end-group"]
Expand Down