bsd.sys.mk revision 228546
176861Skris# $FreeBSD: head/share/mk/bsd.sys.mk 228546 2011-12-15 22:08:08Z 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
3199542Sobrien.   if !defined(NO_WERROR)
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
45204025Smarcel.   if !defined(NO_WCAST_ALIGN)
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
60228546Sdim# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
61228546Sdim# is set to low values, these have to be disabled explicitly.
62228546Sdim.  if ${CC:T:Mclang} == "clang"
63228546Sdim.   if ${WARNS} <= 3
64228546SdimCWARNFLAGS	+=	-Wno-tautological-compare -Wno-unused-value
65228546Sdim.   endif
66228546Sdim.   if ${WARNS} <= 2
67228546SdimCWARNFLAGS	+=	-Wno-switch-enum
68228546Sdim.   endif
69228546Sdim.   if ${WARNS} <= 1
70228546SdimCWARNFLAGS	+=	-Wno-parentheses
71228546Sdim.   endif
72228546Sdim.  endif
7376861Skris. endif
7476861Skris
7576861Skris. if defined(FORMAT_AUDIT)
7676861SkrisWFORMAT		=	1
7776861Skris. endif
7876861Skris. if defined(WFORMAT)
7976861Skris.  if ${WFORMAT} > 0
80124372Sru#CWARNFLAGS	+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
81124372SruCWARNFLAGS	+=	-Wformat=2 -Wno-format-extra-args
8299542Sobrien.   if !defined(NO_WERROR)
83124372SruCWARNFLAGS	+=	-Werror
8499542Sobrien.   endif
8576861Skris.  endif
8676861Skris. endif
87219368Spjd. if defined(NO_WFORMAT)
88219368SpjdCWARNFLAGS	+=	-Wno-format
89219368Spjd. endif
9076861Skris.endif
9176861Skris
92163971Sjb.if defined(IGNORE_PRAGMA)
93163971SjbCWARNFLAGS	+=	-Wno-unknown-pragmas
94163971Sjb.endif
95163971Sjb
96220863Sdim.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
97220863Sdim    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
98180012Sru# Don't use -Wstack-protector as it breaks world with -Werror.
99180012SruSSP_CFLAGS	?=	-fstack-protector
100180012SruCFLAGS		+=	${SSP_CFLAGS}
101180012Sru.endif
102180012Sru
10376861Skris# Allow user-specified additional warning flags
10476861SkrisCFLAGS		+=	${CWARNFLAGS}
105