-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
161 lines (125 loc) · 3.54 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
TARGET_EXEC ?= CubicServer
TARGET_TESTS ?= glados
CXX ?= gcc
BUILD_DIR := build
BUILD_DIR_TESTS := build_tests
SRC_DIRS := cubic-server
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
OBJS_TESTS := $(SRCS:%=$(BUILD_DIR_TESTS)/%.o)
DEPS := $(OBJS:.o=.d)
LIB_FOLDERS := $(shell ls -d libs/*/)
INC_DIRS := $(SRC_DIRS) $(addsuffix include,$(LIB_FOLDERS))
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CPPFLAGS := $(INC_FLAGS) -MMD -MP
ifeq ($(MC_VERSION), 1.21)
CPPFLAGS += -DCUBIC_MC_VERSION=1.21 -DCUBIC_MC_PROTOCOL=767
else
$(error Minecraft version not supported or MC_VERSION env variable not set)
endif
CXXFLAGS := -Wall
CXXFLAGS += -Wextra
CXXFLAGS += -Wconversion
CXXFLAGS += -std=c++17
CXXFLAGS += -Wp,-U_FORTIFY_SOURCE
CXXFLAGS += -Wformat=2
CXXFLAGS += -Wcast-qual
CXXFLAGS += -Wconversion
CXXFLAGS += -Wdisabled-optimization
CXXFLAGS += -Werror=return-type
CXXFLAGS += -Winit-self
CXXFLAGS += -Winline
CXXFLAGS += -Wredundant-decls
CXXFLAGS += -Wshadow
CXXFLAGS += -Wundef
CXXFLAGS += -Wunreachable-code
CXXFLAGS += -Wwrite-strings
CXXFLAGS += -Wno-missing-field-initializers
ifeq ($(CXX), g++)
CXXFLAGS += -Wduplicated-branches
CXXFLAGS += -Wduplicated-cond
CXXFLAGS += -Werror=vla-larger-than=0
CXXFLAGS += -Wlogical-op
endif
LDFLAGS := -Llibs/cubic-protocol -lcubic-protocol
# TODO: Set this up in a more generic way
NEEDED_LIBS := libs/cubic-protocol/libcubic-protocol.a
ifeq ($(DEBUG), 1)
CXXFLAGS += -Og -ggdb
else
CXXFLAGS += -O3 -DNDEBUG
LDFLAGS += -s
endif
ifeq ($(LTO), 1)
CXXFLAGS += -flto
# This will break with DEBUG=1, but who the hell builds with
# LTOs and debug at the same time?
# I could also make it throw an error if DEBUG and LTO are activated
# at the same time but for now this will do
LDFLAGS += -flto -O3
endif
ifeq ($(ASAN), 1)
CXXFLAGS += -fsanitize=address,leak,undefined
LDFLAGS += -fsanitize=address,leak,undefined
endif
ifeq ($(NATIVE), 1)
CXXFLAGS += -march=native -mtune=native
endif
# -fanalyzer is quite broken in g++, deactivate by default
ifeq ($(ANALYZER), 1)
ifeq ($(CXX), g++)
CXXFLAGS += -fanalyzer
CXXFLAGS += -Wno-analyzer-use-of-uninitialized-value
endif
endif
.PHONY: all
all:
$(MAKE) all-libs
$(MAKE) $(TARGET_EXEC)
.PHONY: tests_run
tests_run:
$(MAKE) all-libs
$(MAKE) tests_run-libs
$(MAKE) $(TARGET_TESTS)
./$(TARGET_TESTS)
$(TARGET_EXEC): $(BUILD_DIR)/$(TARGET_EXEC)
cp $(BUILD_DIR)/$(TARGET_EXEC) $(TARGET_EXEC)
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS) $(NEEDED_LIBS)
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
$(TARGET_TESTS): $(BUILD_DIR_TESTS)/$(TARGET_TESTS)
cp $(BUILD_DIR_TESTS)/$(TARGET_TESTS) $(TARGET_TESTS)
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): CPPFLAGS += -DUNIT_TESTS=1
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): CXXFLAGS += --coverage
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): LDFLAGS += -lcriterion --coverage
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): $(OBJS_TESTS) $(NEEDED_LIBS)
$(CXX) $(OBJS_TESTS) -o $@ $(LDFLAGS)
$(BUILD_DIR_TESTS)/%.cpp.o: %.cpp
@mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(BUILD_DIR)/%.cpp.o: %.cpp
@mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: all-libs
all-libs: $(LIB_FOLDERS)
$(MAKE) -C $^ all
.PHONY: tests_run-libs
tests_run-libs: $(LIB_FOLDERS)
$(MAKE) -C $^ tests_run
.PHONY: clean-libs
clean-libs: $(LIB_FOLDERS)
$(MAKE) -C $^ clean
.PHONY: fclean-libs
fclean-libs: $(LIB_FOLDERS)
$(MAKE) -C $^ fclean
.PHONY: clean
clean: clean-libs
rm -rf $(BUILD_DIR)
rm -rf $(BUILD_DIR_TESTS)
.PHONY: fclean
fclean: fclean-libs clean
rm -f $(TARGET_EXEC)
rm -f $(TARGET_TESTS)
.PHONY: re
re: fclean
$(MAKE) all
-include $(DEPS)