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 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 72263508SdimCWARNFLAGS+= -Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable 73234353Sdim.endif # WARNS <= 6 74233052Sdim.if ${WARNS} <= 3 75233052SdimCWARNFLAGS+= -Wno-tautological-compare -Wno-unused-value\ 76259158Sdim -Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion 77233052Sdim.endif # WARNS <= 3 78233052Sdim.if ${WARNS} <= 2 79246880SdimCWARNFLAGS+= -Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter 80233052Sdim.endif # WARNS <= 2 81233052Sdim.if ${WARNS} <= 1 82233052SdimCWARNFLAGS+= -Wno-parentheses 83233052Sdim.endif # WARNS <= 1 84233052Sdim.if defined(NO_WARRAY_BOUNDS) 85233052SdimCWARNFLAGS+= -Wno-array-bounds 86233052Sdim.endif # NO_WARRAY_BOUNDS 87233052Sdim.endif # CLANG 88233052Sdim.endif # WARNS 8976861Skris 90233052Sdim.if defined(FORMAT_AUDIT) 91233052SdimWFORMAT= 1 92233052Sdim.endif # FORMAT_AUDIT 93233052Sdim.if defined(WFORMAT) 94233052Sdim.if ${WFORMAT} > 0 95233052Sdim#CWARNFLAGS+= -Wformat-nonliteral -Wformat-security -Wno-format-extra-args 96233052SdimCWARNFLAGS+= -Wformat=2 -Wno-format-extra-args 97240468Sbrooks.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) 98234353Sdim.if ${WARNS} <= 3 99234353SdimCWARNFLAGS+= -Wno-format-nonliteral 100234353Sdim.endif # WARNS <= 3 101234353Sdim.endif # CLANG 102240468Sbrooks.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \ 103240468Sbrooks || !defined(NO_WERROR.clang)) 104233052SdimCWARNFLAGS+= -Werror 105233052Sdim.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang) 106233052Sdim.endif # WFORMAT > 0 107233052Sdim.endif # WFORMAT 108240468Sbrooks.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang)) 109233052SdimCWARNFLAGS+= -Wno-format 110233052Sdim.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang) 111233052Sdim.endif # !NO_WARNS 11276861Skris 113163971Sjb.if defined(IGNORE_PRAGMA) 114233052SdimCWARNFLAGS+= -Wno-unknown-pragmas 115233052Sdim.endif # IGNORE_PRAGMA 116163971Sjb 117260096Sdim.if !defined(EARLY_BUILD) 118260096Sdim.if ${COMPILER_TYPE} == "clang" 119233052SdimCLANG_NO_IAS= -no-integrated-as 120234353SdimCLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\ 121233052Sdim -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret 122234353SdimCFLAGS+= -Qunused-arguments 123263763Sdim.if ${MACHINE_CPUARCH} == "sparc64" 124263763Sdim# Don't emit .cfi directives, since we must use GNU as on sparc64, for now. 125263763SdimCFLAGS+= -fno-dwarf2-cfi-asm 126263763Sdim.endif # SPARC64 127262459Sdim# The libc++ headers use c++11 extensions. These are normally silenced because 128262459Sdim# they are treated as system headers, but we explicitly disable that warning 129262459Sdim# suppression when building the base system to catch bugs in our headers. 130262459Sdim# Eventually we'll want to start building the base system C++ code as C++11, 131262459Sdim# but not yet. 132262459SdimCXXFLAGS+= -Wno-c++11-extensions 133260096SdimCFLAGS+= ${CFLAGS.clang} 134260096SdimCXXFLAGS+= ${CXXFLAGS.clang} 135260096Sdim.else # !CLANG 136260495SdimGCC_MS_EXTENSIONS= -fms-extensions 137260096SdimCFLAGS+= ${CFLAGS.gcc} 138260096SdimCXXFLAGS+= ${CXXFLAGS.gcc} 139233052Sdim.endif # CLANG 140260096Sdim.endif # !EARLY_BUILD 141232263Sdim 142220863Sdim.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \ 143220863Sdim ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips" 144180012Sru# Don't use -Wstack-protector as it breaks world with -Werror. 145233052SdimSSP_CFLAGS?= -fstack-protector 146233052SdimCFLAGS+= ${SSP_CFLAGS} 147233052Sdim.endif # SSP && !IA64 && !ARM && !MIPS 148180012Sru 14976861Skris# Allow user-specified additional warning flags 150233052SdimCFLAGS+= ${CWARNFLAGS} 151241298Smarcel 152241298Smarcel 153241298Smarcel# Tell bmake not to mistake standard targets for things to be searched for 154241298Smarcel# or expect to ever be up-to-date. 155241298SmarcelPHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \ 156241298Smarcel beforelinking build build-tools buildfiles buildincludes \ 157241298Smarcel checkdpadd clean cleandepend cleandir cleanobj configure \ 158262964Sache depend dependall distclean distribute exe extract \ 159241298Smarcel html includes install installfiles installincludes lint \ 160262964Sache obj objlink objs objwarn realall realdepend \ 161241298Smarcel realinstall regress subdir-all subdir-depend subdir-install \ 162241298Smarcel tags whereobj 163241298Smarcel 164262964Sache.if defined(PORTNAME) 165262964SachePHONY_NOTMAIN+= fetch patch 166262964Sache.endif 167262964Sache 168241298Smarcel.PHONY: ${PHONY_NOTMAIN} 169241298Smarcel.NOTMAIN: ${PHONY_NOTMAIN} 170