-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflags.mk
229 lines (196 loc) · 5.92 KB
/
flags.mk
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
# Define flags to pass to the various compilation tools for the current build configuration and
# host system environment.
#
# The following flags are defined:
#
# CFLAGS = Compiler flags for C and Objective-C files.
# CXXFLAGS = Compiler flags for C++ and Objective-C++ files.
# LDFLAGS = Linker flags for C-family targets.
# LDLIBS = Linker libraries required by the STL for C-family targets.
#
# JFLAGS = Compiler flags for Java files.
#
# STRIP_FLAGS = Flags to be used when stripping symbols from a target.
# JAR_CREATE_FLAGS = Flags to be used when creating a JAR archive
# TAR_EXTRACT_FLAGS = Flags to be used when extracting a tar archive.
# TAR_CREATE_FLAGS = Flags to be used when creating a tar archive
# ZIP_EXTRACT_FLAGS = Flags to be used when extracting a zip archive.
#
# The application may define the following variables in any files.mk to define compiler/linker flags
# on a per-directory level. These variables are defaulted to the values of the parent directory, so
# generally these variables should be treated as append-only (+=). But this behavior may be avoided
# by assigning values instead (:=).
#
# CFLAGS_$(d)
# CXXFLAGS_$(d)
# LDFLAGS_$(d)
# LDLIBS_$(d)
# JFLAGS_$(d)
#
# The resulting flags used when compiling a directory are the global flags defined in this file
# followed by any _$(d) variants defined in the directory's files.mk.
# Remove built-in rules.
MAKEFLAGS += --no-builtin-rules --no-print-directory
.SUFFIXES:
# Use bash instead of sh.
SHELL := /bin/bash
# Linker flags.
LDFLAGS ?=
LDLIBS ?=
# Standard linker flags.
LDFLAGS += -L$(INSTALL_LIB_DIR) -fuse-ld=$(linker)
LDLIBS += -lpthread
ifeq ($(SYSTEM), LINUX)
LDLIBS += -latomic
endif
# Compiler flags for all C-family files.
CF_ALL := -MD -MP -fPIC
CF_ALL += -I$(SOURCE_ROOT) -I$(GEN_DIR) -I$(INSTALL_INC_DIR)
ifeq ($(SYSTEM), MACOS)
CF_ALL += -isysroot $(XCODE)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
endif
ifeq ($(arch), x86)
CF_ALL += -m32
endif
ifeq ($(toolchain), gcc)
CF_ALL += -Wno-psabi
endif
# C and C++ specific flags.
CFLAGS ?=
CXXFLAGS ?=
# Compiler flags for Java files.
JFLAGS ?=
# Language standard flags.
CFLAGS += -std=$(cstandard)
CXXFLAGS += -std=$(cxxstandard)
# Error and warning flags.
ifneq ($(strict), 0)
CF_ALL += \
-Wall \
-Wextra \
-Werror
ifneq ($(strict), 1)
CF_ALL += \
-pedantic \
-Wcast-align \
-Wcast-qual \
-Wdisabled-optimization \
-Wfloat-equal \
-Winvalid-pch \
-Wmissing-declarations \
-Wpointer-arith \
-Wredundant-decls \
-Wshadow \
-Wstrict-overflow=2 \
-Wundef \
-Wunreachable-code \
-Wunused \
CXXFLAGS += \
-Wctor-dtor-privacy \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Woverloaded-virtual \
# Disabled due to LLVM bug: https://bugs.llvm.org/show_bug.cgi?id=44325
# -Wzero-as-null-pointer-constant \
ifeq ($(mode), debug)
CF_ALL += -Winline
endif
ifeq ($(toolchain), clang)
CF_ALL += \
-Wnewline-eof \
-Wsign-conversion
# C++20 introduces __VA_OPT__ to handle variadic macros invoked with zero variadic
# arguments. However, Apple's clang has not updated -pedantic to allow such invocations.
# See: https://stackoverflow.com/a/67996331
ifeq ($(SYSTEM), MACOS)
ifeq ($(cxxstandard), $(filter c++20 c++2a, $(cxxstandard)))
CF_ALL += \
-Wno-gnu-zero-variadic-macro-arguments
endif
endif
else ifeq ($(toolchain), gcc)
CF_ALL += \
-Wlogical-op \
-Wnull-dereference \
-Wredundant-decls
CXXFLAGS += -Wsuggest-override
ifeq ($(mode), debug)
CXXFLAGS += \
-Wsuggest-final-methods \
-Wsuggest-final-types
endif
endif
endif
endif
JFLAGS += \
-Werror \
-Xlint
# Add debug symbols, optimize release builds, or add profiling symbols.
ifeq ($(mode), debug)
CF_ALL += -O0 -g$(symbols)
JFLAGS += -g:lines,vars,source
else ifeq ($(mode), release)
CF_ALL += -O2 -DNDEBUG
JFLAGS += -g:none
else ifeq ($(mode), profile)
ifeq ($(toolchain), gcc)
CF_ALL += -O2 -DNDEBUG -g$(symbols) -pg -DFLY_PROFILE
LDFLAGS += -pg
else
$(error Profiling not supported with toolchain $(toolchain), check flags.mk)
endif
endif
# Enable sanitizers.
ifneq ($(sanitize),)
CF_ALL += -fsanitize=$(sanitize) -fno-omit-frame-pointer -fno-sanitize-recover=all
endif
# Enable code coverage instrumentation.
ifeq ($(coverage), 1)
ifeq ($(toolchain), clang)
CF_ALL += -fprofile-instr-generate -fcoverage-mapping
else ifeq ($(toolchain), gcc)
CF_ALL += --coverage
endif
endif
CFLAGS += $(CF_ALL)
CXXFLAGS += $(CF_ALL)
# Enable verbose Java output.
ifeq ($(verbose), 1)
JFLAGS += -verbose
endif
# On macOS: Link commonly used frameworks.
ifeq ($(SYSTEM), MACOS)
LDFLAGS += \
-framework CoreFoundation \
-framework CoreServices \
-framework Foundation
endif
# strip flags.
ifeq ($(SYSTEM), LINUX)
STRIP_FLAGS := -s
else ifeq ($(SYSTEM), MACOS)
STRIP_FLAGS := -rSx
else
$(error Unrecognized system $(SYSTEM), check flags.mk)
endif
# jar flags.
ifeq ($(verbose), 1)
JAR_CREATE_FLAGS := cvef
else
JAR_CREATE_FLAGS := cef
endif
# tar flags.
ifeq ($(verbose), 1)
TAR_EXTRACT_FLAGS := -xjvf
TAR_CREATE_FLAGS := -cjvf
else
TAR_EXTRACT_FLAGS := -xjf
TAR_CREATE_FLAGS := -cjf
endif
ifeq ($(SYSTEM), MACOS)
TAR_EXTRACT_FLAGS := -mo $(TAR_EXTRACT_FLAGS)
endif
# zip flags.
ifeq ($(verbose), 0)
ZIP_EXTRACT_FLAGS := -q
endif