xref: /freebsd/share/mk/bsd.sys.mk (revision 3ef51c5fb9163f2aafb1c14729e06a8bf0c4d113)
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-4.2.1/gcc/Warning-Options.html
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 # CSTD
23CFLAGS+=	-std=${CSTD}
24.endif # CSTD
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) && ((${MK_CLANG_IS_CC} == "no" && \
32    ${CC:T:Mclang} != "clang") || !defined(NO_WERROR.clang))
33CWARNFLAGS+=	-Werror
34.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
35.endif # WARNS >= 1
36.if ${WARNS} >= 2
37CWARNFLAGS+=	-Wall -Wno-format-y2k
38.endif # WARNS >= 2
39.if ${WARNS} >= 3
40CWARNFLAGS+=	-W -Wno-unused-parameter -Wstrict-prototypes\
41		-Wmissing-prototypes -Wpointer-arith
42.endif # WARNS >= 3
43.if ${WARNS} >= 4
44CWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
45		-Wunused-parameter
46.if !defined(NO_WCAST_ALIGN) && ((${MK_CLANG_IS_CC} == "no" && \
47    ${CC:T:Mclang} != "clang") || !defined(NO_WCAST_ALIGN.clang))
48CWARNFLAGS+=	-Wcast-align
49.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
50.endif # WARNS >= 4
51# BDECFLAGS
52.if ${WARNS} >= 6
53CWARNFLAGS+=	-Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
54		-Wold-style-definition
55.endif # WARNS >= 6
56.if ${WARNS} >= 2 && ${WARNS} <= 4
57# XXX Delete -Wuninitialized by default for now -- the compiler doesn't
58# XXX always get it right.
59CWARNFLAGS+=	-Wno-uninitialized
60.endif # WARNS >=2 && WARNS <= 4
61CWARNFLAGS+=	-Wno-pointer-sign
62# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
63# is set to low values, these have to be disabled explicitly.
64.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang"
65.if ${WARNS} <= 3
66CWARNFLAGS+=	-Wno-tautological-compare -Wno-unused-value\
67		-Wno-parentheses-equality -Wno-unused-function -Wno-conversion
68.endif # WARNS <= 3
69.if ${WARNS} <= 2
70CWARNFLAGS+=	-Wno-switch-enum -Wno-empty-body
71.endif # WARNS <= 2
72.if ${WARNS} <= 1
73CWARNFLAGS+=	-Wno-parentheses
74.endif # WARNS <= 1
75.if defined(NO_WARRAY_BOUNDS)
76CWARNFLAGS+=	-Wno-array-bounds
77.endif # NO_WARRAY_BOUNDS
78.endif # CLANG
79.endif # WARNS
80
81.if defined(FORMAT_AUDIT)
82WFORMAT=	1
83.endif # FORMAT_AUDIT
84.if defined(WFORMAT)
85.if ${WFORMAT} > 0
86#CWARNFLAGS+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
87CWARNFLAGS+=	-Wformat=2 -Wno-format-extra-args
88.if !defined(NO_WERROR) && ((${MK_CLANG_IS_CC} == "no" && \
89    ${CC:T:Mclang} != "clang") || !defined(NO_WERROR.clang))
90CWARNFLAGS+=	-Werror
91.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
92.endif # WFORMAT > 0
93.endif # WFORMAT
94.if defined(NO_WFORMAT) || ((${MK_CLANG_IS_CC} != "no" || \
95    ${CC:T:Mclang} == "clang") && defined(NO_WFORMAT.clang))
96CWARNFLAGS+=	-Wno-format
97.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
98.endif # !NO_WARNS
99
100.if defined(IGNORE_PRAGMA)
101CWARNFLAGS+=	-Wno-unknown-pragmas
102.endif # IGNORE_PRAGMA
103
104.if ${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang"
105CLANG_NO_IAS=	 -no-integrated-as
106CLANG_OPT_SMALL= -mllvm -stack-alignment=8 -mllvm -inline-threshold=3\
107		 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
108.endif # CLANG
109
110.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
111    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
112# Don't use -Wstack-protector as it breaks world with -Werror.
113SSP_CFLAGS?=	-fstack-protector
114CFLAGS+=	${SSP_CFLAGS}
115.endif # SSP && !IA64 && !ARM && !MIPS
116
117# Allow user-specified additional warning flags
118CFLAGS+=	${CWARNFLAGS}
119