bsd.sys.mk revision 232930
176861Skris# $FreeBSD: stable/9/share/mk/bsd.sys.mk 232930 2012-03-13 18:39:57Z dim $ 276861Skris# 376861Skris# This file contains common settings used for building FreeBSD 476861Skris# sources. 576861Skris 676861Skris# Enable various levels of compiler warning checks. These may be 776861Skris# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS. 876861Skris 996316Sobrien# for GCC: http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html#IDX143 1096316Sobrien 11189801Srdivacky# the default is gnu99 for now 12189801SrdivackyCSTD ?= gnu99 13189801Srdivacky 14220863Sdim.if ${CSTD} == "k&r" 15161214SdesCFLAGS += -traditional 16220863Sdim.elif ${CSTD} == "c89" || ${CSTD} == "c90" 17161214SdesCFLAGS += -std=iso9899:1990 18220863Sdim.elif ${CSTD} == "c94" || ${CSTD} == "c95" 19161214SdesCFLAGS += -std=iso9899:199409 20220863Sdim.elif ${CSTD} == "c99" 21161214SdesCFLAGS += -std=iso9899:1999 22220863Sdim.else 23161214SdesCFLAGS += -std=${CSTD} 24198365Sru.endif 25220863Sdim.if !defined(NO_WARNS) 26161214Sdes# -pedantic is problematic because it also imposes namespace restrictions 27161214Sdes#CFLAGS += -pedantic 2876861Skris. if defined(WARNS) 29140359Sobrien. if ${WARNS} >= 1 30124372SruCWARNFLAGS += -Wsystem-headers 31232930Sdim. if !defined(NO_WERROR) && (${CC:T:Mclang} != "clang" || !defined(NO_WERROR.clang)) 32124372SruCWARNFLAGS += -Werror 3399542Sobrien. endif 3476861Skris. endif 35140359Sobrien. if ${WARNS} >= 2 36124372SruCWARNFLAGS += -Wall -Wno-format-y2k 3776861Skris. endif 38140359Sobrien. if ${WARNS} >= 3 39140361SobrienCWARNFLAGS += -W -Wno-unused-parameter -Wstrict-prototypes\ 40140361Sobrien -Wmissing-prototypes -Wpointer-arith 4187976Sobrien. endif 42140359Sobrien. if ${WARNS} >= 4 43140361SobrienCWARNFLAGS += -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch\ 44204025Smarcel -Wshadow -Wunused-parameter 45232930Sdim. if !defined(NO_WCAST_ALIGN) && (${CC:T:Mclang} != "clang" || !defined(NO_WCAST_ALIGN.clang)) 46204025SmarcelCWARNFLAGS += -Wcast-align 47204025Smarcel. endif 4887976Sobrien. endif 4994332Sobrien# BDECFLAGS 50140359Sobrien. if ${WARNS} >= 6 51201300SedCWARNFLAGS += -Wchar-subscripts -Winline -Wnested-externs\ 52201300Sed -Wredundant-decls -Wold-style-definition 5394332Sobrien. endif 54140359Sobrien. if ${WARNS} >= 2 && ${WARNS} <= 4 5588936Sdwmalone# XXX Delete -Wuninitialized by default for now -- the compiler doesn't 5688936Sdwmalone# XXX always get it right. 57124372SruCWARNFLAGS += -Wno-uninitialized 5888936Sdwmalone. endif 59169723SkanCWARNFLAGS += -Wno-pointer-sign 60229087Sdim# Clang has more warnings enabled by default, and when using -Wall, so if WARNS 61229087Sdim# is set to low values, these have to be disabled explicitly. 62229087Sdim. if ${CC:T:Mclang} == "clang" 63229087Sdim. if ${WARNS} <= 3 64229087SdimCWARNFLAGS += -Wno-tautological-compare -Wno-unused-value\ 65229087Sdim -Wno-parentheses-equality -Wno-unused-function\ 66229087Sdim -Wno-conversion 67229087Sdim. endif 68229087Sdim. if ${WARNS} <= 2 69229087SdimCWARNFLAGS += -Wno-switch-enum -Wno-empty-body 70229087Sdim. endif 71229087Sdim. if ${WARNS} <= 1 72229087SdimCWARNFLAGS += -Wno-parentheses 73229087Sdim. endif 74229087Sdim. if defined(NO_WARRAY_BOUNDS) 75229087SdimCWARNFLAGS += -Wno-array-bounds 76229087Sdim. endif 77229087Sdim. endif 7876861Skris. endif 7976861Skris 8076861Skris. if defined(FORMAT_AUDIT) 8176861SkrisWFORMAT = 1 8276861Skris. endif 8376861Skris. if defined(WFORMAT) 8476861Skris. if ${WFORMAT} > 0 85124372Sru#CWARNFLAGS += -Wformat-nonliteral -Wformat-security -Wno-format-extra-args 86124372SruCWARNFLAGS += -Wformat=2 -Wno-format-extra-args 87232930Sdim. if !defined(NO_WERROR) && (${CC:T:Mclang} != "clang" || !defined(NO_WERROR.clang)) 88124372SruCWARNFLAGS += -Werror 8999542Sobrien. endif 9076861Skris. endif 9176861Skris. endif 92232930Sdim. if defined(NO_WFORMAT) || (${CC:T:Mclang} == "clang" && defined(NO_WFORMAT.clang)) 93219368SpjdCWARNFLAGS += -Wno-format 94219368Spjd. endif 9576861Skris.endif 9676861Skris 97163971Sjb.if defined(IGNORE_PRAGMA) 98163971SjbCWARNFLAGS += -Wno-unknown-pragmas 99163971Sjb.endif 100163971Sjb 101232930Sdim.if ${CC:T:Mclang} == "clang" 102232930SdimCLANG_NO_IAS = -no-integrated-as 103232930SdimCLANG_OPT_SMALL = -mllvm -stack-alignment=8 -mllvm -inline-threshold=3 \ 104232930Sdim -mllvm -enable-load-pre=false 105232930Sdim.endif 106232930Sdim 107220863Sdim.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 108220863Sdim ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 109180012Sru# Don't use -Wstack-protector as it breaks world with -Werror. 110180012SruSSP_CFLAGS ?= -fstack-protector 111180012SruCFLAGS += ${SSP_CFLAGS} 112180012Sru.endif 113180012Sru 11476861Skris# Allow user-specified additional warning flags 11576861SkrisCFLAGS += ${CWARNFLAGS} 116