Skip to content

Commit

Permalink
Fix conflict name issue during APP building
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
cedelavergne-ledger committed Oct 10, 2023
1 parent e8b56c4 commit 4735a38
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
34 changes: 28 additions & 6 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
10 changes: 5 additions & 5 deletions Makefile.rules_generic
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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),$<,$@)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 4735a38

Please sign in to comment.