bsd.sys.mk revision 260495
1164190Sjkoshy# $FreeBSD: stable/10/share/mk/bsd.sys.mk 260495 2014-01-09 22:40:51Z dim $
2164190Sjkoshy#
3164190Sjkoshy# This file contains common settings used for building FreeBSD
4164190Sjkoshy# sources.
5164190Sjkoshy
6164190Sjkoshy# Enable various levels of compiler warning checks.  These may be
7164190Sjkoshy# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS.
8164190Sjkoshy
9164190Sjkoshy# for GCC:   http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html
10164190Sjkoshy
11164190Sjkoshy.include <bsd.compiler.mk>
12164190Sjkoshy
13164190Sjkoshy# the default is gnu99 for now
14164190SjkoshyCSTD?=		gnu99
15164190Sjkoshy
16164190Sjkoshy.if ${CSTD} == "k&r"
17164190SjkoshyCFLAGS+=	-traditional
18164190Sjkoshy.elif ${CSTD} == "c89" || ${CSTD} == "c90"
19164190SjkoshyCFLAGS+=	-std=iso9899:1990
20164190Sjkoshy.elif ${CSTD} == "c94" || ${CSTD} == "c95"
21164190SjkoshyCFLAGS+=	-std=iso9899:199409
22164190Sjkoshy.elif ${CSTD} == "c99"
23164190SjkoshyCFLAGS+=	-std=iso9899:1999
24164190Sjkoshy.else # CSTD
25164190SjkoshyCFLAGS+=	-std=${CSTD}
26164190Sjkoshy.endif # CSTD
27206622Suqs.if !defined(NO_WARNS)
28164190Sjkoshy# -pedantic is problematic because it also imposes namespace restrictions
29164190Sjkoshy#CFLAGS+=	-pedantic
30164190Sjkoshy.if defined(WARNS)
31164190Sjkoshy.if ${WARNS} >= 1
32164190SjkoshyCWARNFLAGS+=	-Wsystem-headers
33164190Sjkoshy.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
34164190Sjkoshy    || !defined(NO_WERROR.clang))
35164190SjkoshyCWARNFLAGS+=	-Werror
36164190Sjkoshy.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
37164190Sjkoshy.endif # WARNS >= 1
38164190Sjkoshy.if ${WARNS} >= 2
39164190SjkoshyCWARNFLAGS+=	-Wall -Wno-format-y2k
40164190Sjkoshy.endif # WARNS >= 2
41164190Sjkoshy.if ${WARNS} >= 3
42164190SjkoshyCWARNFLAGS+=	-W -Wno-unused-parameter -Wstrict-prototypes\
43164190Sjkoshy		-Wmissing-prototypes -Wpointer-arith
44164190Sjkoshy.endif # WARNS >= 3
45164190Sjkoshy.if ${WARNS} >= 4
46164190SjkoshyCWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
47164190Sjkoshy		-Wunused-parameter
48164190Sjkoshy.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \
49164190Sjkoshy    || !defined(NO_WCAST_ALIGN.clang))
50164190SjkoshyCWARNFLAGS+=	-Wcast-align
51164190Sjkoshy.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
52164190Sjkoshy.endif # WARNS >= 4
53164190Sjkoshy# BDECFLAGS
54164190Sjkoshy.if ${WARNS} >= 6
55164190SjkoshyCWARNFLAGS+=	-Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
56164190Sjkoshy		-Wold-style-definition
57164190Sjkoshy.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \
58164190Sjkoshy    !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
59164190SjkoshyCWARNFLAGS+=	-Wmissing-variable-declarations
60164190Sjkoshy.endif
61164190Sjkoshy.endif # WARNS >= 6
62164190Sjkoshy.if ${WARNS} >= 2 && ${WARNS} <= 4
63164190Sjkoshy# XXX Delete -Wuninitialized by default for now -- the compiler doesn't
64164190Sjkoshy# XXX always get it right.
65164190SjkoshyCWARNFLAGS+=	-Wno-uninitialized
66164190Sjkoshy.endif # WARNS >=2 && WARNS <= 4
67164190SjkoshyCWARNFLAGS+=	-Wno-pointer-sign
68164190Sjkoshy# Clang has more warnings enabled by default, and when using -Wall, so if WARNS
69164190Sjkoshy# is set to low values, these have to be disabled explicitly.
70164190Sjkoshy.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
71164190Sjkoshy.if ${WARNS} <= 6
72164190SjkoshyCWARNFLAGS+=	-Wno-empty-body -Wno-string-plus-int
73164190Sjkoshy.endif # WARNS <= 6
74164190Sjkoshy.if ${WARNS} <= 3
75164190SjkoshyCWARNFLAGS+=	-Wno-tautological-compare -Wno-unused-value\
76164190Sjkoshy		-Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
77164190Sjkoshy.endif # WARNS <= 3
78164190Sjkoshy.if ${WARNS} <= 2
79164190SjkoshyCWARNFLAGS+=	-Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
80164190Sjkoshy.endif # WARNS <= 2
81164190Sjkoshy.if ${WARNS} <= 1
82164190SjkoshyCWARNFLAGS+=	-Wno-parentheses
83164190Sjkoshy.endif # WARNS <= 1
84164190Sjkoshy.if defined(NO_WARRAY_BOUNDS)
85164190SjkoshyCWARNFLAGS+=	-Wno-array-bounds
86164190Sjkoshy.endif # NO_WARRAY_BOUNDS
87164190Sjkoshy.endif # CLANG
88164190Sjkoshy.endif # WARNS
89164190Sjkoshy
90164190Sjkoshy.if defined(FORMAT_AUDIT)
91164190SjkoshyWFORMAT=	1
92164190Sjkoshy.endif # FORMAT_AUDIT
93164190Sjkoshy.if defined(WFORMAT)
94164190Sjkoshy.if ${WFORMAT} > 0
95164190Sjkoshy#CWARNFLAGS+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
96164190SjkoshyCWARNFLAGS+=	-Wformat=2 -Wno-format-extra-args
97164190Sjkoshy.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
98164190Sjkoshy.if ${WARNS} <= 3
99164190SjkoshyCWARNFLAGS+=	-Wno-format-nonliteral
100164190Sjkoshy.endif # WARNS <= 3
101164190Sjkoshy.endif # CLANG
102164190Sjkoshy.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
103164190Sjkoshy    || !defined(NO_WERROR.clang))
104164190SjkoshyCWARNFLAGS+=	-Werror
105164190Sjkoshy.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
106164190Sjkoshy.endif # WFORMAT > 0
107164190Sjkoshy.endif # WFORMAT
108164190Sjkoshy.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang))
109164190SjkoshyCWARNFLAGS+=	-Wno-format
110164190Sjkoshy.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
111164190Sjkoshy.endif # !NO_WARNS
112164190Sjkoshy
113164190Sjkoshy.if defined(IGNORE_PRAGMA)
114164190SjkoshyCWARNFLAGS+=	-Wno-unknown-pragmas
115164190Sjkoshy.endif # IGNORE_PRAGMA
116164190Sjkoshy
117164190Sjkoshy.if !defined(EARLY_BUILD)
118164190Sjkoshy.if ${COMPILER_TYPE} == "clang"
119164190SjkoshyCLANG_NO_IAS=	 -no-integrated-as
120164190SjkoshyCLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
121164190Sjkoshy		 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
122CFLAGS+=	 -Qunused-arguments
123CFLAGS+=	 ${CFLAGS.clang}
124CXXFLAGS+=	 ${CXXFLAGS.clang}
125.else # !CLANG
126GCC_MS_EXTENSIONS= -fms-extensions
127CFLAGS+=	 ${CFLAGS.gcc}
128CXXFLAGS+=	 ${CXXFLAGS.gcc}
129.endif # CLANG
130.endif # !EARLY_BUILD
131
132.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
133    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
134# Don't use -Wstack-protector as it breaks world with -Werror.
135SSP_CFLAGS?=	-fstack-protector
136CFLAGS+=	${SSP_CFLAGS}
137.endif # SSP && !IA64 && !ARM && !MIPS
138
139# Allow user-specified additional warning flags
140CFLAGS+=	${CWARNFLAGS}
141
142
143# Tell bmake not to mistake standard targets for things to be searched for
144# or expect to ever be up-to-date.
145PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
146		beforelinking build build-tools buildfiles buildincludes \
147		checkdpadd clean cleandepend cleandir cleanobj configure \
148		depend dependall distclean distribute exe extract fetch \
149		html includes install installfiles installincludes lint \
150		obj objlink objs objwarn patch realall realdepend \
151		realinstall regress subdir-all subdir-depend subdir-install \
152		tags whereobj
153
154.PHONY: ${PHONY_NOTMAIN}
155.NOTMAIN: ${PHONY_NOTMAIN}
156