xref: /freebsd/share/mk/bsd.sys.mk (revision 675be9115aae86ad6b3d877155d4fd7822892105)
1# $FreeBSD$
2#
3# This file contains common settings used for building FreeBSD
4# sources.
5
6# Enable various levels of compiler warning checks.  These may be
7# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS.
8
9# for GCC:  http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html#IDX143
10
11# the default is gnu99 for now
12CSTD		?= gnu99
13
14.if ${CSTD} == "k&r"
15CFLAGS		+= -traditional
16.elif ${CSTD} == "c89" || ${CSTD} == "c90"
17CFLAGS		+= -std=iso9899:1990
18.elif ${CSTD} == "c94" || ${CSTD} == "c95"
19CFLAGS		+= -std=iso9899:199409
20.elif ${CSTD} == "c99"
21CFLAGS		+= -std=iso9899:1999
22.else
23CFLAGS		+= -std=${CSTD}
24.endif
25.if !defined(NO_WARNS)
26# -pedantic is problematic because it also imposes namespace restrictions
27#CFLAGS		+= -pedantic
28. if defined(WARNS)
29.  if ${WARNS} >= 1
30CWARNFLAGS	+=	-Wsystem-headers
31.   if !defined(NO_WERROR)
32CWARNFLAGS	+=	-Werror
33.   endif
34.  endif
35.  if ${WARNS} >= 2
36CWARNFLAGS	+=	-Wall -Wno-format-y2k
37.  endif
38.  if ${WARNS} >= 3
39CWARNFLAGS	+=	-W -Wno-unused-parameter -Wstrict-prototypes\
40			-Wmissing-prototypes -Wpointer-arith
41.  endif
42.  if ${WARNS} >= 4
43CWARNFLAGS	+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch\
44			-Wshadow -Wunused-parameter
45.   if !defined(NO_WCAST_ALIGN)
46CWARNFLAGS	+=	-Wcast-align
47.   endif
48.  endif
49# BDECFLAGS
50.  if ${WARNS} >= 6
51CWARNFLAGS	+=	-Wchar-subscripts -Winline -Wnested-externs\
52			-Wredundant-decls -Wold-style-definition
53.  endif
54.  if ${WARNS} >= 2 && ${WARNS} <= 4
55# XXX Delete -Wuninitialized by default for now -- the compiler doesn't
56# XXX always get it right.
57CWARNFLAGS	+=	-Wno-uninitialized
58.  endif
59CWARNFLAGS	+=	-Wno-pointer-sign
60# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
61# is set to low values, these have to be disabled explicitly.
62.  if ${CC:T:Mclang} == "clang"
63.   if ${WARNS} <= 3
64CWARNFLAGS	+=	-Wno-tautological-compare -Wno-unused-value\
65			-Wno-parentheses-equality
66.   endif
67.   if ${WARNS} <= 2
68CWARNFLAGS	+=	-Wno-switch-enum
69.   endif
70.   if ${WARNS} <= 1
71CWARNFLAGS	+=	-Wno-parentheses
72.   endif
73.  endif
74. endif
75
76. if defined(FORMAT_AUDIT)
77WFORMAT		=	1
78. endif
79. if defined(WFORMAT)
80.  if ${WFORMAT} > 0
81#CWARNFLAGS	+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
82CWARNFLAGS	+=	-Wformat=2 -Wno-format-extra-args
83.   if !defined(NO_WERROR)
84CWARNFLAGS	+=	-Werror
85.   endif
86.  endif
87. endif
88. if defined(NO_WFORMAT)
89CWARNFLAGS	+=	-Wno-format
90. endif
91.endif
92
93.if defined(IGNORE_PRAGMA)
94CWARNFLAGS	+=	-Wno-unknown-pragmas
95.endif
96
97.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
98    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
99# Don't use -Wstack-protector as it breaks world with -Werror.
100SSP_CFLAGS	?=	-fstack-protector
101CFLAGS		+=	${SSP_CFLAGS}
102.endif
103
104# Allow user-specified additional warning flags
105CFLAGS		+=	${CWARNFLAGS}
106