-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
57 lines (37 loc) · 1.26 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
OBJ_PATH=obj
BIN_PATH=bin
LIB_PATH=bin
# 不取测试文件
SRC_FILE= $(shell find . -name '*.cpp' | grep -v -E '^.+test_.+\.cpp')
SRC_NAME = $(notdir $(SRC_FILE))
OBJ_FILE = $(addprefix $(OBJ_PATH)/, $(patsubst %.cpp,%.o,$(SRC_NAME)))
INC_PATH = include .
INC_FLAG = $(addprefix -I, $(INC_PATH))
DEFINES = DEBUG
DEF_FLAG = $(addprefix -D, $(DEFINES))
OTH_FLAG = -Werror -Wall
CC_FLAG = $(INC_FLAG) $(DEF_FLAG) $(OTH_FLAG)
# MAIN_NAME = config/test_config
# OBJ_FILE= $(addsuffix .o, $(addprefix $(OBJ_PATH)/, $(SRC_NAME)))
# MAIN_FILE= $(addsuffix .c, $(addprefix $(SRC_PATH)/, $(MAIN_NAME)))
# LIB_FILE= $(addsuffix .a, $(addprefix $(OBJ_PATH)/, $(SRC_NAME)))
# BIN_FILE = $(addprefix $(BIN_PATH)/, $(MAIN_NAME))
CLEAN_OBJ =$(OBJ_FILE) .depend bin/* #$(BIN_FILE) $(LIB_FILE)
build: .depend $(OBJ_FILE)
# echo $(INC_FLAG)
$(BIN_FILE): $(OBJ_FILE)# $(MAIN_FILE)
g++ $(CC_FLAG) $^ -g -o $@
.depend: $(SRC_FILE)
g++ -MM $(CC_FLAG) $^ > $@
sed -i '/.o:/ s,^,obj/,' $@
include .depend
$(OBJ_PATH)/%.o:
g++ -c $< $(CC_FLAG) -g -o $@
# $(BIN_PATH)/%.out:
# TEST_NAME = $(notdir $@)
# TEST_FILE = $(patsubst %.out, %.cpp, $(TEST_NAME))
# TEST_FILE = $(shell find . -name $(TEST_FILE).cpp)
rebuild: clean build
clean:
-rm $(CLEAN_OBJ)
.PHONY: build rebuild clean