176861Skris# $FreeBSD: stable/10/share/mk/bsd.sys.mk 313790 2017-02-16 05:14:07Z ngie $ 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 9233052Sdim# for GCC: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html 1096316Sobrien 11240468Sbrooks.include <bsd.compiler.mk> 12240468Sbrooks 13189801Srdivacky# the default is gnu99 for now 14233052SdimCSTD?= gnu99 15189801Srdivacky 16220863Sdim.if ${CSTD} == "k&r" 17233052SdimCFLAGS+= -traditional 18220863Sdim.elif ${CSTD} == "c89" || ${CSTD} == "c90" 19233052SdimCFLAGS+= -std=iso9899:1990 20220863Sdim.elif ${CSTD} == "c94" || ${CSTD} == "c95" 21233052SdimCFLAGS+= -std=iso9899:199409 22220863Sdim.elif ${CSTD} == "c99" 23233052SdimCFLAGS+= -std=iso9899:1999 24233052Sdim.else # CSTD 25233052SdimCFLAGS+= -std=${CSTD} 26233052Sdim.endif # CSTD 27220863Sdim.if !defined(NO_WARNS) 28161214Sdes# -pedantic is problematic because it also imposes namespace restrictions 29233052Sdim#CFLAGS+= -pedantic 30233052Sdim.if defined(WARNS) 31233052Sdim.if ${WARNS} >= 1 32233052SdimCWARNFLAGS+= -Wsystem-headers 33240468Sbrooks.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 34240468Sbrooks || !defined(NO_WERROR.clang)) 35233052SdimCWARNFLAGS+= -Werror 36233052Sdim.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 37233052Sdim.endif # WARNS >= 1 38233052Sdim.if ${WARNS} >= 2 39233052SdimCWARNFLAGS+= -Wall -Wno-format-y2k 40233052Sdim.endif # WARNS >= 2 41233052Sdim.if ${WARNS} >= 3 42233052SdimCWARNFLAGS+= -W -Wno-unused-parameter -Wstrict-prototypes\ 43233052Sdim -Wmissing-prototypes -Wpointer-arith 44233052Sdim.endif # WARNS >= 3 45233052Sdim.if ${WARNS} >= 4 46233052SdimCWARNFLAGS+= -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\ 47233052Sdim -Wunused-parameter 48240468Sbrooks.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \ 49240468Sbrooks || !defined(NO_WCAST_ALIGN.clang)) 50233052SdimCWARNFLAGS+= -Wcast-align 51233052Sdim.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang) 52233052Sdim.endif # WARNS >= 4 5394332Sobrien# BDECFLAGS 54233052Sdim.if ${WARNS} >= 6 55233052SdimCWARNFLAGS+= -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\ 56233052Sdim -Wold-style-definition 57249657Sed.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \ 58249657Sed !defined(NO_WMISSING_VARIABLE_DECLARATIONS) 59249657SedCWARNFLAGS+= -Wmissing-variable-declarations 60249657Sed.endif 61233052Sdim.endif # WARNS >= 6 62233052Sdim.if ${WARNS} >= 2 && ${WARNS} <= 4 6388936Sdwmalone# XXX Delete -Wuninitialized by default for now -- the compiler doesn't 6488936Sdwmalone# XXX always get it right. 65233052SdimCWARNFLAGS+= -Wno-uninitialized 66233052Sdim.endif # WARNS >=2 && WARNS <= 4 67233052SdimCWARNFLAGS+= -Wno-pointer-sign 68228546Sdim# Clang has more warnings enabled by default, and when using -Wall, so if WARNS 69228546Sdim# is set to low values, these have to be disabled explicitly. 70240468Sbrooks.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 71234353Sdim.if ${WARNS} <= 6 72279793SdimCWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int 73279793Sdim.if ${COMPILER_VERSION} > 30300 74279793SdimCWARNFLAGS+= -Wno-unused-const-variable 75279793Sdim.endif 76234353Sdim.endif # WARNS <= 6 77233052Sdim.if ${WARNS} <= 3 78233052SdimCWARNFLAGS+= -Wno-tautological-compare -Wno-unused-value\ 79259158Sdim -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion 80233052Sdim.endif # WARNS <= 3 81233052Sdim.if ${WARNS} <= 2 82246880SdimCWARNFLAGS+= -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter 83233052Sdim.endif # WARNS <= 2 84233052Sdim.if ${WARNS} <= 1 85233052SdimCWARNFLAGS+= -Wno-parentheses 86233052Sdim.endif # WARNS <= 1 87233052Sdim.if defined(NO_WARRAY_BOUNDS) 88233052SdimCWARNFLAGS+= -Wno-array-bounds 89233052Sdim.endif # NO_WARRAY_BOUNDS 90233052Sdim.endif # CLANG 91233052Sdim.endif # WARNS 9276861Skris 93233052Sdim.if defined(FORMAT_AUDIT) 94233052SdimWFORMAT= 1 95233052Sdim.endif # FORMAT_AUDIT 96233052Sdim.if defined(WFORMAT) 97233052Sdim.if ${WFORMAT} > 0 98233052Sdim#CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args 99233052SdimCWARNFLAGS+= -Wformat=2 -Wno-format-extra-args 100240468Sbrooks.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 101234353Sdim.if ${WARNS} <= 3 102234353SdimCWARNFLAGS+= -Wno-format-nonliteral 103234353Sdim.endif # WARNS <= 3 104234353Sdim.endif # CLANG 105240468Sbrooks.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 106240468Sbrooks || !defined(NO_WERROR.clang)) 107233052SdimCWARNFLAGS+= -Werror 108233052Sdim.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 109233052Sdim.endif # WFORMAT > 0 110233052Sdim.endif # WFORMAT 111240468Sbrooks.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang)) 112233052SdimCWARNFLAGS+= -Wno-format 113233052Sdim.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang) 114233052Sdim.endif # !NO_WARNS 11576861Skris 116163971Sjb.if defined(IGNORE_PRAGMA) 117233052SdimCWARNFLAGS+= -Wno-unknown-pragmas 118233052Sdim.endif # IGNORE_PRAGMA 119163971Sjb 120260096Sdim.if !defined(EARLY_BUILD) 121260096Sdim.if ${COMPILER_TYPE} == "clang" 122233052SdimCLANG_NO_IAS= -no-integrated-as 123234353SdimCLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\ 124233052Sdim -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret 125234353SdimCFLAGS+= -Qunused-arguments 126263763Sdim.if ${MACHINE_CPUARCH} == "sparc64" 127263763Sdim# Don't emit .cfi directives, since we must use GNU as on sparc64, for now. 128263763SdimCFLAGS+= -fno-dwarf2-cfi-asm 129263763Sdim.endif # SPARC64 130262459Sdim# The libc++ headers use c++11 extensions. These are normally silenced because 131262459Sdim# they are treated as system headers, but we explicitly disable that warning 132262459Sdim# suppression when building the base system to catch bugs in our headers. 133262459Sdim# Eventually we'll want to start building the base system C++ code as C++11, 134262459Sdim# but not yet. 135262459SdimCXXFLAGS+= -Wno-c++11-extensions 136260096SdimCFLAGS+= ${CFLAGS.clang} 137260096SdimCXXFLAGS+= ${CXXFLAGS.clang} 138260096Sdim.else # !CLANG 139260495SdimGCC_MS_EXTENSIONS= -fms-extensions 140260096SdimCFLAGS+= ${CFLAGS.gcc} 141260096SdimCXXFLAGS+= ${CXXFLAGS.gcc} 142233052Sdim.endif # CLANG 143260096Sdim.endif # !EARLY_BUILD 144232263Sdim 145220863Sdim.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 146220863Sdim ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 147180012Sru# Don't use -Wstack-protector as it breaks world with -Werror. 148233052SdimSSP_CFLAGS?= -fstack-protector 149233052SdimCFLAGS+= ${SSP_CFLAGS} 150233052Sdim.endif # SSP && !IA64 && !ARM && !MIPS 151180012Sru 152294974Ssmh# Allow user-specified additional warning flags and file specific flag 153294974Ssmh# overrides. 154294974SsmhCFLAGS+= ${CWARNFLAGS} ${CWARNFLAGS.${.IMPSRC:T}} 155241298Smarcel 156241298Smarcel 157241298Smarcel# Tell bmake not to mistake standard targets for things to be searched for 158241298Smarcel# or expect to ever be up-to-date. 159241298SmarcelPHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ 160241298Smarcel beforelinking build build-tools buildfiles buildincludes \ 161313790Sngie check checkdpadd clean cleandepend cleandir cleanobj configure \ 162262964Sache depend dependall distclean distribute exe extract \ 163241298Smarcel html includes install installfiles installincludes lint \ 164262964Sache obj objlink objs objwarn realall realdepend \ 165313790Sngie realinstall subdir-all subdir-depend subdir-install \ 166241298Smarcel tags whereobj 167241298Smarcel 168262964Sache.if defined(PORTNAME) 169262964SachePHONY_NOTMAIN+= fetch patch 170262964Sache.endif 171262964Sache 172241298Smarcel.PHONY: ${PHONY_NOTMAIN} 173241298Smarcel.NOTMAIN: ${PHONY_NOTMAIN} 174