diff --git a/Makefile b/Makefile index a7c3faf8a..2ce1a48a1 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/apps/Makefile b/apps/Makefile index 4e5077837..b3447cef6 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -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)) diff --git a/quiz/Makefile b/quiz/Makefile index 9e56ca958..2dce92b8d 100644 --- a/quiz/Makefile +++ b/quiz/Makefile @@ -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)