Skip to content

Commit 3155e71

Browse files
committed
Add pre-processing of linker scripts to Make exporter
For toolchains that do not implicitly run the C pre-processor on their linker scripts the toolchain is expected to define a `preproc` attribute. The Makefiles then pick up on this attribute and add another rule for pre-processing the linker script automatically.
1 parent af4d848 commit 3155e71

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

tools/export/makefile/Makefile.tmpl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ CC = {{cc_cmd}}
6767
CPP = {{cppc_cmd}}
6868
LD = {{ld_cmd}}
6969
ELF2BIN = {{elf2bin_cmd}}
70+
{% if pp_cmd -%}
71+
PREPROC = {{pp_cmd}}
72+
{%- endif %}
7073
{% if hex_files %}
7174
SREC_CAT = srec_cat
7275
{%- endif %}
@@ -119,8 +122,13 @@ all: $(PROJECT).bin $(PROJECT).hex size
119122
+@echo "Compile: $(notdir $<)"
120123
@$(CPP) $(CXX_FLAGS) $(INCLUDE_PATHS) -o $@ $<
121124

125+
{% if pp_cmd %}
126+
$(PROJECT).link_script{{link_script_ext}}: $(LINKER_SCRIPT)
127+
@$(PREPROC) $< -o $@
128+
{% endif %}
129+
122130
{% block target_project_elf %}
123-
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LINKER_SCRIPT)
131+
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) {% if pp_cmd -%} $(PROJECT).link_script{{link_script_ext}} {% else%} $(LINKER_SCRIPT) {% endif %}
124132
+@echo "link: $(notdir $@)"
125133
@$(LD) $(LD_FLAGS) {{link_script_option}} $(filter %{{link_script_ext}}, $^) $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES) $(LD_SYS_LIBS)
126134
{% endblock %}

tools/export/makefile/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ def generate(self):
8787
'user_library_flag': self.USER_LIBRARY_FLAG,
8888
}
8989

90+
if hasattr(self.toolchain, "preproc"):
91+
ctx['pp_cmd'] = " ".join(["\'" + part + "\'" for part
92+
in ([basename(self.toolchain.preproc[0])] +
93+
self.toolchain.preproc[1:] +
94+
self.toolchain.ld[1:])])
95+
else:
96+
ctx['pp_cmd'] = None
97+
9098
for key in ['include_paths', 'library_paths', 'linker_script',
9199
'hex_files']:
92100
if isinstance(ctx[key], list):

0 commit comments

Comments
 (0)