Proper dependency tracking

Change-Id: Ib55da5b0c9779610c323ddaf6f695eb88d3583c7
This commit is contained in:
Romain Goyet
2016-11-11 19:52:15 +01:00
parent 6248a63b29
commit 5f04544503
3 changed files with 26 additions and 10 deletions

View File

@@ -33,7 +33,7 @@ endif
CFLAGS = -std=c99
CXXFLAGS = -std=c++11 -fno-exceptions -fno-rtti -fno-threadsafe-statics
products := boot.$(EXE) boot.$(EXE) boot.bin test.$(EXE) test.hex test.bin
products :=
ifeq ($(VERBOSE),1)
default: info clean app_size app_memory_map
@@ -56,6 +56,14 @@ info:
@echo "LDFLAGS = $(LDFLAGS)"
@echo "==============================="
# Each sub-Makefile can either add objects to the $(objs) variable or define a
# new executable target. The $(objs) variable lists the objects that will be
# linked to every executable being generated. Each Makefile is also responsible
# for keeping the $(product) variable updated. This variable lists all files
# that could be generated during the build and that needs to be cleaned up
# afterwards.
# Library Makefiles
ifeq ($(USE_LIBA),0)
include liba/Makefile.bridge
else
@@ -67,14 +75,18 @@ include ion/Makefile
include kandinsky/Makefile
include poincare/Makefile
include escher/Makefile
# Executable Makefiles
include apps/Makefile
include quiz/Makefile # Quiz should be included at the end
include quiz/Makefile # Quiz needs to be included at the end
dependencies = $(objs:.o=.d)
products += $(objs)
all_objs = $(filter %.o, $(products))
dependencies = $(all_objs:.o=.d)
-include $(dependencies)
products += $(dependencies)
.SECONDARY: $(objs)
%.$(EXE): $(objs)
@echo "LD $@"
@$(LD) $^ $(LDFLAGS) -o $@
@@ -90,13 +102,15 @@ dependencies = $(objs:.o=.d)
%_run: %.$(EXE)
$(GDB) -x gdb_script.gdb $<
ifdef OBJCOPY
products += $(products:.$(EXE)=.hex) $(products:.$(EXE)=.bin)
%.hex: %.$(EXE)
@echo "OBJCOPY $@"
@$(OBJCOPY) -O ihex $< $@
%.bin: %.$(EXE)
@echo "OBJCOPY $@"
@$(OBJCOPY) -O binary $< $@
endif
%.o: %.c
@echo "CC $@"
@@ -109,4 +123,4 @@ dependencies = $(objs:.o=.d)
.PHONY: clean
clean:
@echo "CLEAN"
@rm -f $(objs) $(products) $(dependencies)
@rm -f $(products)

View File

@@ -25,8 +25,9 @@ app_objs += $(addprefix apps/,\
# practice, this forces all the images to be before the app.
app_image_objs := $(app_images:.png=.o)
.SECONDARY: $(app_images:.png=.cpp)
$(app_objs): $(app_image_objs)
products += $(app_objs) $(call INLINER_PRODUCTS,$(app_images)) app.elf app.hex app.bin
app.$(EXE): $(app_objs) $(app_image_objs)
products += app.$(EXE) $(app_objs) $(call INLINER_PRODUCTS,$(app_images))

View File

@@ -9,6 +9,7 @@ $(symbols_file): $(tests)
runner_objs += $(addprefix quiz/src/, runner.o symbols.o)
test_objs = $(subst .c,.o, $(subst .cpp,.o,$(tests)))
products += test.$(EXE) test.hex test.bin $(runner_objs) $(test_objs)
test.$(EXE): $(objs) $(runner_objs) $(test_objs)
test.$(EXE): $(runner_objs) $(test_objs)
products += test.$(EXE) $(runner_objs) $(test_objs)