Article From:https://www.cnblogs.com/wanmeishenghuo/p/9735215.html

 

 

 

 

 

 

 

 1 .PHONY : all compile link clean rebuild
 2 
 3 MODULES := common \
 4            module \
 5            main
 6            
 7 MKDIR := mkdir
 8 RM := rm -fr
 9 
10 CC := gcc
11 LFLAGS := 
12 
13 DIR_PROJECT := $(realpath .)
14 DIR_BUILD := build
15 DIR_BUILD_SUB := $(addprefix $(DIR_BUILD)/, $(MODULES))
16 MODULE_LIB := $(addsuffix .a, $(MODULES))
17 MODULE_LIB := $(addprefix $(DIR_BUILD)/, $(MODULE_LIB))
18 
19 APP := app.out
20 APP := $(addprefix $(DIR_BUILD)/, $(APP))
21 
22 all : compile $(APP)
23     @echo "Success! Target ==> $(APP)"
24 
25 compile : $(DIR_BUILD) $(DIR_BUILD_SUB)
26     @echo "Begin to compile ..."
27     @set -e; \
28     for dir in $(MODULES); \
29     do \
30         cd $$dir && $(MAKE) all DEBUG:=$(DEBUG) && cd .. ; \
31     done
32     @echo "Compile Success!"
33     
34 link $(APP) : $(MODULE_LIB)
35     @echo "Begin to link ..."
36     $(CC) -o $(APP) -Xlinker "-(" $^ -Xlinker "-)" $(LFLAGS)
37     @echo "Link Success!"
38     
39 $(DIR_BUILD) $(DIR_BUILD_SUB) : 
40     $(MKDIR) $@
41     
42 clean : 
43     @echo "Begin to clean ..."
44     $(RM) $(DIR_BUILD)
45     @echo "Clean Success!"
46     
47 rebuild : clean all

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *