include config/make/rules.mk APP ?= engine_control MAINFILE = $(EXE_DIR)/$(APP)$(ELF_EXT) BINFILE = $(EXE_DIR)/$(APP)$(BIN_EXT) HEXFILE = $(EXE_DIR)/$(APP)$(HEX_EXT) SIZEFILE = $(SIZE_DIR)/$(APP)$(SIZE_EXT) MAP_FILE = $(MAP_DIR)/$(APP)$(MAP_EXT) INCLUDES += $(SRC_DIR) SOURCES := $(wildcard $(SRC_DIR)/*.c) OBJECTS = $(SOURCES:$(ROOT_DIR)/%.c=$(OBJ_DIR)/%.o) DEPS = $(SOURCES:$(ROOT_DIR)/%.c=$(OBJ_DIR)/%.d) #include subfolders include source/application/application.mk SOURCES += $(foreach folder, $(SUB_FOLDER), $(wildcard $(ROOT_DIR)/$(folder)/*.c)) all: $(MAINFILE) $(MAINFILE): $(OBJECTS) @$(MKDIR) $(EXE_DIR) @$(MKDIR) $(MAP_DIR) @$(MKDIR) $(SIZE_DIR) $(CXX) $(GEN_FLAGS) $(L_FLAGS) -L$(LIB_DIR) -Wl,-Map,"$(MAP_FILE)" -o "$(MAINFILE)" $(OBJECTS) $(addprefix -l, $(LIBS)) $(OBJCOPY) $(MAINFILE) -O binary $(BINFILE) $(OBJCOPY) $(MAINFILE) -O ihex $(HEXFILE) $(NM) --size-sort --print-size $(MAINFILE) > $(SIZEFILE) @echo @$(SIZE) --format=berkeley -x $(MAINFILE) @echo $(OBJ_DIR)/%.o: $(ROOT_DIR)/%.c @$(MKDIR) $(OBJ_DIR) @$(foreach folder, $(SUB_FOLDER), $(shell mkdir -p $(OBJ_DIR)/$(folder))) $(call makedep,$<,$@,$(subst .o,.d,$@),$(GEN_FLAGS) $(C_FLAGS)) $(CC) $(GEN_FLAGS) $(C_FLAGS) -c -o "$@" "$<" clean: $(foreach folder, $(SUB_FOLDER), $(shell rm -f $(OBJ_DIR)/$(folder)/*.o)) $(foreach folder, $(SUB_FOLDER), $(shell rm -f $(OBJ_DIR)/$(folder)/*.d)) -rm -f $(OBJ_DIR)/*.o \ $(OBJ_DIR)/*.d \ $(MAINFILE) \ $(BINFILE) \ $(HEXFILE) \ $(SIZEFILE) distclean: -rm -rf $(ROOT_DIR)/release install: all $(PRE_PROGRAM) $(PROGRAM) ifneq "$(MAKECMDGOALS)" "clean" -include $(DEPS) else ifneq "$(MAKECMDGOALS)" "distclean" -include $(DEPS) endif endif