-
Notifications
You must be signed in to change notification settings - Fork 66
/
Makefile
91 lines (68 loc) · 2.17 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
CXXFLAGS += -Wall -std=c++11 \
-Werror \
-Wextra \
-Wconversion \
-Wno-deprecated \
-Winit-self \
-Wsign-conversion \
-Wredundant-decls \
-Wvla -Wshadow -Wctor-dtor-privacy -Wnon-virtual-dtor -Woverloaded-virtual \
-Winit-self \
-Wpointer-arith \
-Wcast-qual \
-Wcast-align \
-Wdouble-promotion \
-Wold-style-cast -Wno-error=old-style-cast \
-Wsign-promo \
-Wswitch-enum \
-Wswitch-default \
-MMD \
-O3 \
# -Wundef
CPPFLAGS += -I$(INC_DIR)
LDFLAGS += -lgtest_main \
-lgtest \
-lpthread \
-pthread \
-lgmock
EXE = BookConstructor
EXE_TEST = executeTests
SCR_DIR = src
BIN_DIR = bin
INC_DIR = include
BUILD_DIR = build
TEST_DIR = gtests
SOURCES=$(wildcard $(SCR_DIR)/*.cpp)
OBJECTS=$(SOURCES:$(SCR_DIR)/%.cpp=$(BUILD_DIR)/%.o)
SOURCES_T=$(wildcard $(TEST_DIR)/*.cpp)
OBJECTS_T=$(SOURCES_T:$(TEST_DIR)/%.cpp=$(BUILD_DIR)/%.o) $(filter-out $(BUILD_DIR)/main.o, $(OBJECTS))
# --------------------------------------------------------------
.PHONY: all clean distclean
.DEFAULT_GOAL:= all
all: directories $(BIN_DIR)/$(EXE)
#Make the Directories
directories:
@mkdir -p $(BUILD_DIR) $(BIN_DIR)
# --------------------------------------------------------------
$(BIN_DIR)/$(EXE): $(OBJECTS)
@$(CXX) $(CXXFLAGS) $^ -o $@
# --------------------------------------------------------------
test: directories $(BIN_DIR)/$(EXE_TEST)
$(BIN_DIR)/$(EXE_TEST): $(OBJECTS_T)
@$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ #put LDFLAGS before objects and LDLIBS after
# --------------------------------------------------------------
$(BUILD_DIR)/%.o : $(SCR_DIR)/%.cpp #$(SCR_DIR)/%.h $(SCR_DIR)/%.d
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
@echo "Compiling: $<"
$(BUILD_DIR)/%.o : $(TEST_DIR)/%.cpp
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@
@echo "Compiling: $<"
# --------------------------------------------------------------
-include $(OBJECTS:%.o=%.d) #(.d are dependency files automatically produced by -MMD flag)
clean:
@$(RM) $(BUILD_DIR)/* #delete all files(.o, .d)
@echo "Removing: * from $(BUILD_DIR)"
distclean: clean
@$(RM) $(BIN_DIR)/$(EXE) $(BIN_DIR)/$(EXE_TEST)
@echo "Removing: * from $(BIN_DIR)"
print-% : ; @echo $* = $($*)