Skip to content

Commit 00d2a45

Browse files
committed
Generalize make exporters for all toolchains
1 parent 17e096b commit 00d2a45

22 files changed

+221
-285
lines changed

tools/export/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
'uvision4': uvision4.Uvision4,
3333
'uvision5': uvision5.Uvision5,
3434
'lpcxpresso': codered.CodeRed,
35-
'gcc_arm': makefile.GccArm,
36-
'make_gcc_arm': makefile.GccArm,
35+
'gcc_arm': makefile.GccArm_Exporter,
36+
'make_gcc_arm': makefile.GccArm_Exporter,
37+
'make_armc5': makefile.Armc5_Exporter,
38+
'make_iar': makefile.IAR_Exporter,
3739
'ds5_5': ds5_5.DS5_5,
3840
'iar': iar.IAREmbeddedWorkbench,
3941
'emblocks' : emblocks.IntermediateFile,

tools/export/makefile/Makefile.tmpl

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# This file was automagically generated by mbed.org. For more information,
2+
# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded
3+
4+
###############################################################################
5+
# Boiler-plate
6+
7+
# cross-platform directory manipulation
8+
ifeq ($(shell echo $$OS),$$OS)
9+
MAKEDIR = if not exist "$(1)" mkdir "$(1)"
10+
RM = rmdir /S /Q "$(1)"
11+
else
12+
MAKEDIR = $(SHELL) -c "mkdir -p \"$(1)\""
13+
RM = $(SHELL) -c "rm -rf \"$(1)\""
14+
endif
15+
16+
# Move to the build directory
17+
ifeq (,$(filter .build,$(notdir $(CURDIR))))
18+
.SUFFIXES:
19+
OBJDIR := .build
20+
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
21+
MAKETARGET = $(MAKE) --no-print-directory -C $(OBJDIR) -f $(mkfile_path) \
22+
SRCDIR=$(CURDIR) $(MAKECMDGOALS)
23+
.PHONY: $(OBJDIR) clean
24+
all:
25+
+@$(call MAKEDIR,$(OBJDIR))
26+
+@$(MAKETARGET)
27+
$(OBJDIR): all
28+
Makefile : ;
29+
% :: $(OBJDIR) ; :
30+
clean :
31+
$(call RM,$(OBJDIR))
32+
{% block target_clean -%}
33+
{% endblock %}
34+
else
35+
36+
# trick rules into thinking we are in the root, when we are in the bulid dir
37+
VPATH = {{vpath|join(" ")}}
38+
39+
# Boiler-plate
40+
###############################################################################
41+
# Project settings
42+
43+
PROJECT := {{name}}
44+
45+
{% for sym in symbols %}CC_SYMBOLS += -D{{sym}}
46+
{% endfor %}
47+
48+
# Project settings
49+
###############################################################################
50+
# Objects and Paths
51+
52+
{% for obj in to_be_compiled %}OBJECTS += {{obj}}
53+
{% endfor %}
54+
{% for obj in object_files %} SYS_OBJECTS += {{obj}}
55+
{% endfor %}
56+
{% for path in include_paths %}INCLUDE_PATHS += -I{{path}}
57+
{% endfor %}
58+
LIBRARY_PATHS :={% for p in library_paths %} -L{{p}} {% endfor %}
59+
LIBRARIES :={% for lib in libraries %} -l{{lib}} {% endfor %}
60+
LINKER_SCRIPT := {{linker_script}}
61+
{%- block additional_variables -%}{% endblock %}
62+
63+
# Objects and Paths
64+
###############################################################################
65+
# Tools and Flags
66+
67+
AS = {{asm_cmd}}
68+
CC = {{cc_cmd}}
69+
CPP = {{cppc_cmd}}
70+
LD = {{ld_cmd}}
71+
ELF2BIN = {{elf2bin_cmd}}
72+
{% if hex_files %}
73+
SREC_CAT = srec_cat
74+
{%- endif %}
75+
{%- block additional_executables -%}{%- endblock %}
76+
77+
LD_FLAGS :={%- block ld_flags -%} {{ld_flags|join(" ")}} {% endblock %}
78+
{% block sys_libs -%}{%- endblock %}
79+
80+
# Tools and Flags
81+
###############################################################################
82+
# Rules
83+
84+
.PHONY: all lst size
85+
86+
{% if hex_files -%}
87+
all: $(PROJECT).bin $(PROJECT)-combined.hex size
88+
{% else %}
89+
all: $(PROJECT).bin $(PROJECT).hex size
90+
{% endif %}
91+
92+
.asm.o:
93+
+@$(call MAKEDIR,$(dir $@))
94+
$(AS) -c $(CC_SYMBOLS) $(INCLUDE_PATHS) -o $@ $<
95+
.s.o:
96+
+@$(call MAKEDIR,$(dir $@))
97+
$(AS) -c $(CC_SYMBOLS) $(INCLUDE_PATHS) -o $@ $<
98+
.S.o:
99+
+@$(call MAKEDIR,$(dir $@))
100+
$(AS) -c $(CC_SYMBOLS) $(INCLUDE_PATHS) -o $@ $<
101+
102+
.c.o:
103+
+@$(call MAKEDIR,$(dir $@))
104+
$(CC) $(CC_SYMBOLS) $(INCLUDE_PATHS) -o $@ $<
105+
106+
.cpp.o:
107+
+@$(call MAKEDIR,$(dir $@))
108+
$(CPP) $(CC_SYMBOLS) $(INCLUDE_PATHS) -o $@ $<
109+
110+
{% block target_project_elf %}
111+
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LINKER_SCRIPT)
112+
$(LD) $(LD_FLAGS) {{link_script_option}} $(filter %{{link_script_ext}}, $^) $(LIBRARY_PATHS) --output $@ $(filter %.o, $^) $(LIBRARIES) $(LD_SYS_LIBS)
113+
{% endblock %}
114+
115+
$(PROJECT).bin: $(PROJECT).elf
116+
{%- block elf2bin -%}{%- endblock %}
117+
118+
$(PROJECT).hex: $(PROJECT).elf
119+
{%- block elf2hex -%}{%- endblock %}
120+
121+
{% if hex_files %}
122+
$(PROJECT)-combined.hex: $(PROJECT).hex
123+
$(SREC_CAT) {% for f in hex_files %}{{f}} {% endfor %} -intel $(PROJECT).hex -intel -o $(PROJECT)-combined.hex -intel --line-length=44
124+
{% endif %}
125+
# Rules
126+
###############################################################################
127+
# Dependencies
128+
129+
DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)
130+
-include $(DEPS)
131+
endif
132+
133+
# Dependencies
134+
###############################################################################
135+

tools/export/makefile/__init__.py

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
exists
1919
from os import curdir, getcwd
2020
from tools.export.exporters import Exporter
21+
from tools.utils import NotSupportedException
2122
from jinja2.exceptions import TemplateNotFound
2223

2324

24-
class GccArm(Exporter):
25-
NAME = 'GccArm'
26-
TOOLCHAIN = 'GCC_ARM'
25+
class Makefile(Exporter):
2726

2827
TARGETS = [
2928
'LPC1768',
@@ -164,11 +163,17 @@ def generate(self):
164163
'linker_script': self.resources.linker_script,
165164
'libraries': libraries,
166165
'symbols': self.toolchain.get_symbols(),
167-
'cpu_flags': self.toolchain.cpu,
168166
'hex_files': self.resources.hex_files,
169167
'vpath': (["../../.."]
170168
if basename(dirname(dirname(self.export_dir))) == "projectfiles"
171-
else [".."])
169+
else [".."]),
170+
'cc_cmd': " ".join(self.toolchain.cc),
171+
'cppc_cmd': " ".join(self.toolchain.cppc),
172+
'asm_cmd': " ".join(self.toolchain.asm),
173+
'ld_cmd': " ".join(self.toolchain.ld),
174+
'elf2bin_cmd': self.toolchain.elf2bin,
175+
'link_script_ext': self.toolchain.LINKER_EXT,
176+
'link_script_option': self.LINK_SCRIPT_OPTION,
172177
}
173178

174179
for key in ['include_paths', 'library_paths', 'linker_script', 'hex_files']:
@@ -178,8 +183,40 @@ def generate(self):
178183
ctx[key] = ctx['vpath'][0] + "/" + ctx[key]
179184
if "../." not in ctx["include_paths"]:
180185
ctx["include_paths"] += ['../.']
186+
ctx["include_paths"] = list(set(ctx["include_paths"]))
187+
for key in ['include_paths', 'library_paths', 'hex_files', 'to_be_compiled', 'symbols']:
188+
ctx[key] = sorted(ctx[key])
181189
ctx.update(self.flags)
182-
try:
183-
self.gen_file('gcc_arm_%s.tmpl' % self.target.lower(), ctx, 'Makefile')
184-
except TemplateNotFound:
185-
self.gen_file('gcc_arm_common.tmpl', ctx, 'Makefile')
190+
191+
for templatefile in \
192+
['makefile/%s_%s.tmpl' % (self.NAME.lower(),
193+
self.target.lower())] + \
194+
['makefile/%s_%s.tmpl' % (self.NAME.lower(),
195+
label.lower()) for label
196+
in self.toolchain.target.extra_labels] +\
197+
['makefile/%s.tmpl' % self.NAME.lower()]:
198+
try:
199+
self.gen_file(templatefile, ctx, 'Makefile')
200+
break
201+
except TemplateNotFound:
202+
pass
203+
else:
204+
raise NotSupportedException("This make tool is in development")
205+
206+
207+
class GccArm_Exporter(Makefile):
208+
NAME = 'Make-GCC-ARM'
209+
TOOLCHAIN = "GCC_ARM"
210+
LINK_SCRIPT_OPTION = "-T"
211+
212+
213+
class Armc5_Exporter(Makefile):
214+
NAME = 'Make-ARMc5'
215+
TOOLCHAIN = "ARM"
216+
LINK_SCRIPT_OPTION = "--scatter"
217+
218+
219+
class IAR_Exporter(Makefile):
220+
NAME = 'Make-IAR'
221+
TOOLCHAIN = "IAR"
222+
LINK_SCRIPT_OPTION = "--config"

tools/export/makefile/gcc_arm_common.tmpl

Lines changed: 0 additions & 141 deletions
This file was deleted.

tools/export/makefile/gcc_arm_lpc1114.tmpl

Lines changed: 0 additions & 10 deletions
This file was deleted.

tools/export/makefile/gcc_arm_lpc11u24.tmpl

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)