-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
97 lines (71 loc) · 2.68 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
CXX = g++
CXXFLAGS = -std=c++11 -Wall -ggdb -Wno-unused
LINKS = -lpthread
TEST_LINKS = -lgtest
BUILD_DIR = ./build
BIN_DIR = ./bin
# Create 'build' and 'bin' folders
$(shell test -d $(BUILD_DIR) || mkdir -p $(BUILD_DIR))
$(shell test -d $(BIN_DIR) || mkdir -p $(BIN_DIR))
DIR_SRC_DIR = ./src
TEST_SRC_DIR = ./test
BENCHMARK_TEST_SRC_DIR = ./benchmark
TOOL_SRC_DIR = ./tools
SRC1 = $(wildcard $(DIR_SRC_DIR)/*.cpp $(DIR_SRC_DIR)/net/*.cpp)
SRC = $(filter-out $(DIR_SRC_DIR)/main.cpp, $(SRC1))
OBJ = $(patsubst %.cpp, $(BUILD_DIR)/%.o, $(notdir $(SRC)))
INC = $(patsubst %, %, $(shell find src -name '[a-zA-Z0-9]*'.h))
# main program
KVMAIN_TARGET = $(BIN_DIR)/kvmain
# testing programs
TEST_SRCS = $(wildcard $(TEST_SRC_DIR)/*.cpp)
TEST_TARGETS = $(patsubst %.cpp, $(BIN_DIR)/%, $(notdir $(TEST_SRCS)))
# benchmark testing programs
BENCHMARK_SRCS = $(wildcard $(BENCHMARK_TEST_SRC_DIR)/*.cpp)
BENCHMARK_TARGETS = $(patsubst %.cpp, $(BIN_DIR)/%, $(notdir $(BENCHMARK_SRCS)))
# tools
TOOLS_SRCS = $(wildcard $(TOOL_SRC_DIR)/*.cpp)
TOOLS_TARGETS = $(patsubst %.cpp, $(BIN_DIR)/%, $(notdir $(TOOLS_SRCS)))
D_TCMALLOC_FLAG =
TCMALLOC_LINK =
TCMALLOC_FOUND = $(shell find /usr/lib/ -name '*tcmalloc*')
ifneq ($(strip $(TCMALLOC_FOUND)),)
D_TCMALLOC_FLAG = -O2 -DTCMALLOC_FOUND
TCMALLOC_LINK = -ltcmalloc
endif
all: $(KVMAIN_TARGET) $(TEST_TARGETS) $(BENCHMARK_TARGETS) $(TOOLS_TARGETS)
kvmain: $(KVMAIN_TARGET)
test: $(TEST_TARGETS)
benchmark: $(BENCHMARK_TARGETS)
tools: $(TOOLS_TARGETS)
$(TOOLS_TARGETS) : $(BIN_DIR)/% : $(TOOL_SRC_DIR)/%.cpp $(OBJ) $(INC)
$(CXX) $(CXXFLAGS) $(OBJ) $< -o $@ $(LINKS) $(D_TCMALLOC_FLAG) $(TCMALLOC_LINK)
@echo "Done generating tools"
$(BENCHMARK_TARGETS) : $(BIN_DIR)/% : $(BENCHMARK_TEST_SRC_DIR)/%.cpp $(OBJ) $(INC)
$(CXX) $(CXXFLAGS) $(OBJ) $< -o $@ $(LINKS) $(D_TCMALLOC_FLAG) $(TCMALLOC_LINK)
@echo "Done generating benchmark test targets"
$(TEST_TARGETS) : $(BIN_DIR)/% : $(TEST_SRC_DIR)/%.cpp $(OBJ) $(INC)
$(CXX) $(CXXFLAGS) $(OBJ) $< -o $@ $(LINKS) $(TEST_LINKS)
@echo "Done generating test targets"
$(KVMAIN_TARGET) : $(OBJ) $(INC)
$(CXX) $(CXXFLAGS) -c $(DIR_SRC_DIR)/main.cpp -o $(BUILD_DIR)/main.o $(D_TCMALLOC_FLAG)
$(CXX) $(CXXFLAGS) $(OBJ) $(BUILD_DIR)/main.o -o $@ $(LINKS) $(TCMALLOC_LINK)
@echo "Done generating kvmain"
$(BUILD_DIR)/%.o : $(DIR_SRC_DIR)/net/%.cpp $(INC)
$(CXX) $(CXXFLAGS) -c $< -o $@
$(BUILD_DIR)/%.o : $(DIR_SRC_DIR)/%.cpp $(INC)
$(CXX) $(CXXFLAGS) -c $< -o $@
.PHONY: clean display check_tcmalloc
display:
@echo $(TEST_TARGETS)
@echo $(BENCHMARK_TARGETS)
@echo $(OBJ)
@echo $(SRC)
clean:
-rm -r build/*
-rm $(TEST_TARGETS)
-rm $(KVMAIN_TARGET)
-rm $(BENCHMARK_TARGETS)
-rm $(TOOLS_TARGETS)
check_tcmalloc:
@echo $(D_TCMALLOC_FLAG)