bsd.sys.mk revision 360658
1# $FreeBSD: stable/11/share/mk/bsd.sys.mk 360658 2020-05-05 12:59:04Z dim $ 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.if defined(NO_WMISLEADING_INDENTATION) && \ 108 ((${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 100000) || \ 109 (${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60100)) 110CWARNFLAGS+= -Wno-misleading-indentation 111.endif # NO_WMISLEADING_INDENTATION 112.endif # WARNS 113 114.if defined(FORMAT_AUDIT) 115WFORMAT= 1 116.endif # FORMAT_AUDIT 117.if defined(WFORMAT) 118.if ${WFORMAT} > 0 119#CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args 120CWARNFLAGS+= -Wformat=2 -Wno-format-extra-args 121.if ${WARNS} <= 3 122CWARNFLAGS.clang+= -Wno-format-nonliteral 123.endif # WARNS <= 3 124.if !defined(NO_WERROR) && !defined(NO_WERROR.${COMPILER_TYPE}) 125CWARNFLAGS+= -Werror 126.endif # !NO_WERROR && !NO_WERROR.${COMPILER_TYPE} 127.endif # WFORMAT > 0 128.endif # WFORMAT 129.if defined(NO_WFORMAT) || defined(NO_WFORMAT.${COMPILER_TYPE}) 130CWARNFLAGS+= -Wno-format 131.endif # NO_WFORMAT || NO_WFORMAT.${COMPILER_TYPE} 132 133# GCC 5.2.0 134.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 50200 135CWARNFLAGS+= -Wno-error=address \ 136 -Wno-error=array-bounds \ 137 -Wno-error=attributes \ 138 -Wno-error=bool-compare \ 139 -Wno-error=cast-align \ 140 -Wno-error=clobbered \ 141 -Wno-error=deprecated-declarations \ 142 -Wno-error=enum-compare \ 143 -Wno-error=extra \ 144 -Wno-error=inline \ 145 -Wno-error=logical-not-parentheses \ 146 -Wno-error=strict-aliasing \ 147 -Wno-error=uninitialized \ 148 -Wno-error=unused-but-set-variable \ 149 -Wno-error=unused-function \ 150 -Wno-error=unused-value 151.endif 152 153# GCC 6.1.0 154.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 60100 155CWARNFLAGS+= -Wno-error=nonnull-compare \ 156 -Wno-error=shift-negative-value \ 157 -Wno-error=tautological-compare \ 158 -Wno-error=unused-const-variable 159.endif 160 161# How to handle FreeBSD custom printf format specifiers. 162.if ${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30600 163FORMAT_EXTENSIONS= -D__printf__=__freebsd_kprintf__ 164.else 165FORMAT_EXTENSIONS= -fformat-extensions 166.endif 167 168.if defined(IGNORE_PRAGMA) 169CWARNFLAGS+= -Wno-unknown-pragmas 170.endif # IGNORE_PRAGMA 171 172# We need this conditional because many places that use it 173# only enable it for some files with CLFAGS.$FILE+=${CLANG_NO_IAS}. 174# unconditionally, and can't easily use the CFLAGS.clang= 175# mechanism. 176.if ${COMPILER_TYPE} == "clang" 177CLANG_NO_IAS= -no-integrated-as 178.endif 179CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\ 180 -mllvm -simplifycfg-dup-ret 181.if ${COMPILER_VERSION} >= 30500 && ${COMPILER_VERSION} < 30700 182CLANG_OPT_SMALL+= -mllvm -enable-gvn=false 183.else 184CLANG_OPT_SMALL+= -mllvm -enable-load-pre=false 185.endif 186CFLAGS.clang+= -Qunused-arguments 187.if ${MACHINE_CPUARCH} == "sparc64" 188# Don't emit .cfi directives, since we must use GNU as on sparc64, for now. 189CFLAGS.clang+= -fno-dwarf2-cfi-asm 190.endif # SPARC64 191# The libc++ headers use c++11 extensions. These are normally silenced because 192# they are treated as system headers, but we explicitly disable that warning 193# suppression when building the base system to catch bugs in our headers. 194# Eventually we'll want to start building the base system C++ code as C++11, 195# but not yet. 196CXXFLAGS.clang+= -Wno-c++11-extensions 197 198.if ${MK_SSP} != "no" && \ 199 ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 200.if (${COMPILER_TYPE} == "clang" && ${COMPILER_VERSION} >= 30500) || \ 201 (${COMPILER_TYPE} == "gcc" && \ 202 (${COMPILER_VERSION} == 40201 || ${COMPILER_VERSION} >= 40900)) 203# Don't use -Wstack-protector as it breaks world with -Werror. 204SSP_CFLAGS?= -fstack-protector-strong 205.else 206SSP_CFLAGS?= -fstack-protector 207.endif 208CFLAGS+= ${SSP_CFLAGS} 209.endif # SSP && !ARM && !MIPS 210 211# Allow user-specified additional warning flags, plus compiler and file 212# specific flag overrides, unless we've overriden this... 213.if ${MK_WARNS} != "no" 214CFLAGS+= ${CWARNFLAGS:M*} ${CWARNFLAGS.${COMPILER_TYPE}} 215CFLAGS+= ${CWARNFLAGS.${.IMPSRC:T}} 216CXXFLAGS+= ${CXXWARNFLAGS:M*} ${CXXWARNFLAGS.${COMPILER_TYPE}} 217CXXFLAGS+= ${CXXWARNFLAGS.${.IMPSRC:T}} 218.endif 219 220CFLAGS+= ${CFLAGS.${COMPILER_TYPE}} 221CXXFLAGS+= ${CXXFLAGS.${COMPILER_TYPE}} 222 223AFLAGS+= ${AFLAGS.${.IMPSRC:T}} 224ACFLAGS+= ${ACFLAGS.${.IMPSRC:T}} 225CFLAGS+= ${CFLAGS.${.IMPSRC:T}} 226CXXFLAGS+= ${CXXFLAGS.${.IMPSRC:T}} 227 228.if defined(SRCTOP) 229# Prevent rebuilding during install to support read-only objdirs. 230.if ${.TARGETS:M*install*} == ${.TARGETS} && empty(.MAKE.MODE:Mmeta) 231CFLAGS+= ERROR-tried-to-rebuild-during-make-install 232.endif 233.endif 234 235# Tell bmake not to mistake standard targets for things to be searched for 236# or expect to ever be up-to-date. 237PHONY_NOTMAIN = analyze afterdepend afterinstall all beforedepend beforeinstall \ 238 beforelinking build build-tools buildconfig buildfiles \ 239 buildincludes check checkdpadd clean cleandepend cleandir \ 240 cleanobj configure depend distclean distribute exe \ 241 files html includes install installconfig installfiles \ 242 installincludes lint obj objlink objs objwarn \ 243 realinstall tags whereobj 244 245# we don't want ${PROG} to be PHONY 246.PHONY: ${PHONY_NOTMAIN:N${PROG:U}} 247.NOTMAIN: ${PHONY_NOTMAIN:Nall} 248 249.if ${MK_STAGING} != "no" 250.if defined(_SKIP_BUILD) || (!make(all) && !make(clean*) && !make(*clean)) 251_SKIP_STAGING?= yes 252.endif 253.if ${_SKIP_STAGING:Uno} == "yes" 254staging stage_libs stage_files stage_as stage_links stage_symlinks: 255.else 256# allow targets like beforeinstall to be leveraged 257DESTDIR= ${STAGE_OBJTOP} 258.export DESTDIR 259 260.if target(beforeinstall) 261.if !empty(_LIBS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG)) 262staging: beforeinstall 263.endif 264.endif 265 266# normally only libs and includes are staged 267.if ${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG) 268STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR} 269 270.if !empty(PROG) 271.if defined(PROGNAME) 272STAGE_AS_SETS+= prog 273STAGE_AS_${PROG}= ${PROGNAME} 274stage_as.prog: ${PROG} 275.else 276STAGE_SETS+= prog 277stage_files.prog: ${PROG} 278STAGE_TARGETS+= stage_files 279.endif 280.endif 281.endif 282 283.if !empty(_LIBS) && !defined(INTERNALLIB) 284.if defined(SHLIBDIR) && ${SHLIBDIR} != ${LIBDIR} && ${_LIBS:Uno:M*.so.*} != "" 285STAGE_SETS+= shlib 286STAGE_DIR.shlib= ${STAGE_OBJTOP}${SHLIBDIR} 287STAGE_FILES.shlib+= ${_LIBS:M*.so.*} 288stage_files.shlib: ${_LIBS:M*.so.*} 289.endif 290 291.if defined(SHLIB_LINK) && commands(${SHLIB_LINK:R}.ld) 292STAGE_AS_SETS+= ldscript 293STAGE_AS.ldscript+= ${SHLIB_LINK:R}.ld 294stage_as.ldscript: ${SHLIB_LINK:R}.ld 295STAGE_DIR.ldscript = ${STAGE_LIBDIR} 296STAGE_AS_${SHLIB_LINK:R}.ld:= ${SHLIB_LINK} 297NO_SHLIB_LINKS= 298.endif 299 300.if target(stage_files.shlib) 301stage_libs: ${_LIBS} 302.if defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols) 303stage_files.shlib: ${SHLIB_NAME}.symbols 304.endif 305.else 306stage_libs: ${_LIBS} 307.endif 308.if defined(SHLIB_NAME) && defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols) 309stage_libs: ${SHLIB_NAME}.symbols 310.endif 311 312.endif 313 314.if !empty(INCS) || !empty(INCSGROUPS) && target(buildincludes) 315.if !defined(NO_BEFOREBUILD_INCLUDES) 316stage_includes: buildincludes 317beforebuild: stage_includes 318.endif 319.endif 320 321.for t in stage_libs stage_files stage_as 322.if target($t) 323STAGE_TARGETS+= $t 324.endif 325.endfor 326 327.if !empty(STAGE_AS_SETS) 328STAGE_TARGETS+= stage_as 329.endif 330 331.if !empty(_LIBS) || (${MK_STAGING_PROG} != "no" && !defined(INTERNALPROG)) 332 333.if !empty(LINKS) 334STAGE_TARGETS+= stage_links 335.if ${MAKE_VERSION} < 20131001 336stage_links.links: ${_LIBS} ${PROG} 337.endif 338STAGE_SETS+= links 339STAGE_LINKS.links= ${LINKS} 340.endif 341 342.if !empty(SYMLINKS) 343STAGE_TARGETS+= stage_symlinks 344STAGE_SETS+= links 345STAGE_SYMLINKS.links= ${SYMLINKS} 346.endif 347 348.endif 349 350.include <meta.stage.mk> 351.endif 352.endif 353 354.if defined(META_TARGETS) 355.for _tgt in ${META_TARGETS} 356.if target(${_tgt}) 357${_tgt}: ${META_DEPS} 358.endif 359.endfor 360.endif 361