Skip to content

Commit 8658519

Browse files
committed
rework the common template to place objects into bin
1 parent c988ce1 commit 8658519

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

tools/export/gcc_arm_common.tmpl

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
# This file was automagically generated by mbed.org. For more information,
22
# see http://mbed.org/handbook/Exporting-to-GCC-ARM-Embedded
33

4+
ifeq (,$(filter bin,$(notdir $(CURDIR))))
5+
.SUFFIXES:
6+
OBJDIR := bin
7+
MAKETARGET = $(MAKE) --no-print-directory -C $@ -f $(CURDIR)/Makefile \
8+
SRCDIR=$(CURDIR) $(MAKECMDGOALS)
9+
.PHONY: $(OBJDIR) clean
10+
$(OBJDIR):
11+
+@[ -d $@ ] || mkdir -p $@
12+
+@$(MAKETARGET)
13+
Makefile : ;
14+
% :: $(OBJDIR) ; :
15+
clean :
16+
rm -rf $(OBJDIR)
17+
{% block target_clean -%}
18+
{% endblock %}
19+
else
20+
21+
VPATH = $(SRCDIR)
22+
423
GCC_BIN =
524
PROJECT = {{name}}
625
OBJECTS = {% for f in to_be_compiled %}{{f}} {% endfor %}
726
SYS_OBJECTS = {% for f in object_files %}{{f}} {% endfor %}
8-
INCLUDE_PATHS = {% for p in include_paths %}-I{{p}} {% endfor %}
9-
LIBRARY_PATHS = {% for p in library_paths %}-L{{p}} {% endfor %}
27+
INCLUDE_PATHS = {% for p in include_paths %}-I../{{p}} {% endfor %}
28+
LIBRARY_PATHS = {% for p in library_paths %}-L../{{p}} {% endfor %}
1029
LIBRARIES = {% for lib in libraries %}-l{{lib}} {% endfor %}
1130
LINKER_SCRIPT = {{linker_script}}
1231
{%- block additional_variables -%}{% endblock %}
@@ -49,34 +68,35 @@ else
4968
CC_FLAGS += -DNDEBUG -Os
5069
endif
5170

52-
.PHONY: all clean lst size
71+
.PHONY: all lst size
5372

5473
{% block target_all -%}
5574
all: $(PROJECT).bin $(PROJECT).hex size
5675
{% endblock %}
5776

58-
{% block target_clean -%}
59-
clean:
60-
rm -f $(PROJECT).bin $(PROJECT).elf $(PROJECT).hex $(PROJECT).map $(PROJECT).lst $(OBJECTS) $(DEPS)
61-
{% endblock %}
6277

6378
.asm.o:
79+
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
6480
$(CC) $(CPU) -c $(ASM_FLAGS) -o $@ $<
6581
.s.o:
82+
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
6683
$(CC) $(CPU) -c $(ASM_FLAGS) -o $@ $<
6784
.S.o:
85+
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
6886
$(CC) $(CPU) -c $(ASM_FLAGS) -o $@ $<
6987

7088
.c.o:
89+
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
7190
$(CC) $(CC_FLAGS) $(CC_SYMBOLS) $(INCLUDE_PATHS) -o $@ $<
7291

7392
.cpp.o:
93+
@[ -d $(dir $@) ] || mkdir -p $(dir $@)
7494
$(CPP) $(CPPC_FLAGS) $(CC_SYMBOLS) $(INCLUDE_PATHS) -o $@ $<
7595

7696

7797
{% block target_project_elf %}
78-
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS)
79-
$(LD) $(LD_FLAGS) -T$(LINKER_SCRIPT) $(LIBRARY_PATHS) -o $@ $^ -Wl,--start-group $(LIBRARIES) $(LD_SYS_LIBS) -Wl,--end-group
98+
$(PROJECT).elf: $(OBJECTS) $(SYS_OBJECTS) $(LINKER_SCRIPT)
99+
$(LD) $(LD_FLAGS) -T$(filter %.ld, $^) $(LIBRARY_PATHS) -o $@ $(filter %.o, $^) -Wl,--start-group $(LIBRARIES) $(LD_SYS_LIBS) -Wl,--end-group
80100
{% endblock %}
81101

82102
$(PROJECT).bin: $(PROJECT).elf
@@ -97,4 +117,5 @@ DEPS = $(OBJECTS:.o=.d) $(SYS_OBJECTS:.o=.d)
97117
-include $(DEPS)
98118

99119
{% block additional_targets %}{% endblock %}
120+
endif
100121

tools/export/gccarm.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717
from exporters import Exporter
1818
from os.path import splitext, basename
19+
from os import curdir
1920

2021

2122
class GccArm(Exporter):
@@ -128,6 +129,7 @@ class GccArm(Exporter):
128129
def generate(self):
129130
# "make" wants Unix paths
130131
self.resources.win_to_unix()
132+
self.resources.relative_to(curdir)
131133

132134
to_be_compiled = []
133135
for r_type in ['s_sources', 'c_sources', 'cpp_sources']:

0 commit comments

Comments
 (0)