1# $FreeBSD: releng/10.3/share/mk/bsd.sys.mk 294974 2016-01-28 08:49:21Z smh $
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.include <bsd.compiler.mk>
12
13# the default is gnu99 for now
14CSTD?=		gnu99
15
16.if ${CSTD} == "k&r"
17CFLAGS+=	-traditional
18.elif ${CSTD} == "c89" || ${CSTD} == "c90"
19CFLAGS+=	-std=iso9899:1990
20.elif ${CSTD} == "c94" || ${CSTD} == "c95"
21CFLAGS+=	-std=iso9899:199409
22.elif ${CSTD} == "c99"
23CFLAGS+=	-std=iso9899:1999
24.else # CSTD
25CFLAGS+=	-std=${CSTD}
26.endif # CSTD
27.if !defined(NO_WARNS)
28# -pedantic is problematic because it also imposes namespace restrictions
29#CFLAGS+=	-pedantic
30.if defined(WARNS)
31.if ${WARNS} >= 1
32CWARNFLAGS+=	-Wsystem-headers
33.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
34    || !defined(NO_WERROR.clang))
35CWARNFLAGS+=	-Werror
36.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
37.endif # WARNS >= 1
38.if ${WARNS} >= 2
39CWARNFLAGS+=	-Wall -Wno-format-y2k
40.endif # WARNS >= 2
41.if ${WARNS} >= 3
42CWARNFLAGS+=	-W -Wno-unused-parameter -Wstrict-prototypes\
43		-Wmissing-prototypes -Wpointer-arith
44.endif # WARNS >= 3
45.if ${WARNS} >= 4
46CWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
47		-Wunused-parameter
48.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \
49    || !defined(NO_WCAST_ALIGN.clang))
50CWARNFLAGS+=	-Wcast-align
51.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
52.endif # WARNS >= 4
53# BDECFLAGS
54.if ${WARNS} >= 6
55CWARNFLAGS+=	-Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
56		-Wold-style-definition
57.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \
58    !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
59CWARNFLAGS+=	-Wmissing-variable-declarations
60.endif
61.endif # WARNS >= 6
62.if ${WARNS} >= 2 && ${WARNS} <= 4
63# XXX Delete -Wuninitialized by default for now -- the compiler doesn't
64# XXX always get it right.
65CWARNFLAGS+=	-Wno-uninitialized
66.endif # WARNS >=2 && WARNS <= 4
67CWARNFLAGS+=	-Wno-pointer-sign
68# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
69# is set to low values, these have to be disabled explicitly.
70.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
71.if ${WARNS} <= 6
72CWARNFLAGS+=	-Wno-empty-body -Wno-string-plus-int
73.if ${COMPILER_VERSION} > 30300
74CWARNFLAGS+=	-Wno-unused-const-variable
75.endif
76.endif # WARNS <= 6
77.if ${WARNS} <= 3
78CWARNFLAGS+=	-Wno-tautological-compare -Wno-unused-value\
79		-Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
80.endif # WARNS <= 3
81.if ${WARNS} <= 2
82CWARNFLAGS+=	-Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
83.endif # WARNS <= 2
84.if ${WARNS} <= 1
85CWARNFLAGS+=	-Wno-parentheses
86.endif # WARNS <= 1
87.if defined(NO_WARRAY_BOUNDS)
88CWARNFLAGS+=	-Wno-array-bounds
89.endif # NO_WARRAY_BOUNDS
90.endif # CLANG
91.endif # WARNS
92
93.if defined(FORMAT_AUDIT)
94WFORMAT=	1
95.endif # FORMAT_AUDIT
96.if defined(WFORMAT)
97.if ${WFORMAT} > 0
98#CWARNFLAGS+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
99CWARNFLAGS+=	-Wformat=2 -Wno-format-extra-args
100.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
101.if ${WARNS} <= 3
102CWARNFLAGS+=	-Wno-format-nonliteral
103.endif # WARNS <= 3
104.endif # CLANG
105.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
106    || !defined(NO_WERROR.clang))
107CWARNFLAGS+=	-Werror
108.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
109.endif # WFORMAT > 0
110.endif # WFORMAT
111.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang))
112CWARNFLAGS+=	-Wno-format
113.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
114.endif # !NO_WARNS
115
116.if defined(IGNORE_PRAGMA)
117CWARNFLAGS+=	-Wno-unknown-pragmas
118.endif # IGNORE_PRAGMA
119
120.if !defined(EARLY_BUILD)
121.if ${COMPILER_TYPE} == "clang"
122CLANG_NO_IAS=	 -no-integrated-as
123CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
124		 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
125CFLAGS+=	 -Qunused-arguments
126.if ${MACHINE_CPUARCH} == "sparc64"
127# Don't emit .cfi directives, since we must use GNU as on sparc64, for now.
128CFLAGS+=	 -fno-dwarf2-cfi-asm
129.endif # SPARC64
130# The libc++ headers use c++11 extensions.  These are normally silenced because
131# they are treated as system headers, but we explicitly disable that warning
132# suppression when building the base system to catch bugs in our headers.
133# Eventually we'll want to start building the base system C++ code as C++11,
134# but not yet.
135CXXFLAGS+=	 -Wno-c++11-extensions
136CFLAGS+=	 ${CFLAGS.clang}
137CXXFLAGS+=	 ${CXXFLAGS.clang}
138.else # !CLANG
139GCC_MS_EXTENSIONS= -fms-extensions
140CFLAGS+=	 ${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		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 regress 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