xref: /freebsd/share/mk/bsd.sys.mk (revision 991554f2c46fdbc7e9acbf87fc8da089618c3a19)
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.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) && !defined(NO_WERROR.${COMPILER_TYPE})
34CWARNFLAGS+=	-Werror
35.endif # !NO_WERROR && !NO_WERROR.${COMPILER_TYPE}
36.endif # WARNS >= 1
37.if ${WARNS} >= 2
38CWARNFLAGS+=	-Wall -Wno-format-y2k
39.endif # WARNS >= 2
40.if ${WARNS} >= 3
41CWARNFLAGS+=	-W -Wno-unused-parameter -Wstrict-prototypes\
42		-Wmissing-prototypes -Wpointer-arith
43.endif # WARNS >= 3
44.if ${WARNS} >= 4
45CWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
46		-Wunused-parameter
47.if !defined(NO_WCAST_ALIGN) && !defined(NO_WCAST_ALIGN.${COMPILER_TYPE})
48CWARNFLAGS+=	-Wcast-align
49.endif # !NO_WCAST_ALIGN !NO_WCAST_ALIGN.${COMPILER_TYPE}
50.endif # WARNS >= 4
51# BDECFLAGS
52.if ${WARNS} >= 6
53CWARNFLAGS+=	-Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
54		-Wold-style-definition
55.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \
56    !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
57CWARNFLAGS+=	-Wmissing-variable-declarations
58.endif
59.endif # WARNS >= 6
60.if ${WARNS} >= 2 && ${WARNS} <= 4
61# XXX Delete -Wuninitialized by default for now -- the compiler doesn't
62# XXX always get it right.
63CWARNFLAGS+=	-Wno-uninitialized
64.endif # WARNS >=2 && WARNS <= 4
65CWARNFLAGS+=	-Wno-pointer-sign
66# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
67# is set to low values, these have to be disabled explicitly.
68.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
69.if ${WARNS} <= 6
70CWARNFLAGS+=	-Wno-empty-body -Wno-string-plus-int -Wno-unused-const-variable
71.endif # WARNS <= 6
72.if ${WARNS} <= 3
73CWARNFLAGS+=	-Wno-tautological-compare -Wno-unused-value\
74		-Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
75.endif # WARNS <= 3
76.if ${WARNS} <= 2
77CWARNFLAGS+=	-Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
78.endif # WARNS <= 2
79.if ${WARNS} <= 1
80CWARNFLAGS+=	-Wno-parentheses
81.endif # WARNS <= 1
82.if defined(NO_WARRAY_BOUNDS)
83CWARNFLAGS+=	-Wno-array-bounds
84.endif # NO_WARRAY_BOUNDS
85.endif # CLANG
86.endif # WARNS
87
88.if defined(FORMAT_AUDIT)
89WFORMAT=	1
90.endif # FORMAT_AUDIT
91.if defined(WFORMAT)
92.if ${WFORMAT} > 0
93#CWARNFLAGS+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
94CWARNFLAGS+=	-Wformat=2 -Wno-format-extra-args
95.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
96.if ${WARNS} <= 3
97CWARNFLAGS+=	-Wno-format-nonliteral
98.endif # WARNS <= 3
99.endif # CLANG
100.if !defined(NO_WERROR) && !defined(NO_WERROR.${COMPILER_TYPE})
101CWARNFLAGS+=	-Werror
102.endif # !NO_WERROR && !NO_WERROR.${COMPILER_TYPE}
103.endif # WFORMAT > 0
104.endif # WFORMAT
105.if defined(NO_WFORMAT) || defined(NO_WFORMAT.${COMPILER_TYPE})
106CWARNFLAGS+=	-Wno-format
107.endif # NO_WFORMAT || NO_WFORMAT.${COMPILER_TYPE}
108.endif # !NO_WARNS
109
110.if defined(IGNORE_PRAGMA)
111CWARNFLAGS+=	-Wno-unknown-pragmas
112.endif # IGNORE_PRAGMA
113
114.if !defined(EARLY_BUILD)
115.if ${COMPILER_TYPE} == "clang"
116CLANG_NO_IAS=	 -no-integrated-as
117CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
118		 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
119CFLAGS+=	 -Qunused-arguments
120.if ${MACHINE_CPUARCH} == "sparc64"
121# Don't emit .cfi directives, since we must use GNU as on sparc64, for now.
122CFLAGS+=	 -fno-dwarf2-cfi-asm
123.endif # SPARC64
124# The libc++ headers use c++11 extensions.  These are normally silenced because
125# they are treated as system headers, but we explicitly disable that warning
126# suppression when building the base system to catch bugs in our headers.
127# Eventually we'll want to start building the base system C++ code as C++11,
128# but not yet.
129CXXFLAGS+=	 -Wno-c++11-extensions
130.endif # CLANG
131CFLAGS+=	 ${CFLAGS.${COMPILER_TYPE}}
132CXXFLAGS+=	 ${CXXFLAGS.${COMPILER_TYPE}}
133.endif # !EARLY_BUILD
134
135.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
136    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
137# Don't use -Wstack-protector as it breaks world with -Werror.
138SSP_CFLAGS?=	-fstack-protector
139CFLAGS+=	${SSP_CFLAGS}
140.endif # SSP && !IA64 && !ARM && !MIPS
141
142# Allow user-specified additional warning flags
143CFLAGS+=	${CWARNFLAGS}
144
145
146# Tell bmake not to mistake standard targets for things to be searched for
147# or expect to ever be up-to-date.
148PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
149		beforelinking build build-tools buildfiles buildincludes \
150		checkdpadd clean cleandepend cleandir cleanobj configure \
151		depend dependall distclean distribute exe extract \
152		html includes install installfiles installincludes lint \
153		obj objlink objs objwarn realall realdepend \
154		realinstall regress subdir-all subdir-depend subdir-install \
155		tags whereobj
156
157.if defined(PORTNAME)
158PHONY_NOTMAIN+=	fetch patch
159.endif
160
161.PHONY: ${PHONY_NOTMAIN}
162.NOTMAIN: ${PHONY_NOTMAIN}
163