bsd.sys.mk revision 262964
139665Smsmith# $FreeBSD: stable/10/share/mk/bsd.sys.mk 262964 2014-03-09 23:47:34Z ache $
239665Smsmith#
339665Smsmith# This file contains common settings used for building FreeBSD
439665Smsmith# sources.
539665Smsmith
639665Smsmith# Enable various levels of compiler warning checks.  These may be
739665Smsmith# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS.
839665Smsmith
939665Smsmith# for GCC:   http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gcc/Warning-Options.html
1039665Smsmith
1139665Smsmith.include <bsd.compiler.mk>
1239665Smsmith
1339665Smsmith# the default is gnu99 for now
1439665SmsmithCSTD?=		gnu99
1539665Smsmith
1639665Smsmith.if ${CSTD} == "k&r"
1739665SmsmithCFLAGS+=	-traditional
1839665Smsmith.elif ${CSTD} == "c89" || ${CSTD} == "c90"
1939665SmsmithCFLAGS+=	-std=iso9899:1990
2039665Smsmith.elif ${CSTD} == "c94" || ${CSTD} == "c95"
2139665SmsmithCFLAGS+=	-std=iso9899:199409
2239665Smsmith.elif ${CSTD} == "c99"
2339665SmsmithCFLAGS+=	-std=iso9899:1999
2439665Smsmith.else # CSTD
2539665SmsmithCFLAGS+=	-std=${CSTD}
2639665Smsmith.endif # CSTD
2784221Sdillon.if !defined(NO_WARNS)
2884221Sdillon# -pedantic is problematic because it also imposes namespace restrictions
2984221Sdillon#CFLAGS+=	-pedantic
3039665Smsmith.if defined(WARNS)
3139665Smsmith.if ${WARNS} >= 1
3239665SmsmithCWARNFLAGS+=	-Wsystem-headers
3339665Smsmith.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
3439665Smsmith    || !defined(NO_WERROR.clang))
3539665SmsmithCWARNFLAGS+=	-Werror
3639665Smsmith.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
3739665Smsmith.endif # WARNS >= 1
3839665Smsmith.if ${WARNS} >= 2
3939665SmsmithCWARNFLAGS+=	-Wall -Wno-format-y2k
4039665Smsmith.endif # WARNS >= 2
4139665Smsmith.if ${WARNS} >= 3
4239665SmsmithCWARNFLAGS+=	-W -Wno-unused-parameter -Wstrict-prototypes\
4360481Speter		-Wmissing-prototypes -Wpointer-arith
4460481Speter.endif # WARNS >= 3
4560481Speter.if ${WARNS} >= 4
4639665SmsmithCWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
4739665Smsmith		-Wunused-parameter
4839665Smsmith.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \
4939665Smsmith    || !defined(NO_WCAST_ALIGN.clang))
5039665SmsmithCWARNFLAGS+=	-Wcast-align
5139665Smsmith.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
5239665Smsmith.endif # WARNS >= 4
5339665Smsmith# BDECFLAGS
5439665Smsmith.if ${WARNS} >= 6
5539665SmsmithCWARNFLAGS+=	-Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
5639665Smsmith		-Wold-style-definition
5739665Smsmith.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \
5839665Smsmith    !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
5939665SmsmithCWARNFLAGS+=	-Wmissing-variable-declarations
6039665Smsmith.endif
6139665Smsmith.endif # WARNS >= 6
6239665Smsmith.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.endif # WARNS <= 6
74.if ${WARNS} <= 3
75CWARNFLAGS+=	-Wno-tautological-compare -Wno-unused-value\
76		-Wno-parentheses-equality -Wno-unused-function -Wno-enum-conversion
77.endif # WARNS <= 3
78.if ${WARNS} <= 2
79CWARNFLAGS+=	-Wno-switch -Wno-switch-enum -Wno-knr-promoted-parameter
80.endif # WARNS <= 2
81.if ${WARNS} <= 1
82CWARNFLAGS+=	-Wno-parentheses
83.endif # WARNS <= 1
84.if defined(NO_WARRAY_BOUNDS)
85CWARNFLAGS+=	-Wno-array-bounds
86.endif # NO_WARRAY_BOUNDS
87.endif # CLANG
88.endif # WARNS
89
90.if defined(FORMAT_AUDIT)
91WFORMAT=	1
92.endif # FORMAT_AUDIT
93.if defined(WFORMAT)
94.if ${WFORMAT} > 0
95#CWARNFLAGS+=	-Wformat-nonliteral -Wformat-security -Wno-format-extra-args
96CWARNFLAGS+=	-Wformat=2 -Wno-format-extra-args
97.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
98.if ${WARNS} <= 3
99CWARNFLAGS+=	-Wno-format-nonliteral
100.endif # WARNS <= 3
101.endif # CLANG
102.if !defined(NO_WERROR) && (${COMPILER_TYPE} != "clang" \
103    || !defined(NO_WERROR.clang))
104CWARNFLAGS+=	-Werror
105.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
106.endif # WFORMAT > 0
107.endif # WFORMAT
108.if defined(NO_WFORMAT) || (${COMPILER_TYPE} == "clang" && defined(NO_WFORMAT.clang))
109CWARNFLAGS+=	-Wno-format
110.endif # NO_WFORMAT || (CLANG && NO_WFORMAT.clang)
111.endif # !NO_WARNS
112
113.if defined(IGNORE_PRAGMA)
114CWARNFLAGS+=	-Wno-unknown-pragmas
115.endif # IGNORE_PRAGMA
116
117.if !defined(EARLY_BUILD)
118.if ${COMPILER_TYPE} == "clang"
119CLANG_NO_IAS=	 -no-integrated-as
120CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
121		 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
122CFLAGS+=	 -Qunused-arguments
123# The libc++ headers use c++11 extensions.  These are normally silenced because
124# they are treated as system headers, but we explicitly disable that warning
125# suppression when building the base system to catch bugs in our headers.
126# Eventually we'll want to start building the base system C++ code as C++11,
127# but not yet.
128CXXFLAGS+=	 -Wno-c++11-extensions
129CFLAGS+=	 ${CFLAGS.clang}
130CXXFLAGS+=	 ${CXXFLAGS.clang}
131.else # !CLANG
132GCC_MS_EXTENSIONS= -fms-extensions
133CFLAGS+=	 ${CFLAGS.gcc}
134CXXFLAGS+=	 ${CXXFLAGS.gcc}
135.endif # CLANG
136.endif # !EARLY_BUILD
137
138.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
139    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
140# Don't use -Wstack-protector as it breaks world with -Werror.
141SSP_CFLAGS?=	-fstack-protector
142CFLAGS+=	${SSP_CFLAGS}
143.endif # SSP && !IA64 && !ARM && !MIPS
144
145# Allow user-specified additional warning flags
146CFLAGS+=	${CWARNFLAGS}
147
148
149# Tell bmake not to mistake standard targets for things to be searched for
150# or expect to ever be up-to-date.
151PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
152		beforelinking build build-tools buildfiles buildincludes \
153		checkdpadd clean cleandepend cleandir cleanobj configure \
154		depend dependall distclean distribute exe extract \
155		html includes install installfiles installincludes lint \
156		obj objlink objs objwarn realall realdepend \
157		realinstall regress subdir-all subdir-depend subdir-install \
158		tags whereobj
159
160.if defined(PORTNAME)
161PHONY_NOTMAIN+=	fetch patch
162.endif
163
164.PHONY: ${PHONY_NOTMAIN}
165.NOTMAIN: ${PHONY_NOTMAIN}
166