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