From 4735a38846cf6c152184393ed96890c7739ce33e Mon Sep 17 00:00:00 2001 From: Charles-Edouard de la Vergne Date: Mon, 9 Oct 2023 18:22:54 +0200 Subject: [PATCH] Fix conflict name issue during APP building - Separate object files into 2 distinct directories for both SDK and APP - Same modification for dependency files - Warn if same headers filename are found in both SDK and APP - Simplify the way source files list is generated --- Makefile.rules | 34 ++++++++++++++++++++++++++++------ Makefile.rules_generic | 10 +++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/Makefile.rules b/Makefile.rules index 5d06dc155..63ce413cd 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -26,6 +26,17 @@ SDK_SOURCE_PATH += lib_nbgl lib_ux_stax endif endif +define uniq = + $(eval seen :=) + $(foreach _,$1,$(if $(filter $_,${seen}),,$(eval seen += $_))) + ${seen} +endef + +define check_duplicate = + $(eval LIST := $(sort $(foreach file_h,$(notdir $1),$(notdir $(shell find $2 -name $(file_h)))))) + $(if $(LIST), $(warning Found duplicate files in SDK and APP: ${LIST})) +endef + # adding the correct target header to sources SDK_SOURCE_PATH += target/$(TARGET)/include @@ -37,12 +48,23 @@ ifeq ($(NO_CXNG),) INCLUDES_PATH += $(BOLOS_SDK)/lib_cxng/include endif -SOURCE_PATH += $(BOLOS_SDK)/src $(foreach libdir, $(SDK_SOURCE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) -name '*.[csS]'))) $(dir $(shell find $(APP_SOURCE_PATH) -name '*.[csS]')) -SOURCE_FILES += $(shell find $(SOURCE_PATH) -name '*.[csS]') $(GLYPH_DESTC) $(APP_SOURCE_FILES) -INCLUDES_PATH += $(dir $(foreach libdir, $(SDK_SOURCE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) -name '*.h')))) include $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm $(dir $(shell find $(APP_SOURCE_PATH) -name '*.h')) $(GLYPH_SRC_DIR) +# Retrieve SDK and APP sources separately +SOURCES_SDK += $(foreach libdir, src $(SDK_SOURCE_PATH), $(shell find $(BOLOS_SDK)/$(libdir) -name '*.[csS]')) +SOURCES_APP += $(SOURCE_FILES) $(foreach libdir, $(SOURCE_PATH) $(APP_SOURCE_PATH), $(shell find $(libdir) -name '*.[csS]')) $(GLYPH_DESTC) $(APP_SOURCE_FILES) +VPATH += $(call uniq, $(dir $(SOURCES_SDK) $(SOURCES_APP))) + +# Retrieve APP header filenames +INCLUDES_APP += $(shell find $(APP_SOURCE_PATH) -name '*.h') +# Warn if a same header filename is found in both APP and SDK +$(call check_duplicate, $(INCLUDES_APP), $(BOLOS_SDK)) +# Retrieve header directories +INCLUDES_PATH += $(call uniq, $(dir $(foreach libdir, $(SDK_SOURCE_PATH), $(dir $(shell find $(BOLOS_SDK)/$(libdir) -name '*.h')))) include $(BOLOS_SDK)/include $(BOLOS_SDK)/include/arm $(dir $(INCLUDES_APP)) $(GLYPH_SRC_DIR)) -VPATH += $(dir $(SOURCE_FILES)) -OBJECT_FILES += $(sort $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(basename $(notdir $(SOURCE_FILES)))))) -DEPEND_FILES += $(sort $(addprefix $(DEP_DIR)/, $(addsuffix .d, $(basename $(notdir $(SOURCE_FILES)))))) +# Separate object files from SDK and APP to avoid name conflicts +OBJECTS_SDK += $(sort $(addprefix $(OBJ_DIR)/sdk/, $(addsuffix .o, $(basename $(notdir $(SOURCES_SDK)))))) +OBJECTS_APP += $(sort $(addprefix $(OBJ_DIR)/app/, $(addsuffix .o, $(basename $(notdir $(SOURCES_APP)))))) +OBJECT_FILES = $(OBJECTS_SDK) $(OBJECTS_APP) +# Separate dependency files from SDK and APP to avoid name conflicts +DEPEND_FILES = $(subst $(OBJ_DIR),$(DEP_DIR),$(addsuffix .d, $(basename $(OBJECT_FILES)))) include $(BOLOS_SDK)/Makefile.rules_generic diff --git a/Makefile.rules_generic b/Makefile.rules_generic index d5300fc6f..05b99407c 100644 --- a/Makefile.rules_generic +++ b/Makefile.rules_generic @@ -67,7 +67,7 @@ BUILD_DEPENDENCIES += $(APP_CUSTOM_BUILD_DEPENDENCIES) prepare: $(L)echo Prepare directories - @mkdir -p $(BIN_DIR) $(OBJ_DIR) $(DBG_DIR) $(DEP_DIR) $(GEN_SRC_DIR) bin debug + @mkdir -p $(BIN_DIR) $(OBJ_DIR)/{sdk,app} $(DBG_DIR) $(DEP_DIR)/{sdk,app} $(GEN_SRC_DIR) bin debug $(BUILD_DEPENDENCIES): prepare @@ -76,15 +76,15 @@ DBG_TARGETS := debug/app.map debug/app.asm default: $(BIN_TARGETS) $(DBG_TARGETS) -$(OBJ_DIR)/%.o: %.c $(BUILD_DEPENDENCIES) prepare +$(OBJ_DIR)/%.o $(OBJ_DIR)/sdk/%.o $(OBJ_DIR)/app/%.o: %.c $(BUILD_DEPENDENCIES) prepare @echo "[CC] $@" $(L)$(call cc_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@) -$(OBJ_DIR)/%.o: %.s $(BUILD_DEPENDENCIES) prepare +$(OBJ_DIR)/%.o $(OBJ_DIR)/sdk/%.o $(OBJ_DIR)/app/%.o: %.s $(BUILD_DEPENDENCIES) prepare @echo "[AS] $@" $(L)$(call as_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@) -$(OBJ_DIR)/%.o: %.S $(BUILD_DEPENDENCIES) prepare +$(OBJ_DIR)/%.o $(OBJ_DIR)/sdk/%.o $(OBJ_DIR)/app/%.o: %.S $(BUILD_DEPENDENCIES) prepare @echo "[AS] $@" $(L)$(call as_cmdline,$(INCLUDES_PATH), $(DEFINES),$<,$@) @@ -156,7 +156,7 @@ endif # cc_cmdline(include,defines,src,dest) Macro that is used to format arguments for the compiler # dependency files are generated along the object file -cc_cmdline = $(CC) -c $(CFLAGS) -MMD -MT $(OBJ_DIR)/$(basename $(notdir $(4))).o -MF $(DEP_DIR)/$(basename $(notdir $(4))).d $(addprefix -D,$(2)) $(addprefix -I,$(1)) -o $(4) $(3) +cc_cmdline = $(CC) -c $(CFLAGS) -MMD -MT $(4) -MF $(subst $(OBJ_DIR),$(DEP_DIR),$(addsuffix .d, $(basename $(4)))) $(addprefix -D,$(2)) $(addprefix -I,$(1)) -o $(4) $(3) as_cmdline = $(AS) -c $(AFLAGS) $(addprefix -D,$(2)) $(addprefix -I,$(1)) -o $(4) $(3)