]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.sys.mk
Remove -simplifycfg-dup-ret from CLANG_OPT_SMALL flags for clang 13
[FreeBSD/FreeBSD.git] / share / mk / bsd.sys.mk
1 # $FreeBSD$
2 #
3 # This file contains common settings used for building FreeBSD
4 # sources.
5
6 # Enable various levels of compiler warning checks.  These may be
7 # overridden (e.g. if using a non-gcc compiler) by defining MK_WARNS=no.
8
9 # for GCC:   https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
10 # for clang: https://clang.llvm.org/docs/DiagnosticsReference.html
11
12 .include <bsd.compiler.mk>
13
14 # the default is gnu99 for now
15 CSTD?=          gnu99
16
17 .if ${CSTD} == "c89" || ${CSTD} == "c90"
18 CFLAGS+=        -std=iso9899:1990
19 .elif ${CSTD} == "c94" || ${CSTD} == "c95"
20 CFLAGS+=        -std=iso9899:199409
21 .elif ${CSTD} == "c99"
22 CFLAGS+=        -std=iso9899:1999
23 .else # CSTD
24 CFLAGS+=        -std=${CSTD}
25 .endif # CSTD
26
27 .if !empty(CXXSTD)
28 CXXFLAGS+=      -std=${CXXSTD}
29 .endif
30
31 # -pedantic is problematic because it also imposes namespace restrictions
32 #CFLAGS+=       -pedantic
33 .if defined(WARNS)
34 .if ${WARNS} >= 1
35 CWARNFLAGS+=    -Wsystem-headers
36 .if !defined(NO_WERROR) && !defined(NO_WERROR.${COMPILER_TYPE})
37 CWARNFLAGS+=    -Werror
38 .endif # !NO_WERROR && !NO_WERROR.${COMPILER_TYPE}
39 .endif # WARNS >= 1
40 .if ${WARNS} >= 2
41 CWARNFLAGS+=    -Wall -Wno-format-y2k
42 .endif # WARNS >= 2
43 .if ${WARNS} >= 3
44 CWARNFLAGS+=    -W -Wno-unused-parameter -Wstrict-prototypes\
45                 -Wmissing-prototypes -Wpointer-arith
46 .endif # WARNS >= 3
47 .if ${WARNS} >= 4
48 CWARNFLAGS+=    -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
49                 -Wunused-parameter
50 .if !defined(NO_WCAST_ALIGN) && !defined(NO_WCAST_ALIGN.${COMPILER_TYPE})
51 CWARNFLAGS+=    -Wcast-align
52 .endif # !NO_WCAST_ALIGN !NO_WCAST_ALIGN.${COMPILER_TYPE}
53 .endif # WARNS >= 4
54 .if ${WARNS} >= 6
55 CWARNFLAGS+=    -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
56                 -Wold-style-definition
57 .if !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
58 CWARNFLAGS.clang+=      -Wmissing-variable-declarations
59 .endif
60 .if !defined(NO_WTHREAD_SAFETY)
61 CWARNFLAGS.clang+=      -Wthread-safety
62 .endif
63 .endif # WARNS >= 6
64 .if ${WARNS} >= 2 && ${WARNS} <= 4
65 # XXX Delete -Wuninitialized by default for now -- the compiler doesn't
66 # XXX always get it right.
67 CWARNFLAGS+=    -Wno-uninitialized
68 .endif # WARNS >=2 && WARNS <= 4
69 CWARNFLAGS+=    -Wno-pointer-sign
70 # Clang has more warnings enabled by default, and when using -Wall, so if WARNS
71 # is set to low values, these have to be disabled explicitly.
72 .if ${WARNS} <= 6
73 CWARNFLAGS.clang+=      -Wno-empty-body -Wno-string-plus-int
74 CWARNFLAGS.clang+=      -Wno-unused-const-variable
75 .endif # WARNS <= 6
76 .if ${WARNS} <= 3
77 CWARNFLAGS.clang+=      -Wno-tautological-compare -Wno-unused-value\
78                 -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
79 CWARNFLAGS.clang+=      -Wno-unused-local-typedef
80 CWARNFLAGS.clang+=      -Wno-address-of-packed-member
81 .if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 90100
82 CWARNFLAGS.gcc+=        -Wno-address-of-packed-member
83 .endif
84 .if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 70000 && \
85     ${MACHINE_CPUARCH} == "arm" && !${MACHINE_ARCH:Marmv[67]*}
86 CWARNFLAGS.clang+=      -Wno-atomic-alignment
87 .endif
88 .endif # WARNS <= 3
89 .if ${WARNS} <= 2
90 CWARNFLAGS.clang+=      -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
91 .endif # WARNS <= 2
92 .if ${WARNS} <= 1
93 CWARNFLAGS.clang+=      -Wno-parentheses
94 .endif # WARNS <= 1
95 .if defined(NO_WARRAY_BOUNDS)
96 CWARNFLAGS.clang+=      -Wno-array-bounds
97 .endif # NO_WARRAY_BOUNDS
98 .if defined(NO_WMISLEADING_INDENTATION) && \
99     ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 100000) || \
100       ${COMPILER_TYPE} == "gcc")
101 CWARNFLAGS+=            -Wno-misleading-indentation
102 .endif # NO_WMISLEADING_INDENTATION
103 .endif # WARNS
104
105 .if defined(FORMAT_AUDIT)
106 WFORMAT=        1
107 .endif # FORMAT_AUDIT
108 .if defined(WFORMAT)
109 .if ${WFORMAT} > 0
110 #CWARNFLAGS+=   -Wformat-nonliteral -Wformat-security -Wno-format-extra-args
111 CWARNFLAGS+=    -Wformat=2 -Wno-format-extra-args
112 .if ${WARNS} <= 3
113 CWARNFLAGS.clang+=      -Wno-format-nonliteral
114 .endif # WARNS <= 3
115 .if !defined(NO_WERROR) && !defined(NO_WERROR.${COMPILER_TYPE})
116 CWARNFLAGS+=    -Werror
117 .endif # !NO_WERROR && !NO_WERROR.${COMPILER_TYPE}
118 .endif # WFORMAT > 0
119 .endif # WFORMAT
120 .if defined(NO_WFORMAT) || defined(NO_WFORMAT.${COMPILER_TYPE})
121 CWARNFLAGS+=    -Wno-format
122 .endif # NO_WFORMAT || NO_WFORMAT.${COMPILER_TYPE}
123
124 # GCC
125 # We should clean up warnings produced with these flags.
126 # They were originally added as a quick hack to enable gcc5/6.
127 # The base system requires at least GCC 6.4, but some ports
128 # use this file with older compilers.  Request an exprun
129 # before changing these.
130 .if ${COMPILER_TYPE} == "gcc"
131 # GCC 5.2.0
132 .if ${COMPILER_VERSION} >= 50200
133 CWARNFLAGS+=    -Wno-error=address                      \
134                 -Wno-error=array-bounds                 \
135                 -Wno-error=attributes                   \
136                 -Wno-error=bool-compare                 \
137                 -Wno-error=cast-align                   \
138                 -Wno-error=clobbered                    \
139                 -Wno-error=deprecated-declarations      \
140                 -Wno-error=enum-compare                 \
141                 -Wno-error=extra                        \
142                 -Wno-error=inline                       \
143                 -Wno-error=logical-not-parentheses      \
144                 -Wno-error=strict-aliasing              \
145                 -Wno-error=uninitialized                \
146                 -Wno-error=unused-but-set-variable      \
147                 -Wno-error=unused-function              \
148                 -Wno-error=unused-value
149 .endif
150
151 # GCC 6.1.0
152 .if ${COMPILER_VERSION} >= 60100
153 CWARNFLAGS+=    -Wno-error=empty-body                   \
154                 -Wno-error=maybe-uninitialized          \
155                 -Wno-error=nonnull-compare              \
156                 -Wno-error=redundant-decls              \
157                 -Wno-error=shift-negative-value         \
158                 -Wno-error=tautological-compare         \
159                 -Wno-error=unused-const-variable
160 .endif
161
162 # GCC 6.1.0
163 .if ${COMPILER_VERSION} >= 60100
164 CWARNFLAGS+=    -Wno-error=empty-body                   \
165                 -Wno-error=nonnull-compare              \
166                 -Wno-error=shift-negative-value         \
167                 -Wno-error=tautological-compare         \
168                 -Wno-error=unused-const-variable
169 .endif
170
171 # GCC 7.1.0
172 .if ${COMPILER_VERSION} >= 70100
173 CWARNFLAGS+=    -Wno-error=bool-operation               \
174                 -Wno-error=deprecated                   \
175                 -Wno-error=expansion-to-defined         \
176                 -Wno-error=format-overflow              \
177                 -Wno-error=format-truncation            \
178                 -Wno-error=implicit-fallthrough         \
179                 -Wno-error=int-in-bool-context          \
180                 -Wno-error=memset-elt-size              \
181                 -Wno-error=noexcept-type                \
182                 -Wno-error=nonnull                      \
183                 -Wno-error=pointer-compare              \
184                 -Wno-error=stringop-overflow
185 .endif
186
187 # GCC 8.1.0
188 .if ${COMPILER_VERSION} >= 80100
189 CWARNFLAGS+=    -Wno-error=aggressive-loop-optimizations        \
190                 -Wno-error=cast-function-type                   \
191                 -Wno-error=catch-value                          \
192                 -Wno-error=multistatement-macros                \
193                 -Wno-error=restrict                             \
194                 -Wno-error=sizeof-pointer-memaccess             \
195                 -Wno-error=stringop-truncation
196 .endif
197 .endif  # gcc
198
199 # How to handle FreeBSD custom printf format specifiers.
200 .if ${COMPILER_TYPE} == "clang"
201 FORMAT_EXTENSIONS=      -D__printf__=__freebsd_kprintf__
202 .else
203 FORMAT_EXTENSIONS=      -fformat-extensions
204 .endif
205
206 .if defined(IGNORE_PRAGMA)
207 CWARNFLAGS+=    -Wno-unknown-pragmas
208 .endif # IGNORE_PRAGMA
209
210 # This warning is utter nonsense
211 CFLAGS+=        -Wno-format-zero-length
212
213 CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3
214 .if ${COMPILER_VERSION} < 130000
215 CLANG_OPT_SMALL+= -mllvm -simplifycfg-dup-ret
216 .endif
217 CLANG_OPT_SMALL+= -mllvm -enable-load-pre=false
218 CFLAGS.clang+=   -Qunused-arguments
219 .if ${MACHINE_CPUARCH} == "sparc64"
220 # Don't emit .cfi directives, since we must use GNU as on sparc64, for now.
221 CFLAGS.clang+=   -fno-dwarf2-cfi-asm
222 .endif # SPARC64
223 # The libc++ headers use c++11 extensions.  These are normally silenced because
224 # they are treated as system headers, but we explicitly disable that warning
225 # suppression when building the base system to catch bugs in our headers.
226 # Eventually we'll want to start building the base system C++ code as C++11,
227 # but not yet.
228 CXXFLAGS.clang+=         -Wno-c++11-extensions
229
230 .if ${MK_SSP} != "no" && \
231     ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
232 # Don't use -Wstack-protector as it breaks world with -Werror.
233 SSP_CFLAGS?=    -fstack-protector-strong
234 CFLAGS+=        ${SSP_CFLAGS}
235 .endif # SSP && !ARM && !MIPS
236
237 # Additional flags passed in CFLAGS and CXXFLAGS when MK_DEBUG_FILES is
238 # enabled.
239 DEBUG_FILES_CFLAGS?= -g
240
241 # Allow user-specified additional warning flags, plus compiler and file
242 # specific flag overrides, unless we've overridden this...
243 .if ${MK_WARNS} != "no"
244 CFLAGS+=        ${CWARNFLAGS:M*} ${CWARNFLAGS.${COMPILER_TYPE}}
245 CFLAGS+=        ${CWARNFLAGS.${.IMPSRC:T}}
246 CXXFLAGS+=      ${CXXWARNFLAGS:M*} ${CXXWARNFLAGS.${COMPILER_TYPE}}
247 CXXFLAGS+=      ${CXXWARNFLAGS.${.IMPSRC:T}}
248 .endif
249
250 CFLAGS+=         ${CFLAGS.${COMPILER_TYPE}}
251 CXXFLAGS+=       ${CXXFLAGS.${COMPILER_TYPE}}
252
253 AFLAGS+=        ${AFLAGS.${.IMPSRC:T}}
254 ACFLAGS+=       ${ACFLAGS.${.IMPSRC:T}}
255 CFLAGS+=        ${CFLAGS.${.IMPSRC:T}}
256 CXXFLAGS+=      ${CXXFLAGS.${.IMPSRC:T}}
257
258 LDFLAGS+=       ${LDFLAGS.${LINKER_TYPE}}
259
260 .if defined(SRCTOP)
261 # Prevent rebuilding during install to support read-only objdirs.
262 .if ${.TARGETS:M*install*} == ${.TARGETS} && empty(.MAKE.MODE:Mmeta)
263 CFLAGS+=        ERROR-tried-to-rebuild-during-make-install
264 .endif
265 .endif
266
267 # Tell bmake not to mistake standard targets for things to be searched for
268 # or expect to ever be up-to-date.
269 PHONY_NOTMAIN = analyze afterdepend afterinstall all beforedepend beforeinstall \
270                 beforelinking build build-tools buildconfig buildfiles \
271                 buildincludes check checkdpadd clean cleandepend cleandir \
272                 cleanobj configure depend distclean distribute exe \
273                 files html includes install installconfig installdirs \
274                 installfiles installincludes lint obj objlink objs objwarn \
275                 realinstall tags whereobj
276
277 # we don't want ${PROG} to be PHONY
278 .PHONY: ${PHONY_NOTMAIN:N${PROG:U}}
279 .NOTMAIN: ${PHONY_NOTMAIN:Nall}
280
281 .if ${MK_STAGING} != "no"
282 .if defined(_SKIP_BUILD) || (!make(all) && !make(clean*) && !make(*clean))
283 _SKIP_STAGING?= yes
284 .endif
285 .if ${_SKIP_STAGING:Uno} == "yes"
286 staging stage_libs stage_files stage_as stage_links stage_symlinks:
287 .else
288 # allow targets like beforeinstall to be leveraged
289 DESTDIR= ${STAGE_OBJTOP}
290 .export DESTDIR
291
292 .if target(beforeinstall)
293 .if !empty(_LIBS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG))
294 staging: beforeinstall
295 .endif
296 .endif
297
298 # normally only libs and includes are staged
299 .if ${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG)
300 STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR}
301
302 .if !empty(PROG)
303 .if defined(PROGNAME)
304 STAGE_AS_SETS+= prog
305 STAGE_AS_${PROG}= ${PROGNAME}
306 stage_as.prog: ${PROG}
307 .else
308 STAGE_SETS+= prog
309 stage_files.prog: ${PROG}
310 STAGE_TARGETS+= stage_files
311 .endif
312 .endif
313 .endif
314
315 .if !empty(_LIBS) && !defined(INTERNALLIB)
316 .if defined(SHLIBDIR) && ${SHLIBDIR} != ${LIBDIR} && ${_LIBS:Uno:M*.so.*} != ""
317 STAGE_SETS+= shlib
318 STAGE_DIR.shlib= ${STAGE_OBJTOP}${SHLIBDIR}
319 STAGE_FILES.shlib+= ${_LIBS:M*.so.*}
320 stage_files.shlib: ${_LIBS:M*.so.*}
321 .endif
322
323 .if defined(SHLIB_LINK) && commands(${SHLIB_LINK:R}.ld)
324 STAGE_AS_SETS+= ldscript
325 STAGE_AS.ldscript+= ${SHLIB_LINK:R}.ld
326 stage_as.ldscript: ${SHLIB_LINK:R}.ld
327 STAGE_DIR.ldscript = ${STAGE_LIBDIR}
328 STAGE_AS_${SHLIB_LINK:R}.ld:= ${SHLIB_LINK}
329 NO_SHLIB_LINKS=
330 .endif
331
332 .if target(stage_files.shlib)
333 stage_libs: ${_LIBS}
334 .if defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
335 stage_files.shlib: ${SHLIB_NAME}.symbols
336 .endif
337 .else
338 stage_libs: ${_LIBS}
339 .endif
340 .if defined(SHLIB_NAME) && defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
341 stage_libs: ${SHLIB_NAME}.symbols
342 .endif
343
344 .endif
345
346 .if !empty(INCS) || !empty(INCSGROUPS) && target(buildincludes)
347 .if !defined(NO_BEFOREBUILD_INCLUDES)
348 stage_includes: buildincludes
349 beforebuild: stage_includes
350 .endif
351 .endif
352
353 .for t in stage_libs stage_files stage_as
354 .if target($t)
355 STAGE_TARGETS+= $t
356 .endif
357 .endfor
358
359 .if !empty(STAGE_AS_SETS)
360 STAGE_TARGETS+= stage_as
361 .endif
362
363 .if !empty(STAGE_TARGETS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG))
364
365 .if !empty(LINKS)
366 STAGE_TARGETS+= stage_links
367 .if ${MAKE_VERSION} < 20131001
368 stage_links.links: ${_LIBS} ${PROG}
369 .endif
370 STAGE_SETS+= links
371 STAGE_LINKS.links= ${LINKS}
372 .endif
373
374 .if !empty(SYMLINKS)
375 STAGE_TARGETS+= stage_symlinks
376 STAGE_SETS+= links
377 STAGE_SYMLINKS.links= ${SYMLINKS}
378 .endif
379
380 .endif
381
382 .include <meta.stage.mk>
383 .endif
384 .endif
385
386 .if defined(META_TARGETS)
387 .for _tgt in ${META_TARGETS}
388 .if target(${_tgt})
389 ${_tgt}: ${META_DEPS}
390 .endif
391 .endfor
392 .endif