-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfiguration
More file actions
260 lines (239 loc) · 7.76 KB
/
Configuration
File metadata and controls
260 lines (239 loc) · 7.76 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# Detecting compilers
ifeq ($(OS), Windows_NT)
DETECTED_GCC_PATH:=$(shell where gcc)
DETECTED_CLANG_PATH:=$(shell where clang)
else
DETECTED_GCC_PATH:=$(shell which gcc)
DETECTED_CLANG_PATH:=$(shell which clang)
endif
ifeq ($(COMPILER),)
ifneq ($(DETECTED_GCC_PATH),)
COMPILER:=GCC
INFO_MESSAGE=$(info Automatically using gcc compiler located at : $(DETECTED_GCC_PATH))
else ifneq ($(DETECTED_CLANG_PATH),)
COMPILER:=CLANG
INFO_MESSAGE=$(info Automatically using clang compiler located at : $(DETECTED_CLANG_PATH))
else
ERROR_MESSAGE=$(error No detected compilers, check your PATH)
endif
else ifeq ($(COMPILER), GCC)
ifneq ($(DETECTED_GCC_PATH),)
INFO_MESSAGE=$(info Choosing gcc compiler located at : $(DETECTED_GCC_PATH))
else
ERROR_MESSAGE=$(error Gcc compiler is missing, check your PATH)
endif
else ifeq ($(COMPILER), CLANG)
ifneq ($(DETECTED_CLANG_PATH),)
INFO_MESSAGE=$(info Choosing clang compiler located at : $(DETECTED_CLANG_PATH))
else
ERROR_MESSAGE=$(error Clang compiler is missing, check your PATH)
endif
else
ERROR_MESSAGE=$(error Unexpected COMPILER $(COMPILER), you can choose GCC or CLANG)
endif
# Execute error message if any
$(ERROR_MESSAGE)
$(INFO_MESSAGE)
# Detecting platform
ifeq ($(OS), Windows_NT)
DETECTED_OS:=WINDOWS
ifeq ($(COMPILER), GCC)
DETECTED_TARGET:=$(shell gcc -dumpmachine)
ifneq (, $(findstring x86_64-w64-mingw32, $(DETECTED_TARGET)))
DETECTED_TARGET:=MSYS
else ifneq (, $(findstring x86_64-pc-msys, $(DETECTED_TARGET)))
DETECTED_TARGET:=MSYS
else
ERROR_MESSAGE=$(error Unexpected DETECTED_TARGET $(DETECTED_TARGET))
endif
else ifeq ($(COMPILER), CLANG)
DETECTED_TARGET:=$(shell clang -dumpmachine)
ifneq (, $(findstring x86_64-pc-windows-msvc, $(DETECTED_TARGET)))
DETECTED_TARGET:=MSVC
else ifneq (, $(findstring x86_64-pc-msys, $(DETECTED_TARGET)))
DETECTED_TARGET:=MSYS
else
ERROR_MESSAGE=$(error Unexpected DETECTED_TARGET $(DETECTED_TARGET), consider to add and test it)
endif
endif
else
DETECTED_OS:=$(shell sh -c '(uname 2>/dev/null || echo UNKNOWN) | tr "[:lower:]" "[:upper:]"')
ifeq ($(COMPILER), GCC)
DETECTED_TARGET:=$(shell gcc -dumpmachine)
ifneq (, $(findstring x86_64-linux-gnu, $(DETECTED_TARGET)))
DETECTED_TARGET:=GNU
else ifneq (, $(findstring aarch64--linux-android, $(DETECTED_TARGET)))
DETECTED_TARGET:=ANDROID
else
ERROR_MESSAGE=$(error Unexpected DETECTED_TARGET $(DETECTED_TARGET))
endif
else ifeq ($(COMPILER), CLANG)
DETECTED_TARGET:=$(shell clang -dumpmachine)
ifneq (, $(findstring x86_64-pc-linux-gnu, $(DETECTED_TARGET)))
DETECTED_TARGET:=GNU
else ifneq (, $(findstring aarch64--linux-android, $(DETECTED_TARGET)))
DETECTED_TARGET:=ANDROID
else
ERROR_MESSAGE=$(error Unexpected DETECTED_TARGET $(DETECTED_TARGET), consider to add and test it)
endif
endif
endif
# Execute error message if any
$(ERROR_MESSAGE)
# Default build mode
ifeq ($(BUILD),)
BUILD:=RELEASE
endif
# Detecting LTO linkers
ifeq ($(OS), Windows_NT)
DETECTED_GOLD_PATH:=
DETECTED_LLD_PATH:=$(shell where lld-link)
else
DETECTED_GOLD_PATH:=$(shell which ld.gold)
DETECTED_LLD_PATH:=$(shell which ld.lld)
endif
ifeq ($(LINKER),)
ifeq ($(COMPILER), GCC)
ifneq ($(DETECTED_GOLD_PATH),)
LINKER=GOLD
INFO_MESSAGE=$(info Automatically using gold linker located at : $(DETECTED_GOLD_PATH))
else
LINKER=DEFAULT
INFO_MESSAGE=$(info Automatically using default linker)
endif
else ifeq ($(COMPILER), CLANG)
ifeq ($(DETECTED_TARGET), ANDROID)
ifneq ($(DETECTED_GOLD_PATH),)
LINKER=GOLD
INFO_MESSAGE=$(info Automatically using gold linker located at : $(DETECTED_GOLD_PATH))
else
LINKER=DEFAULT
INFO_MESSAGE=$(info Automatically using default linker)
endif
else ifeq ($(DETECTED_TARGET), GNU)
ifneq ($(DETECTED_LLD_PATH),)
LINKER=LLD
INFO_MESSAGE=$(info Automatically using lld linker located at : $(DETECTED_LLD_PATH))
else ifneq ($(DETECTED_GOLD_PATH),)
LINKER=GOLD
INFO_MESSAGE=$(info Automatically using gold linker located at : $(DETECTED_GOLD_PATH))
else
LINKER=DEFAULT
INFO_MESSAGE=$(info Automatically using default linker)
endif
else ifeq ($(DETECTED_TARGET), MSVC)
ifneq ($(DETECTED_LLD_PATH),)
LINKER=LLD
INFO_MESSAGE=$(info Automatically using lld linker located at : $(DETECTED_LLD_PATH))
else
LINKER=DEFAULT
INFO_MESSAGE=$(info Automatically using default linker)
endif
else
LINKER=DEFAULT
INFO_MESSAGE=$(info Automatically using default linker)
endif
endif
else ifeq ($(LINKER), GOLD)
ifneq ($(DETECTED_GOLD_PATH),)
LINKER=GOLD
INFO_MESSAGE=$(info Choosing gold linker located at : $(DETECTED_GOLD_PATH))
else
ERROR_MESSAGE=$(error Gold linker is missing)
endif
else ifeq ($(LINKER), LLD)
ifneq ($(DETECTED_LLD_PATH),)
LINKER=LLD
INFO_MESSAGE=$(info Choosing lld linker located at : $(DETECTED_LLD_PATH))
else
ERROR_MESSAGE=$(error Gold lld is missing)
endif
else
ERROR_MESSAGE=$(error Unexpected LINKER $(LINKER))
endif
ifeq ($(LINKER)-$(LTO), DEFAULT-ENABLE)
ERROR_MESSAGE=$(error No LTO linker is available)
LTO=DISABLE
endif
# Execute error message if any
$(ERROR_MESSAGE)
$(INFO_MESSAGE)
# Configure build
$(info $(DETECTED_OS)-$(DETECTED_TARGET)-$(COMPILER)-$(LINKER)-$(BUILD))
EXE_SUFFIX=
ifeq ($(BUILD), DEBUG)
BUILD_DIR_PATH=./.debug
else ifeq ($(BUILD), PROFILE)
BUILD_DIR_PATH=./.profile
else ifeq ($(BUILD), RELEASE)
BUILD_DIR_PATH=./.release
endif
BRANCH_NAME:=$(shell git symbolic-ref --short HEAD)
BUILD_DIR_PATH:=$(BUILD_DIR_PATH)_$(BRANCH_NAME)
ifeq ($(COMPILER), GCC)
BUILD_DIR_PATH:=$(BUILD_DIR_PATH)_gcc
EXE_SUFFIX:=$(EXE_SUFFIX)_gcc
else ifeq ($(COMPILER), CLANG)
BUILD_DIR_PATH:=$(BUILD_DIR_PATH)_clang
EXE_SUFFIX:=$(EXE_SUFFIX)_clang
endif
ifeq ($(LTO), ENABLE)
BUILD_DIR_PATH:=$(BUILD_DIR_PATH)_lto
EXE_SUFFIX:=$(EXE_SUFFIX)_lto
endif
ifeq ($(LINKER), GOLD)
BUILD_DIR_PATH:=$(BUILD_DIR_PATH)_gold
EXE_SUFFIX:=$(EXE_SUFFIX)_gold
else ifeq ($(LINKER), LLD)
BUILD_DIR_PATH:=$(BUILD_DIR_PATH)_lld
EXE_SUFFIX:=$(EXE_SUFFIX)_lld
endif
ifeq ($(BUILD), DEBUG)
EXE_SUFFIX:=$(EXE_SUFFIX)_d
else ifeq ($(BUILD), PROFILE)
EXE_SUFFIX:=$(EXE_SUFFIX)_p
else ifeq ($(BUILD), RELEASE)
EXE_SUFFIX:=$(EXE_SUFFIX)_r
endif
ifeq ($(COMPILER), GCC)
CC=gcc
CXX=gcc
CFLAGS=-std=c11 -D_XOPEN_SOURCE=600 -Wall -Wextra -Wpedantic -Wformat -Wcast-qual -Wconversion -Winit-self -Wunused -Werror
CXXFLAGS=-std=c++14 -D_XOPEN_SOURCE=600 -Wall -Wextra -Wpedantic -Wformat -Wcast-qual -Wconversion -Winit-self -Wunused -Werror
LDFLAGS=
else ifeq ($(COMPILER), CLANG)
CC=clang
CXX=clang
CFLAGS=-std=c11 -D_XOPEN_SOURCE=600 -Weverything -Werror -Wno-gnu-empty-initializer -Wno-zero-length-array -Wno-vla -Wno-missing-prototypes -Wno-comma -save-temps=obj
CXXFLAGS=-std=c++14 -D_XOPEN_SOURCE=600 -Weverything -Werror -Wno-gnu-empty-initializer -Wno-zero-length-array -Wno-vla -Wno-missing-prototypes -Wno-comma -save-temps=obj
LDFLAGS=
endif
ifeq ($(LINKER), GOLD)
LDFLAGS+=-fuse-ld=gold
else ifeq ($(LINKER), LLD)
LDFLAGS+=-fuse-ld=lld
endif
ifeq ($(BUILD), DEBUG)
CFLAGS+=-g -O0
CXXFLAGS+=-g -O0
LDFLAGS+=-g
else ifeq ($(BUILD), PROFILE)
CFLAGS+=-g -D NDEBUG -O2
CXXFLAGS+=-g -D NDEBUG -O2
else ifeq ($(BUILD), RELEASE)
CFLAGS+=-D NDEBUG -O2
CXXFLAGS+=-D NDEBUG -O2
endif
ifeq ($(LTO), ENABLE)
CFLAGS+=-flto
CXXFLAGS+=-flto
LDFLAGS+=-flto
ifeq ($(LINKER), GOLD)
LDFLAGS+=-Wl,-plugin-opt=save-temps
endif
endif
# Platform specific compiler options
ifeq ($(DETECTED_OS)-$(DETECTED_TARGET)-$(COMPILER), WINDOWS-MSVC-CLANG)
CFLAGS+=-D WA_LINKING_INLINE_FUNCTION -Wno-comma
CXXFLAGS+=-D WA_LINKING_INLINE_FUNCTION -Wno-comma
endif