bsd.sys.mk revision 313790
133965Sjdp# $FreeBSD: stable/10/share/mk/bsd.sys.mk 313790 2017-02-16 05:14:07Z ngie $ 2218822Sdim# 3218822Sdim# This file contains common settings used for building FreeBSD 433965Sjdp# sources. 533965Sjdp 6104834Sobrien# Enable various levels of compiler warning checks. These may be 733965Sjdp# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS. 8104834Sobrien 9104834Sobrien# for GCC: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html 10104834Sobrien 11104834Sobrien.include <bsd.compiler.mk> 1233965Sjdp 13104834Sobrien# the default is gnu99 for now 14104834SobrienCSTD?= gnu99 15104834Sobrien 16104834Sobrien.if ${CSTD} == "k&r" 1733965SjdpCFLAGS+= -traditional 18104834Sobrien.elif ${CSTD} == "c89" || ${CSTD} == "c90" 19104834SobrienCFLAGS+= -std=iso9899:1990 20218822Sdim.elif ${CSTD} == "c94" || ${CSTD} == "c95" 2133965SjdpCFLAGS+= -std=iso9899:199409 2233965Sjdp.elif ${CSTD} == "c99" 2333965SjdpCFLAGS+= -std=iso9899:1999 2433965Sjdp.else # CSTD 2533965SjdpCFLAGS+= -std=${CSTD} 2633965Sjdp.endif # CSTD 2733965Sjdp.if !defined(NO_WARNS) 2833965Sjdp# -pedantic is problematic because it also imposes namespace restrictions 2933965Sjdp#CFLAGS+= -pedantic 3033965Sjdp.if defined(WARNS) 3133965Sjdp.if ${WARNS} >= 1 3233965SjdpCWARNFLAGS+= -Wsystem-headers 3333965Sjdp.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 3433965Sjdp || !defined(NO_WERROR.clang)) 3533965SjdpCWARNFLAGS+= -Werror 3633965Sjdp.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 3733965Sjdp.endif # WARNS >= 1 3889857Sobrien.if ${WARNS} >= 2 3989857SobrienCWARNFLAGS+= -Wall -Wno-format-y2k 4033965Sjdp.endif # WARNS >= 2 4133965Sjdp.if ${WARNS} >= 3 4233965SjdpCWARNFLAGS+= -W -Wno-unused-parameter -Wstrict-prototypes\ 4333965Sjdp -Wmissing-prototypes -Wpointer-arith 4489857Sobrien.endif # WARNS >= 3 4589857Sobrien.if ${WARNS} >= 4 4689857SobrienCWARNFLAGS+= -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\ 4789857Sobrien -Wunused-parameter 4889857Sobrien.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \ 4989857Sobrien || !defined(NO_WCAST_ALIGN.clang)) 5089857SobrienCWARNFLAGS+= -Wcast-align 5189857Sobrien.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang) 5289857Sobrien.endif # WARNS >= 4 5333965Sjdp# BDECFLAGS 5433965Sjdp.if ${WARNS} >= 6 5533965SjdpCWARNFLAGS+= -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\ 5633965Sjdp -Wold-style-definition 5733965Sjdp.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \ 5833965Sjdp !defined(NO_WMISSING_VARIABLE_DECLARATIONS) 5933965SjdpCWARNFLAGS+= -Wmissing-variable-declarations 6033965Sjdp.endif 6133965Sjdp.endif # WARNS >= 6 6233965Sjdp.if ${WARNS} >= 2 && ${WARNS} <= 4 6333965Sjdp# XXX Delete -Wuninitialized by default for now -- the compiler doesn't 6433965Sjdp# XXX always get it right. 6533965SjdpCWARNFLAGS+= -Wno-uninitialized 6633965Sjdp.endif # WARNS >=2 && WARNS <= 4 6733965SjdpCWARNFLAGS+= -Wno-pointer-sign 6833965Sjdp# Clang has more warnings enabled by default, and when using -Wall, so if WARNS 69130561Sobrien# is set to low values, these have to be disabled explicitly. 70130561Sobrien.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 71130561Sobrien.if ${WARNS} <= 6 72130561SobrienCWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int 73130561Sobrien.if ${COMPILER_VERSION} > 30300 74130561SobrienCWARNFLAGS+= -Wno-unused-const-variable 75130561Sobrien.endif 76130561Sobrien.endif # WARNS <= 6 7733965Sjdp.if ${WARNS} <= 3 7833965SjdpCWARNFLAGS+= -Wno-tautological-compare -Wno-unused-value\ 7933965Sjdp -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion 8033965Sjdp.endif # WARNS <= 3 8133965Sjdp.if ${WARNS} <= 2 8233965SjdpCWARNFLAGS+= -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter 8333965Sjdp.endif # WARNS <= 2 84130561Sobrien.if ${WARNS} <= 1 8533965SjdpCWARNFLAGS+= -Wno-parentheses 8633965Sjdp.endif # WARNS <= 1 8733965Sjdp.if defined(NO_WARRAY_BOUNDS) 8833965SjdpCWARNFLAGS+= -Wno-array-bounds 8933965Sjdp.endif # NO_WARRAY_BOUNDS 9033965Sjdp.endif # CLANG 9133965Sjdp.endif # WARNS 9233965Sjdp 9333965Sjdp.if defined(FORMAT_AUDIT) 9433965SjdpWFORMAT= 1 95218822Sdim.endif # FORMAT_AUDIT 96218822Sdim.if defined(WFORMAT) 97218822Sdim.if ${WFORMAT} > 0 98218822Sdim#CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args 99218822SdimCWARNFLAGS+= -Wformat=2 -Wno-format-extra-args 100218822Sdim.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 101218822Sdim.if ${WARNS} <= 3 102218822SdimCWARNFLAGS+= -Wno-format-nonliteral 103218822Sdim.endif # WARNS <= 3 104218822Sdim.endif # CLANG 105218822Sdim.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 106218822Sdim || !defined(NO_WERROR.clang)) 107218822SdimCWARNFLAGS+= -Werror 108218822Sdim.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 109218822Sdim.endif # WFORMAT > 0 110218822Sdim.endif # WFORMAT 111218822Sdim.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang)) 112218822SdimCWARNFLAGS+= -Wno-format 113218822Sdim.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang) 114218822Sdim.endif # !NO_WARNS 11533965Sjdp 116218822Sdim.if defined(IGNORE_PRAGMA) 11733965SjdpCWARNFLAGS+= -Wno-unknown-pragmas 11833965Sjdp.endif # IGNORE_PRAGMA 11933965Sjdp 12033965Sjdp.if !defined(EARLY_BUILD) 121218822Sdim.if ${COMPILER_TYPE} == "clang" 122218822SdimCLANG_NO_IAS= -no-integrated-as 12333965SjdpCLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\ 12433965Sjdp -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret 12533965SjdpCFLAGS+= -Qunused-arguments 12633965Sjdp.if ${MACHINE_CPUARCH} == "sparc64" 12733965Sjdp# Don't emit .cfi directives, since we must use GNU as on sparc64, for now. 128218822SdimCFLAGS+= -fno-dwarf2-cfi-asm 12933965Sjdp.endif # SPARC64 13033965Sjdp# The libc++ headers use c++11 extensions. These are normally silenced because 13133965Sjdp# they are treated as system headers, but we explicitly disable that warning 13233965Sjdp# suppression when building the base system to catch bugs in our headers. 13333965Sjdp# Eventually we'll want to start building the base system C++ code as C++11, 13433965Sjdp# but not yet. 135218822SdimCXXFLAGS+= -Wno-c++11-extensions 13633965SjdpCFLAGS+= ${CFLAGS.clang} 137130561SobrienCXXFLAGS+= ${CXXFLAGS.clang} 138130561Sobrien.else # !CLANG 139130561SobrienGCC_MS_EXTENSIONS= -fms-extensions 140130561SobrienCFLAGS+= ${CFLAGS.gcc} 141130561SobrienCXXFLAGS+= ${CXXFLAGS.gcc} 142130561Sobrien.endif # CLANG 143130561Sobrien.endif # !EARLY_BUILD 144130561Sobrien 14533965Sjdp.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 14633965Sjdp ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 14733965Sjdp# Don't use -Wstack-protector as it breaks world with -Werror. 14833965SjdpSSP_CFLAGS?= -fstack-protector 14933965SjdpCFLAGS+= ${SSP_CFLAGS} 150218822Sdim.endif # SSP && !IA64 && !ARM && !MIPS 15133965Sjdp 15233965Sjdp# Allow user-specified additional warning flags and file specific flag 15333965Sjdp# overrides. 15433965SjdpCFLAGS+= ${CWARNFLAGS} ${CWARNFLAGS.${.IMPSRC:T}} 15533965Sjdp 15633965Sjdp 15733965Sjdp# Tell bmake not to mistake standard targets for things to be searched for 15833965Sjdp# or expect to ever be up-to-date. 15933965SjdpPHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ 16033965Sjdp beforelinking build build-tools buildfiles buildincludes \ 16133965Sjdp check checkdpadd clean cleandepend cleandir cleanobj configure \ 16233965Sjdp depend dependall distclean distribute exe extract \ 16333965Sjdp html includes install installfiles installincludes lint \ 16433965Sjdp obj objlink objs objwarn realall realdepend \ 16533965Sjdp realinstall subdir-all subdir-depend subdir-install \ 16633965Sjdp tags whereobj 16733965Sjdp 16833965Sjdp.if defined(PORTNAME) 16933965SjdpPHONY_NOTMAIN+= fetch patch 17033965Sjdp.endif 17133965Sjdp 172130561Sobrien.PHONY: ${PHONY_NOTMAIN} 17389857Sobrien.NOTMAIN: ${PHONY_NOTMAIN} 17433965Sjdp