1155214Srwatson# $FreeBSD: stable/10/share/mk/bsd.sys.mk 313790 2017-02-16 05:14:07Z ngie $
2155214Srwatson#
3155214Srwatson# This file contains common settings used for building FreeBSD
4155214Srwatson# sources.
5155214Srwatson
6155214Srwatson# Enable various levels of compiler warning checks.  These may be
7155214Srwatson# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS.
8155214Srwatson
9155214Srwatson# for GCC:   http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html
10155214Srwatson
11155214Srwatson.include <bsd.compiler.mk>
12155214Srwatson
13155214Srwatson# the default is gnu99 for now
14155214SrwatsonCSTD?=		gnu99
15155214Srwatson
16155214Srwatson.if ${CSTD} == "k&r"
17155214SrwatsonCFLAGS+=	-traditional
18155214Srwatson.elif ${CSTD} == "c89" || ${CSTD} == "c90"
19155214SrwatsonCFLAGS+=	-std=iso9899:1990
20155214Srwatson.elif ${CSTD} == "c94" || ${CSTD} == "c95"
21155214SrwatsonCFLAGS+=	-std=iso9899:199409
22155214Srwatson.elif ${CSTD} == "c99"
23155214SrwatsonCFLAGS+=	-std=iso9899:1999
24155214Srwatson.else # CSTD
25155214SrwatsonCFLAGS+=	-std=${CSTD}
26155214Srwatson.endif # CSTD
27193157Srwatson.if !defined(NO_WARNS)
28206622Suqs# -pedantic is problematic because it also imposes namespace restrictions
29155214Srwatson#CFLAGS+=	-pedantic
30155214Srwatson.if defined(WARNS)
31155214Srwatson.if ${WARNS} >= 1
32155214SrwatsonCWARNFLAGS+=	-Wsystem-headers
33155214Srwatson.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
34155214Srwatson    || !defined(NO_WERROR.clang))
35155214SrwatsonCWARNFLAGS+=	-Werror
36155214Srwatson.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
37155214Srwatson.endif # WARNS >= 1
38155214Srwatson.if ${WARNS} >= 2
39155214SrwatsonCWARNFLAGS+=	-Wall -Wno-format-y2k
40155214Srwatson.endif # WARNS >= 2
41155214Srwatson.if ${WARNS} >= 3
42162871SruCWARNFLAGS+=	-W -Wno-unused-parameter -Wstrict-prototypes\
43162871Sru		-Wmissing-prototypes -Wpointer-arith
44155214Srwatson.endif # WARNS >= 3
45155214Srwatson.if ${WARNS} >= 4
46155214SrwatsonCWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
47155247Sbrueffer		-Wunused-parameter
48155214Srwatson.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \
49155214Srwatson    || !defined(NO_WCAST_ALIGN.clang))
50155214SrwatsonCWARNFLAGS+=	-Wcast-align
51155214Srwatson.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
52155214Srwatson.endif # WARNS >= 4
53155214Srwatson# BDECFLAGS
54162871Sru.if ${WARNS} >= 6
55162871SruCWARNFLAGS+=	-Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
56162871Sru		-Wold-style-definition
57155214Srwatson.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \
58155214Srwatson    !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
59155392SrwatsonCWARNFLAGS+=	-Wmissing-variable-declarations
60162871Sru.endif
61162871Sru.endif # WARNS >= 6
62162871Sru.if ${WARNS} >= 2 && ${WARNS} <= 4
63155392Srwatson# XXX Delete -Wuninitialized by default for now -- the compiler doesn't
64155392Srwatson# XXX always get it right.
65155392SrwatsonCWARNFLAGS+=	-Wno-uninitialized
66162871Sru.endif # WARNS >=2 && WARNS <= 4
67162871SruCWARNFLAGS+=	-Wno-pointer-sign
68162871Sru# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
69155392Srwatson# is set to low values, these have to be disabled explicitly.
70155392Srwatson.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
71155392Srwatson.if ${WARNS} <= 6
72159273SrwatsonCWARNFLAGS+=	-Wno-empty-body -Wno-string-plus-int
73159273Srwatson.if ${COMPILER_VERSION} > 30300
74159273SrwatsonCWARNFLAGS+=	-Wno-unused-const-variable
75165216Smpp.endif
76159273Srwatson.endif # WARNS <= 6
77155214Srwatson.if ${WARNS} <= 3
78155214SrwatsonCWARNFLAGS+=	-Wno-tautological-compare -Wno-unused-value\
79155214Srwatson		-Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
80155214Srwatson.endif # WARNS <= 3
81155214Srwatson.if ${WARNS} <= 2
82155214SrwatsonCWARNFLAGS+=	-Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
83155214Srwatson.endif # WARNS <= 2
84155214Srwatson.if ${WARNS} <= 1
85155392SrwatsonCWARNFLAGS+=	-Wno-parentheses
86155392Srwatson.endif # WARNS <= 1
87155214Srwatson.if defined(NO_WARRAY_BOUNDS)
88155214SrwatsonCWARNFLAGS+=	-Wno-array-bounds
89155214Srwatson.endif # NO_WARRAY_BOUNDS
90159273Srwatson.endif # CLANG
91155214Srwatson.endif # WARNS
92155214Srwatson
93155214Srwatson.if defined(FORMAT_AUDIT)
94162871SruWFORMAT=	1
95155214Srwatson.endif # FORMAT_AUDIT
96155214Srwatson.if defined(WFORMAT)
97155214Srwatson.if ${WFORMAT} > 0
98155214Srwatson#CWARNFLAGS+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
99243752SrwatsonCWARNFLAGS+=	-Wformat=2 -Wno-format-extra-args
100243752Srwatson.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
101162871Sru.if ${WARNS} <= 3
102162871SruCWARNFLAGS+=	-Wno-format-nonliteral
103162871Sru.endif # WARNS <= 3
104162871Sru.endif # CLANG
105162871Sru.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
106162871Sru    || !defined(NO_WERROR.clang))
107162871SruCWARNFLAGS+=	-Werror
108162871Sru.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
109162871Sru.endif # WFORMAT > 0
110162871Sru.endif # WFORMAT
111162871Sru.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang))
112162871SruCWARNFLAGS+=	-Wno-format
113155214Srwatson.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
114162871Sru.endif # !NO_WARNS
115155214Srwatson
116155214Srwatson.if defined(IGNORE_PRAGMA)
117162871SruCWARNFLAGS+=	-Wno-unknown-pragmas
118162871Sru.endif # IGNORE_PRAGMA
119162871Sru
120162871Sru.if !defined(EARLY_BUILD)
121155214Srwatson.if ${COMPILER_TYPE} == "clang"
122155214SrwatsonCLANG_NO_IAS=	 -no-integrated-as
123155214SrwatsonCLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
124155214Srwatson		 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
125155214SrwatsonCFLAGS+=	 -Qunused-arguments
126155214Srwatson.if ${MACHINE_CPUARCH} == "sparc64"
127155214Srwatson# Don't emit .cfi directives, since we must use GNU as on sparc64, for now.
128162871SruCFLAGS+=	 -fno-dwarf2-cfi-asm
129155214Srwatson.endif # SPARC64
130155214Srwatson# The libc++ headers use c++11 extensions.  These are normally silenced because
131155214Srwatson# they are treated as system headers, but we explicitly disable that warning
132155214Srwatson# suppression when building the base system to catch bugs in our headers.
133155214Srwatson# Eventually we'll want to start building the base system C++ code as C++11,
134155214Srwatson# but not yet.
135155214SrwatsonCXXFLAGS+=	 -Wno-c++11-extensions
136155214SrwatsonCFLAGS+=	 ${CFLAGS.clang}
137155214SrwatsonCXXFLAGS+=	 ${CXXFLAGS.clang}
138155214Srwatson.else # !CLANG
139155214SrwatsonGCC_MS_EXTENSIONS= -fms-extensions
140155214SrwatsonCFLAGS+=	 ${CFLAGS.gcc}
141CXXFLAGS+=	 ${CXXFLAGS.gcc}
142.endif # CLANG
143.endif # !EARLY_BUILD
144
145.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
146    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
147# Don't use -Wstack-protector as it breaks world with -Werror.
148SSP_CFLAGS?=	-fstack-protector
149CFLAGS+=	${SSP_CFLAGS}
150.endif # SSP && !IA64 && !ARM && !MIPS
151
152# Allow user-specified additional warning flags and file specific flag
153# overrides.
154CFLAGS+=	${CWARNFLAGS} ${CWARNFLAGS.${.IMPSRC:T}}
155
156
157# Tell bmake not to mistake standard targets for things to be searched for
158# or expect to ever be up-to-date.
159PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
160		beforelinking build build-tools buildfiles buildincludes \
161		check checkdpadd clean cleandepend cleandir cleanobj configure \
162		depend dependall distclean distribute exe extract \
163		html includes install installfiles installincludes lint \
164		obj objlink objs objwarn realall realdepend \
165		realinstall subdir-all subdir-depend subdir-install \
166		tags whereobj
167
168.if defined(PORTNAME)
169PHONY_NOTMAIN+=	fetch patch
170.endif
171
172.PHONY: ${PHONY_NOTMAIN}
173.NOTMAIN: ${PHONY_NOTMAIN}
174