From 452333cb3664a8b301c6957e0aa52422759792e8 Mon Sep 17 00:00:00 2001 From: Leandro Lanzieri Date: Mon, 4 Oct 2021 11:31:19 +0200 Subject: [PATCH] Makefile.base: cleanup non selected source object files --- Makefile.base | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile.base b/Makefile.base index 58124cc1e527..4c285157ab3b 100644 --- a/Makefile.base +++ b/Makefile.base @@ -18,7 +18,7 @@ _MOD := $(shell basename $(CURDIR)) MODULE ?= $(_MOD) .PHONY: all clean $(DIRS:%=ALL--%) $(DIRS:%=CLEAN--%) $(MODULE).module \ - compile-commands $(DIRS:%=COMPILE-COMMANDS--%) + compile-commands $(DIRS:%=COMPILE-COMMANDS--%) $(MODULE).cleanup all: $(MODULE).module ..nothing @@ -113,9 +113,16 @@ include $(RIOTMAKE)/tools/fixdep.inc.mk $(BINDIR)/$(MODULE)/: $(Q)mkdir -p $@ +OLD_OBJECTS = $(wildcard $(BINDIR)/$(MODULE)/*.o) +OBJECTS_TO_REMOVE = $(filter-out $(OBJ),$(OLD_OBJECTS)) + $(MODULE).module compile-commands $(OBJ): | $(BINDIR)/$(MODULE)/ -$(MODULE).module: $(OBJ) | $(DIRS:%=ALL--%) +$(MODULE).module: $(OBJ) $(if $(OBJECTS_TO_REMOVE),$(MODULE).cleanup) | $(DIRS:%=ALL--%) + +$(MODULE).cleanup: + $(Q)# cleanup non selected source files objects + $(Q)$(RM) $(OBJECTS_TO_REMOVE) CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS) CCASFLAGS = $(filter-out $(CCASUWFLAGS), $(CFLAGS)) $(CCASEXFLAGS)