From 17e902c3f419274a9c23fad0fa83bbbeaccb51b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Thu, 14 Sep 2023 13:45:23 +0200 Subject: [PATCH] directly use object files when linking ELF Instead of taking all prerequisites and filtering out everything that is not an object just use the objects directly. It is both easier to understand and also more robust in case other non-object files are added to the prerequisites in the future. --- builddefs/common_rules.mk | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builddefs/common_rules.mk b/builddefs/common_rules.mk index 261ab7da02cd..52dccbe475bc 100644 --- a/builddefs/common_rules.mk +++ b/builddefs/common_rules.mk @@ -12,6 +12,9 @@ vpath %.hpp $(VPATH_SRC) vpath %.S $(VPATH_SRC) VPATH := +# Helper to return the distinct elements of a list +uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1))) + # Convert all SRC to OBJ define OBJ_FROM_SRC $(patsubst %.c,$1/%.o,$(patsubst %.cpp,$1/%.o,$(patsubst %.cc,$1/%.o,$(patsubst %.S,$1/%.o,$(patsubst %.clib,$1/%.a,$($1_SRC)))))) @@ -264,7 +267,7 @@ BEGIN = gccversion sizebefore # Note the obj.txt depeendency is there to force linking if a source file is deleted %.elf: $(OBJ) $(MASTER_OUTPUT)/cflags.txt $(MASTER_OUTPUT)/ldflags.txt $(MASTER_OUTPUT)/obj.txt | $(BEGIN) @$(SILENT) || printf "$(MSG_LINKING) $@" | $(AWK_CMD) - $(eval CMD=MAKE=$(MAKE) $(CC) $(ALL_CFLAGS) $(filter-out %.txt,$^) --output $@ $(LDFLAGS)) + $(eval CMD=MAKE=$(MAKE) $(CC) $(ALL_CFLAGS) $(call uniq,$(OBJ)) --output $@ $(LDFLAGS)) @$(BUILD_CMD)