]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.sys.mk
Remove tests for obsolete compilers in the build system
[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 .if ${COMPILER_TYPE} == "gcc"
128 CWARNFLAGS+=    -Wno-error=address                      \
129                 -Wno-error=array-bounds                 \
130                 -Wno-error=attributes                   \
131                 -Wno-error=bool-compare                 \
132                 -Wno-error=cast-align                   \
133                 -Wno-error=clobbered                    \
134                 -Wno-error=deprecated-declarations      \
135                 -Wno-error=enum-compare                 \
136                 -Wno-error=extra                        \
137                 -Wno-error=inline                       \
138                 -Wno-error=logical-not-parentheses      \
139                 -Wno-error=nonnull-compare              \
140                 -Wno-error=shift-negative-value         \
141                 -Wno-error=strict-aliasing              \
142                 -Wno-error=tautological-compare         \
143                 -Wno-error=uninitialized                \
144                 -Wno-error=unused-but-set-variable      \
145                 -Wno-error=unused-const-variable        \
146                 -Wno-error=unused-function              \
147                 -Wno-error=unused-value
148
149 # GCC 7.1.0
150 .if ${COMPILER_VERSION} >= 70100
151 CWARNFLAGS+=    -Wno-error=bool-operation               \
152                 -Wno-error=deprecated                   \
153                 -Wno-error=expansion-to-defined         \
154                 -Wno-error=format-overflow              \
155                 -Wno-error=format-truncation            \
156                 -Wno-error=implicit-fallthrough         \
157                 -Wno-error=int-in-bool-context          \
158                 -Wno-error=memset-elt-size              \
159                 -Wno-error=noexcept-type                \
160                 -Wno-error=nonnull                      \
161                 -Wno-error=pointer-compare              \
162                 -Wno-error=stringop-overflow
163 .endif
164
165 # GCC 8.1.0
166 .if ${COMPILER_VERSION} >= 80100
167 CWARNFLAGS+=    -Wno-error=aggressive-loop-optimizations        \
168                 -Wno-error=cast-function-type                   \
169                 -Wno-error=catch-value                          \
170                 -Wno-error=multistatement-macros                \
171                 -Wno-error=restrict                             \
172                 -Wno-error=sizeof-pointer-memaccess             \
173                 -Wno-error=stringop-truncation
174 .endif
175 .endif  # gcc
176
177 # How to handle FreeBSD custom printf format specifiers.
178 .if ${COMPILER_TYPE} == "clang"
179 FORMAT_EXTENSIONS=      -D__printf__=__freebsd_kprintf__
180 .else
181 FORMAT_EXTENSIONS=      -fformat-extensions
182 .endif
183
184 .if defined(IGNORE_PRAGMA)
185 CWARNFLAGS+=    -Wno-unknown-pragmas
186 .endif # IGNORE_PRAGMA
187
188 # This warning is utter nonsense
189 CFLAGS+=        -Wno-format-zero-length
190
191 .if ${COMPILER_TYPE} == "clang"
192 # The headers provided by clang are incompatible with the FreeBSD headers.
193 # If the version of clang is not one that has been patched to omit the
194 # incompatible headers, we need to compile with -nobuiltininc and add the
195 # resource dir to the end of the search paths. This ensures that headers such as
196 # immintrin.h are still found but stddef.h, etc. are picked up from FreeBSD.
197 #
198 # XXX: This is a hack to support complete external installs of clang while
199 # we work to synchronize our decleration guards with those in the clang tree.
200 .if ${MK_CLANG_BOOTSTRAP:Uno} == "no" && \
201     ${COMPILER_RESOURCE_DIR} != "unknown" && !defined(BOOTSTRAPPING)
202 CFLAGS+=-nobuiltininc -idirafter ${COMPILER_RESOURCE_DIR}/include
203 .endif
204 .endif
205
206 CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
207                  -mllvm -simplifycfg-dup-ret
208 CLANG_OPT_SMALL+= -mllvm -enable-load-pre=false
209 CFLAGS.clang+=   -Qunused-arguments
210 # The libc++ headers use c++11 extensions.  These are normally silenced because
211 # they are treated as system headers, but we explicitly disable that warning
212 # suppression when building the base system to catch bugs in our headers.
213 # Eventually we'll want to start building the base system C++ code as C++11,
214 # but not yet.
215 CXXFLAGS.clang+=         -Wno-c++11-extensions
216
217 .if ${MK_SSP} != "no" && \
218     ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
219 # Don't use -Wstack-protector as it breaks world with -Werror.
220 SSP_CFLAGS?=    -fstack-protector-strong
221 CFLAGS+=        ${SSP_CFLAGS}
222 .endif # SSP && !ARM && !MIPS
223
224 # Additional flags passed in CFLAGS and CXXFLAGS when MK_DEBUG_FILES is
225 # enabled.
226 DEBUG_FILES_CFLAGS?= -g
227
228 # Allow user-specified additional warning flags, plus compiler and file
229 # specific flag overrides, unless we've overridden this...
230 .if ${MK_WARNS} != "no"
231 CFLAGS+=        ${CWARNFLAGS:M*} ${CWARNFLAGS.${COMPILER_TYPE}}
232 CFLAGS+=        ${CWARNFLAGS.${.IMPSRC:T}}
233 CXXFLAGS+=      ${CXXWARNFLAGS:M*} ${CXXWARNFLAGS.${COMPILER_TYPE}}
234 CXXFLAGS+=      ${CXXWARNFLAGS.${.IMPSRC:T}}
235 .endif
236
237 CFLAGS+=         ${CFLAGS.${COMPILER_TYPE}}
238 CXXFLAGS+=       ${CXXFLAGS.${COMPILER_TYPE}}
239
240 AFLAGS+=        ${AFLAGS.${.IMPSRC:T}}
241 AFLAGS+=        ${AFLAGS.${.TARGET:T}}
242 ACFLAGS+=       ${ACFLAGS.${.IMPSRC:T}}
243 ACFLAGS+=       ${ACFLAGS.${.TARGET:T}}
244 CFLAGS+=        ${CFLAGS.${.IMPSRC:T}}
245 CXXFLAGS+=      ${CXXFLAGS.${.IMPSRC:T}}
246
247 LDFLAGS+=       ${LDFLAGS.${LINKER_TYPE}}
248
249 # Only allow .TARGET when not using PROGS as it has the same syntax
250 # per PROG which is ambiguous with this syntax. This is only needed
251 # for PROG_VARS vars.
252 .if !defined(_RECURSING_PROGS)
253 .if ${MK_WARNS} != "no"
254 CFLAGS+=        ${CWARNFLAGS.${.TARGET:T}}
255 .endif
256 CFLAGS+=        ${CFLAGS.${.TARGET:T}}
257 CXXFLAGS+=      ${CXXFLAGS.${.TARGET:T}}
258 LDFLAGS+=       ${LDFLAGS.${.TARGET:T}}
259 LDADD+=         ${LDADD.${.TARGET:T}}
260 LIBADD+=        ${LIBADD.${.TARGET:T}}
261 .endif
262
263 .if defined(SRCTOP)
264 # Prevent rebuilding during install to support read-only objdirs.
265 .if ${.TARGETS:M*install*} == ${.TARGETS} && empty(.MAKE.MODE:Mmeta)
266 CFLAGS+=        ERROR-tried-to-rebuild-during-make-install
267 .endif
268 .endif
269
270 # Tell bmake not to mistake standard targets for things to be searched for
271 # or expect to ever be up-to-date.
272 PHONY_NOTMAIN = analyze afterdepend afterinstall all beforedepend beforeinstall \
273                 beforelinking build build-tools buildconfig buildfiles \
274                 buildincludes check checkdpadd clean cleandepend cleandir \
275                 cleanobj configure depend distclean distribute exe \
276                 files html includes install installconfig installdirs \
277                 installfiles installincludes lint obj objlink objs objwarn \
278                 realinstall tags whereobj
279
280 # we don't want ${PROG} to be PHONY
281 .PHONY: ${PHONY_NOTMAIN:N${PROG:U}}
282 .NOTMAIN: ${PHONY_NOTMAIN:Nall}
283
284 .if ${MK_STAGING} != "no"
285 .if defined(_SKIP_BUILD) || (!make(all) && !make(clean*) && !make(*clean))
286 _SKIP_STAGING?= yes
287 .endif
288 .if ${_SKIP_STAGING:Uno} == "yes"
289 staging stage_libs stage_files stage_as stage_links stage_symlinks:
290 .else
291 # allow targets like beforeinstall to be leveraged
292 DESTDIR= ${STAGE_OBJTOP}
293 .export DESTDIR
294
295 .if target(beforeinstall)
296 .if !empty(_LIBS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG))
297 staging: beforeinstall
298 .endif
299 .endif
300
301 # normally only libs and includes are staged
302 .if ${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG)
303 STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR}
304
305 .if !empty(PROG)
306 .if defined(PROGNAME)
307 STAGE_AS_SETS+= prog
308 STAGE_AS_${PROG}= ${PROGNAME}
309 stage_as.prog: ${PROG}
310 .else
311 STAGE_SETS+= prog
312 stage_files.prog: ${PROG}
313 STAGE_TARGETS+= stage_files
314 .endif
315 .endif
316 .endif
317
318 .if !empty(_LIBS) && !defined(INTERNALLIB)
319 .if defined(SHLIBDIR) && ${SHLIBDIR} != ${LIBDIR} && ${_LIBS:Uno:M*.so.*} != ""
320 STAGE_SETS+= shlib
321 STAGE_DIR.shlib= ${STAGE_OBJTOP}${SHLIBDIR}
322 STAGE_FILES.shlib+= ${_LIBS:M*.so.*}
323 stage_files.shlib: ${_LIBS:M*.so.*}
324 .endif
325
326 .if defined(SHLIB_LINK) && commands(${SHLIB_LINK:R}.ld)
327 STAGE_AS_SETS+= ldscript
328 STAGE_AS.ldscript+= ${SHLIB_LINK:R}.ld
329 stage_as.ldscript: ${SHLIB_LINK:R}.ld
330 STAGE_DIR.ldscript = ${STAGE_LIBDIR}
331 STAGE_AS_${SHLIB_LINK:R}.ld:= ${SHLIB_LINK}
332 NO_SHLIB_LINKS=
333 .endif
334
335 .if target(stage_files.shlib)
336 stage_libs: ${_LIBS}
337 .if defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
338 stage_files.shlib: ${SHLIB_NAME}.symbols
339 .endif
340 .else
341 stage_libs: ${_LIBS}
342 .endif
343 .if defined(SHLIB_NAME) && defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
344 stage_libs: ${SHLIB_NAME}.symbols
345 .endif
346
347 .endif
348
349 .if !empty(INCS) || !empty(INCSGROUPS) && target(buildincludes)
350 .if !defined(NO_BEFOREBUILD_INCLUDES)
351 stage_includes: buildincludes
352 beforebuild: stage_includes
353 .endif
354 .endif
355
356 .for t in stage_libs stage_files stage_as
357 .if target($t)
358 STAGE_TARGETS+= $t
359 .endif
360 .endfor
361
362 .if !empty(STAGE_AS_SETS)
363 STAGE_TARGETS+= stage_as
364 .endif
365
366 .if !empty(STAGE_TARGETS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG))
367
368 .if !empty(LINKS)
369 STAGE_TARGETS+= stage_links
370 .if ${MAKE_VERSION} < 20131001
371 stage_links.links: ${_LIBS} ${PROG}
372 .endif
373 STAGE_SETS+= links
374 STAGE_LINKS.links= ${LINKS}
375 .endif
376
377 .if !empty(SYMLINKS)
378 STAGE_TARGETS+= stage_symlinks
379 STAGE_SETS+= links
380 STAGE_SYMLINKS.links= ${SYMLINKS}
381 .endif
382
383 .endif
384
385 .include <meta.stage.mk>
386 .endif
387 .endif
388
389 .if defined(META_TARGETS)
390 .for _tgt in ${META_TARGETS}
391 .if target(${_tgt})
392 ${_tgt}: ${META_DEPS}
393 .endif
394 .endfor
395 .endif