176861Skris# $FreeBSD$ 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 9234237Sdim# for GCC: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html 1096316Sobrien 11243041Sdim.include <bsd.compiler.mk> 12243041Sdim 13189801Srdivacky# the default is gnu99 for now 14234237SdimCSTD?= gnu99 15189801Srdivacky 16220863Sdim.if ${CSTD} == "k&r" 17234237SdimCFLAGS+= -traditional 18220863Sdim.elif ${CSTD} == "c89" || ${CSTD} == "c90" 19234237SdimCFLAGS+= -std=iso9899:1990 20220863Sdim.elif ${CSTD} == "c94" || ${CSTD} == "c95" 21234237SdimCFLAGS+= -std=iso9899:199409 22220863Sdim.elif ${CSTD} == "c99" 23234237SdimCFLAGS+= -std=iso9899:1999 24234237Sdim.else # CSTD 25234237SdimCFLAGS+= -std=${CSTD} 26234237Sdim.endif # CSTD 27220863Sdim.if !defined(NO_WARNS) 28161214Sdes# -pedantic is problematic because it also imposes namespace restrictions 29234237Sdim#CFLAGS+= -pedantic 30234237Sdim.if defined(WARNS) 31234237Sdim.if ${WARNS} >= 1 32234237SdimCWARNFLAGS+= -Wsystem-headers 33243041Sdim.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 34243041Sdim || !defined(NO_WERROR.clang)) 35234237SdimCWARNFLAGS+= -Werror 36234237Sdim.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 37234237Sdim.endif # WARNS >= 1 38234237Sdim.if ${WARNS} >= 2 39234237SdimCWARNFLAGS+= -Wall -Wno-format-y2k 40234237Sdim.endif # WARNS >= 2 41234237Sdim.if ${WARNS} >= 3 42234237SdimCWARNFLAGS+= -W -Wno-unused-parameter -Wstrict-prototypes\ 43234237Sdim -Wmissing-prototypes -Wpointer-arith 44234237Sdim.endif # WARNS >= 3 45234237Sdim.if ${WARNS} >= 4 46234237SdimCWARNFLAGS+= -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\ 47234237Sdim -Wunused-parameter 48243041Sdim.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \ 49243041Sdim || !defined(NO_WCAST_ALIGN.clang)) 50234237SdimCWARNFLAGS+= -Wcast-align 51234237Sdim.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang) 52234237Sdim.endif # WARNS >= 4 5394332Sobrien# BDECFLAGS 54234237Sdim.if ${WARNS} >= 6 55234237SdimCWARNFLAGS+= -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\ 56234237Sdim -Wold-style-definition 57234237Sdim.endif # WARNS >= 6 58234237Sdim.if ${WARNS} >= 2 && ${WARNS} <= 4 5988936Sdwmalone# XXX Delete -Wuninitialized by default for now -- the compiler doesn't 6088936Sdwmalone# XXX always get it right. 61234237SdimCWARNFLAGS+= -Wno-uninitialized 62234237Sdim.endif # WARNS >=2 && WARNS <= 4 63234237SdimCWARNFLAGS+= -Wno-pointer-sign 64229087Sdim# Clang has more warnings enabled by default, and when using -Wall, so if WARNS 65229087Sdim# is set to low values, these have to be disabled explicitly. 66243041Sdim.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 67235633Sdim.if ${WARNS} <= 6 68263509SdimCWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable 69235633Sdim.endif # WARNS <= 6 70234237Sdim.if ${WARNS} <= 3 71234237SdimCWARNFLAGS+= -Wno-tautological-compare -Wno-unused-value\ 72259158Sdim -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion 73234237Sdim.endif # WARNS <= 3 74234237Sdim.if ${WARNS} <= 2 75247333SdimCWARNFLAGS+= -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter 76234237Sdim.endif # WARNS <= 2 77234237Sdim.if ${WARNS} <= 1 78234237SdimCWARNFLAGS+= -Wno-parentheses 79234237Sdim.endif # WARNS <= 1 80234237Sdim.if defined(NO_WARRAY_BOUNDS) 81234237SdimCWARNFLAGS+= -Wno-array-bounds 82234237Sdim.endif # NO_WARRAY_BOUNDS 83234237Sdim.endif # CLANG 84234237Sdim.endif # WARNS 8576861Skris 86234237Sdim.if defined(FORMAT_AUDIT) 87234237SdimWFORMAT= 1 88234237Sdim.endif # FORMAT_AUDIT 89234237Sdim.if defined(WFORMAT) 90234237Sdim.if ${WFORMAT} > 0 91234237Sdim#CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args 92234237SdimCWARNFLAGS+= -Wformat=2 -Wno-format-extra-args 93243041Sdim.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 94235633Sdim.if ${WARNS} <= 3 95235633SdimCWARNFLAGS+= -Wno-format-nonliteral 96235633Sdim.endif # WARNS <= 3 97235633Sdim.endif # CLANG 98243041Sdim.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 99243041Sdim || !defined(NO_WERROR.clang)) 100234237SdimCWARNFLAGS+= -Werror 101234237Sdim.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 102234237Sdim.endif # WFORMAT > 0 103234237Sdim.endif # WFORMAT 104243041Sdim.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang)) 105234237SdimCWARNFLAGS+= -Wno-format 106234237Sdim.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang) 107234237Sdim.endif # !NO_WARNS 10876861Skris 109163971Sjb.if defined(IGNORE_PRAGMA) 110234237SdimCWARNFLAGS+= -Wno-unknown-pragmas 111234237Sdim.endif # IGNORE_PRAGMA 112163971Sjb 113260096Sdim.if !defined(EARLY_BUILD) 114260096Sdim.if ${COMPILER_TYPE} == "clang" 115234237SdimCLANG_NO_IAS= -no-integrated-as 116235633SdimCLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\ 117234237Sdim -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret 118235633SdimCFLAGS+= -Qunused-arguments 119263764Sdim.if ${MACHINE_CPUARCH} == "sparc64" 120263764Sdim# Don't emit .cfi directives, since we must use GNU as on sparc64, for now. 121263764SdimCFLAGS+= -fno-dwarf2-cfi-asm 122263764Sdim.endif # SPARC64 123262459Sdim# The libc++ headers use c++11 extensions. These are normally silenced because 124262459Sdim# they are treated as system headers, but we explicitly disable that warning 125262459Sdim# suppression when building the base system to catch bugs in our headers. 126262459Sdim# Eventually we'll want to start building the base system C++ code as C++11, 127262459Sdim# but not yet. 128262459SdimCXXFLAGS+= -Wno-c++11-extensions 129260096SdimCFLAGS+= ${CFLAGS.clang} 130260096SdimCXXFLAGS+= ${CXXFLAGS.clang} 131260096Sdim.else # !CLANG 132260495SdimGCC_MS_EXTENSIONS= -fms-extensions 133260096SdimCFLAGS+= ${CFLAGS.gcc} 134260096SdimCXXFLAGS+= ${CXXFLAGS.gcc} 135234237Sdim.endif # CLANG 136260096Sdim.endif # !EARLY_BUILD 137232930Sdim 138220863Sdim.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 139220863Sdim ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 140180012Sru# Don't use -Wstack-protector as it breaks world with -Werror. 141234237SdimSSP_CFLAGS?= -fstack-protector 142234237SdimCFLAGS+= ${SSP_CFLAGS} 143234237Sdim.endif # SSP && !IA64 && !ARM && !MIPS 144180012Sru 14576861Skris# Allow user-specified additional warning flags 146234237SdimCFLAGS+= ${CWARNFLAGS} 147252048Ssjg 148252048Ssjg 149252048Ssjg# Tell bmake not to mistake standard targets for things to be searched for 150252048Ssjg# or expect to ever be up-to-date. 151252048SsjgPHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ 152252048Ssjg beforelinking build build-tools buildfiles buildincludes \ 153252048Ssjg checkdpadd clean cleandepend cleandir cleanobj configure \ 154252048Ssjg depend dependall distclean distribute exe extract fetch \ 155252048Ssjg html includes install installfiles installincludes lint \ 156252048Ssjg obj objlink objs objwarn patch realall realdepend \ 157252048Ssjg realinstall regress subdir-all subdir-depend subdir-install \ 158252048Ssjg tags whereobj 159252048Ssjg 160252048Ssjg.PHONY: ${PHONY_NOTMAIN} 161252048Ssjg.NOTMAIN: ${PHONY_NOTMAIN} 162