1 .PHONY : all compile link clean rebuild $(MODULES) 2 3 DIR_PROJECT := $(realpath .) 4 DIR_BUILD_SUB := $(addprefix $(DIR_BUILD)/, $(MODULES)) 5 MODULE_LIB := $(addsuffix .a, $(MODULES)) 6 MODULE_LIB := $(addprefix $(DIR_BUILD)/, $(MODULE_LIB)) 7 8 9 APP := $(addprefix $(DIR_BUILD)/, $(APP)) 10 11 define makemodule 12 cd $(1) && 13 $(MAKE) all 14 DEBUG:=$(DEBUG) 15 DIR_BUILD:=$(addprefix $(DIR_PROJECT)/, $(DIR_BUILD)) 16 DIR_COMMON_INC:=$(addprefix $(DIR_PROJECT)/, $(DIR_COMMON_INC)) 17 CMD_CFG:=$(addprefix $(DIR_PROJECT)/, $(CMD_CFG)) 18 MOD_CFG:=$(addprefix $(DIR_PROJECT)/, $(MOD_CFG)) 19 MOD_RULE:=$(addprefix $(DIR_PROJECT)/, $(MOD_RULE)) && 20 cd .. ; 21 endef 22 23 all : compile $(APP) 24 @echo "Success! Target ==> $(APP)" 25 26 compile : $(DIR_BUILD) $(DIR_BUILD_SUB) 27 @echo "Begin to compile ..." 28 @set -e; 29 for dir in $(MODULES); 30 do 31 $(call makemodule, $$dir) 32 done 33 @echo "Compile Success!" 34 35 link $(APP) : $(MODULE_LIB) 36 @echo "Begin to link ..." 37 $(CC) -o $(APP) -Xlinker "-(" $^ -Xlinker "-)" $(LFLAGS) 38 @echo "Link Success!" 39 40 $(DIR_BUILD) $(DIR_BUILD_SUB) : 41 $(MKDIR) [email protected] 42 43 clean : 44 @echo "Begin to clean ..." 45 $(RM) $(DIR_BUILD) 46 @echo "Clean Success!" 47 48 rebuild : clean all 49 50 $(MODULES) : $(DIR_BUILD) $(DIR_BUILD)/$(MAKECMDGOALS) 51 @echo "Begin to compile [email protected]" 52 @set -e; 53 $(call makemodule, [email protected]) 54
原文地址:https://www.cnblogs.com/wanmeishenghuo/p/9735278.html
时间: 2024-10-21 12:47:34