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