-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
167 lines (127 loc) · 3.49 KB
/
Makefile
File metadata and controls
167 lines (127 loc) · 3.49 KB
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
162
163
164
165
166
167
TARGET_LIB ?= libcubic-nbt
TARGET_TESTS ?= glados
CXX ?= g++
BUILD_DIR := build
BUILD_DIR_TESTS := build_tests
SRC_DIRS := src
TEST_DIRS := tests
INC_DIRS := include
INC_TEST_DIRS :=
TARGET_LIB_FLAG := -L. -l$(TARGET_LIB:lib%=%)
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp')
SRCS_TESTS := $(shell find $(TEST_DIRS) -name '*.cpp')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
OBJS_TESTS := $(SRCS_TESTS:%=$(BUILD_DIR_TESTS)/%.o)
DEPS := $(OBJS:.o=.d)
ifeq ($(shell mkdir -p ./libs && ls ./libs),)
LIB_FOLDERS :=
else
LIB_FOLDERS := $(shell ls -d ./libs/*/)
endif
INC_DIRS += $(addsuffix include,$(LIB_FOLDERS)) $(SRC_DIRS)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
INC_TEST_DIRS += $(addsuffix include,$(LIB_FOLDERS)) $(TEST_DIRS)
INC_FLAGS_TESTS := $(addprefix -I,$(INC_TEST_DIRS))
CPPFLAGS := -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
SHARED := 0
CXXFLAGS := -DCUBIC_PARSING_BUILD
CXXFLAGS += -Wall
CXXFLAGS += -Wextra
CXXFLAGS += -Wconversion
CXXFLAGS += -std=c++17
CXXFLAGS += -Wp,-U_FORTIFY_SOURCE
CXXFLAGS += -Wformat=2
CXXFLAGS += -Wcast-qual
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
AR := ar
ARFLAGS := rcsPv
LDFLAGS :=
ifeq ($(SHARED), 1)
CXXFLAGS += -fPIC
AR := $(CXX)
ARFLAGS := -shared -o
TARGET_LIB := $(TARGET_LIB).so
else
TARGET_LIB := $(TARGET_LIB).a
endif
ifeq ($(CUBIC_WRAP), 1)
CXXFLAGS += -DNBT_CUBIC_WRAP
endif
ifeq ($(NATIVE), 1)
CXXFLAGS += -pipe
CXXFLAGS += -march=native -mtune=native
endif
ifeq ($(DEBUG), 1)
CXXFLAGS += -Og -ggdb
else
CXXFLAGS += -O3 -DNDEBUG
endif
ifeq ($(LTO), 1)
CXXFLAGS += -flto
endif
ifeq ($(ASAN), 1)
CXXFLAGS += -fsanitize=address,leak,undefined
LDFLAGS += -fsanitize=address,leak,undefined
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
$(TARGET_LIB): $(BUILD_DIR)/$(TARGET_LIB)
cp $(BUILD_DIR)/$(TARGET_LIB) $(TARGET_LIB)
$(BUILD_DIR)/$(TARGET_LIB): CPPFLAGS += $(INC_FLAGS)
$(BUILD_DIR)/$(TARGET_LIB): $(OBJS)
$(AR) $(ARFLAGS) $@ $(OBJS)
$(TARGET_TESTS): $(BUILD_DIR_TESTS)/$(TARGET_TESTS)
cp $(BUILD_DIR_TESTS)/$(TARGET_TESTS) $(TARGET_TESTS)
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): CPPFLAGS += -DUNIT_TESTS=1 $(INC_FLAGS_TESTS) $(INC_FLAGS)
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): CXXFLAGS += --coverage
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): LDFLAGS += -lcriterion --coverage
$(BUILD_DIR_TESTS)/$(TARGET_TESTS): $(OBJS_TESTS) $(NEEDED_LIBS) $(TARGET_LIB)
$(CXX) $(OBJS_TESTS) -o $@ $(LDFLAGS) $(TARGET_LIB_FLAG)
$(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: clean
clean:
rm -rf $(BUILD_DIR)
rm -rf $(BUILD_DIR_TESTS)
.PHONY: fclean
fclean: clean
rm -f $(TARGET_LIB)
rm -f $(TARGET_TESTS)
.PHONY: re
re: fclean
$(MAKE) $(TARGET_LIB)
.PHONY: all
all: $(TARGET_LIB)
.PHONY: tests_run
tests_run: $(TARGET_TESTS)
./$(TARGET_TESTS)
-include $(DEPS)