forked from TeaInside/teavpn2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
228 lines (192 loc) · 4.88 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#
# @author Ammar Faizi <[email protected]> https://www.facebook.com/ammarfaizi2
# @license GNU GPL-v2
#
# TeaVPN2 - Fast and Free VPN Software
#
VERSION = 0
PATCHLEVEL = 0
SUBLEVEL = 1
EXTRAVERSION = -rc1
NAME = Fresh Water
SERVER_DEFAULT_CFG_FILE = config/server.ini
CLIENT_DEFAULT_CFG_FILE = config/client.ini
TARGET_BIN = teavpn2
CC := cc
CXX := c++
LD := $(CXX)
VG := valgrind
BASE_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
BASE_DIR := $(strip $(patsubst %/, %, $(BASE_DIR)))
BASE_DEP_DIR := $(BASE_DIR)/.deps
MAKEFILE_FILE := $(lastword $(MAKEFILE_LIST))
CC_BUILTIN_CONSTANTS := $(shell $(CC) -dM -E - < /dev/null)
CXX_BUILTIN_CONSTANTS := $(shell $(CXX) -dM -E - < /dev/null)
ifeq (,$(findstring __GNUC__,$(CXX_BUILTIN_CONSTANTS)))
$(error I want __GNUC__!)
endif
ifneq ($(DO_TEST),1)
ifneq (,$(findstring __GNUC__,$(CC_BUILTIN_CONSTANTS)))
ifneq (,$(findstring __clang__,$(CC_BUILTIN_CONSTANTS)))
# Clang
WARN_FLAGS := \
-Wall \
-Wextra \
-Weverything \
-Wno-disabled-macro-expansion
else
# Pure GCC
WARN_FLAGS := \
-Wall \
-Wextra \
-Wstrict-aliasing=3 \
-Wformat \
-Wformat-security \
-Wformat-signedness \
-Wsequence-point \
-Wunsafe-loop-optimizations \
-Wstack-usage=2097152
endif
else
$(error I want __GNUC__!)
endif
endif
USE_CLIENT := 1
USE_SERVER := 1
DEPFLAGS = -MT "$@" -MMD -MP -MF "$(@:$(BASE_DIR)/%.o=$(BASE_DEP_DIR)/%.d)"
LIB_LDFLAGS := -lpthread
LDFLAGS := -fPIE -fpie
CFLAGS := -fPIE -fpie # -std=c11
CXXFLAGS := -fPIE -fpie -std=c++2a
VGFLAGS := \
--leak-check=full \
--show-leak-kinds=all \
--track-origins=yes \
--track-fds=yes \
--error-exitcode=99 \
--exit-on-first-error=yes -s
ifndef DEFAULT_OPTIMIZATION
DEFAULT_OPTIMIZATION = -O0
endif
# CCXXFLAGS is a flag that applies to CFLAGS and CXXFLAGS
CCXXFLAGS := \
$(WARN_FLAGS) \
-fstrict-aliasing \
-fstack-protector-strong \
-pedantic-errors \
-D_GNU_SOURCE \
-DVERSION=$(VERSION) \
-DPATCHLEVEL=$(PATCHLEVEL) \
-DSUBLEVEL=$(SUBLEVEL) \
-DEXTRAVERSION=\"$(EXTRAVERSION)\" \
-DSERVER_DEFAULT_CFG_FILE=\"$(SERVER_DEFAULT_CFG_FILE)\" \
-DCLIENT_DEFAULT_CFG_FILE=\"$(CLIENT_DEFAULT_CFG_FILE)\"
ifeq ($(RELEASE_MODE),1)
REL := --- Build release mode
LDFLAGS += $(LDFLAGS) -O3
CCXXFLAGS += -O3 -DNDEBUG
ifndef NOTICE_MAX_LEVEL
NOTICE_MAX_LEVEL = 4
endif
ifndef NOTICE_ALWAYS_EXEC
NOTICE_ALWAYS_EXEC = 0
endif
ifndef DEFAULT_NOTICE_LEVEL
DEFAULT_NOTICE_LEVEL = 4
endif
else
REL := --- Build debug mode
LDFLAGS += $(DEFAULT_OPTIMIZATION)
CCXXFLAGS += \
$(DEFAULT_OPTIMIZATION) \
-ggdb3 \
-grecord-gcc-switches \
-DTEAVPN_DEBUG
ifndef NOTICE_MAX_LEVEL
NOTICE_MAX_LEVEL = 10
endif
ifndef NOTICE_ALWAYS_EXEC
NOTICE_ALWAYS_EXEC = 1
endif
ifndef DEFAULT_NOTICE_LEVEL
DEFAULT_NOTICE_LEVEL = 5
endif
endif
CCXXFLAGS := \
$(CCXXFLAGS) \
-DNOTICE_MAX_LEVEL="$(NOTICE_MAX_LEVEL)" \
-DNOTICE_ALWAYS_EXEC="$(NOTICE_ALWAYS_EXEC)" \
-DDEFAULT_NOTICE_LEVEL="$(DEFAULT_NOTICE_LEVEL)"
ifeq ($(SANITIZE),1)
REL += with sanitize
CCXXFLAGS := \
$(CCXXFLAGS) \
-fsanitize=undefined \
-fno-sanitize-recover=undefined
LIB_LDFLAGS += -lubsan
endif
ifeq ($(OS),Windows_NT)
CCXXFLAGS += -DWIN32
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
CCXXFLAGS += -DAMD64
else
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
CCXXFLAGS += -DAMD64
endif
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
CCXXFLAGS += -DIA32
endif
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
CCXXFLAGS += -DLINUX
endif
ifeq ($(UNAME_S),Darwin)
CCXXFLAGS += -DOSX
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
CCXXFLAGS += -DAMD64
endif
ifneq ($(filter %86,$(UNAME_P)),)
CCXXFLAGS += -DIA32
endif
ifneq ($(filter arm%,$(UNAME_P)),)
CCXXFLAGS += -DARM
endif
endif
#######################################
# Force these to be a simple variable
TESTS :=
OBJ_CC :=
OBJ_PRE_CC :=
OBJ_TMP_CC :=
CFLAGS_TMP :=
#######################################
all: $(TARGET_BIN)
@echo $(REL)
include $(BASE_DIR)/src/teavpn2/Makefile
include $(BASE_DIR)/src/ext/Makefile
CFLAGS := $(INCLUDE_DIR) $(CFLAGS) $(CCXXFLAGS)
CXXFLAGS := $(INCLUDE_DIR) $(CXXFLAGS) $(CCXXFLAGS)
include $(BASE_DIR)/tests/Makefile
$(TARGET_BIN): $(OBJ_CC) $(OBJ_PRE_CC)
@echo " LD " "$(@)"
@$(LD) $(LDFLAGS) $(OBJ_CC) $(OBJ_PRE_CC) -o "$@" $(LIB_LDFLAGS)
@chmod a+x teavpn2 || true
$(DEP_DIRS):
@echo " MKDIR " "$(@:$(BASE_DIR)/%=%)"
@mkdir -p $(@)
$(OBJ_CC): $(MAKEFILE_FILE) | $(DEP_DIRS)
@echo " CC " "$(@:$(BASE_DIR)/%=%)"
@$(CC) $(DEPFLAGS) $(CFLAGS) -c $(@:.o=.c) -o $(@)
$(OBJ_PRE_CC): $(MAKEFILE_FILE) | $(DEP_DIRS)
-include $(OBJ_CC:$(BASE_DIR)/%.o=$(BASE_DEP_DIR)/%.d)
-include $(OBJ_PRE_CC:$(BASE_DIR)/%.o=$(BASE_DEP_DIR)/%.d)
clean: clean_test
@rm -rfv $(DEP_DIRS) $(OBJ_CC) $(OBJ_PRE_CC) $(TARGET_BIN)
server: $(TARGET_BIN)
sudo $(VG) $(VGFLAGS) ./$(TARGET_BIN) server
client: $(TARGET_BIN)
sudo $(VG) $(VGFLAGS) ./$(TARGET_BIN) client