xref: /freebsd/share/mk/bsd.sys.mk (revision 3b8f08459569bf0faa21473e5cec2491e95c9349)
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.if defined(.PARSEDIR)
162# we don't want ${PROG} to be PHONY
163.PHONY: ${PHONY_NOTMAIN:N${PROG:U}}
164.else
165.PHONY: ${PHONY_NOTMAIN}
166.endif
167.NOTMAIN: ${PHONY_NOTMAIN}
168
169.if !defined(.PARSEDIR)
170# this is a no-op
171.WAIT:
172.endif
173
174.if ${MK_STAGING} != "no"
175.if defined(_SKIP_BUILD) || (!make(all) && !make(clean*))
176_SKIP_STAGING?= yes
177.endif
178.if ${_SKIP_STAGING:Uno} == "yes"
179staging stage_libs stage_files stage_as stage_links stage_symlinks:
180.else
181# allow targets like beforeinstall to be leveraged
182DESTDIR= ${STAGE_OBJTOP}
183
184.if commands(beforeinstall)
185.if !empty(_LIBS) || ${MK_STAGING_PROG} != "no"
186staging: beforeinstall
187.endif
188.endif
189
190# normally only libs and includes are staged
191.if ${MK_STAGING_PROG} != "no"
192STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR}
193
194.if !empty(PROG) || !empty(PROGS)
195.if defined(PROGNAME)
196STAGE_AS_SETS+= prog
197STAGE_AS_${PROG}= ${PROGNAME}
198stage_as.prog: ${PROG}
199.else
200STAGE_SETS+= prog
201stage_files.prog: ${PROG}
202staging: stage_files
203.endif
204.endif
205.endif
206
207.if !empty(_LIBS) && !defined(INTERNALLIB)
208stage_libs: ${_LIBS}
209.if defined(SHLIB_NAME) && defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
210stage_libs: ${SHLIB_NAME}.symbols
211.endif
212.endif
213
214.if !empty(INCS) || !empty(INCSGROUPS) && target(buildincludes)
215beforebuild: buildincludes
216.endif
217
218.for t in stage_libs stage_files stage_as
219.if target($t)
220staging: $t
221.endif
222.endfor
223
224.if !empty(STAGE_AS_SETS)
225staging: stage_as
226.endif
227
228.if !empty(_LIBS) || ${MK_STAGING_PROG} != "no"
229
230.if !empty(LINKS)
231staging: stage_links
232.if ${MAKE_VERSION} < 20131001
233stage_links.links: ${_LIBS} ${PROG}
234.endif
235STAGE_SETS+= links
236STAGE_LINKS.links= ${LINKS}
237.endif
238
239.if !empty(SYMLINKS)
240staging: stage_symlinks
241STAGE_SETS+= links
242STAGE_SYMLINKS.links= ${SYMLINKS}
243.endif
244
245.endif
246
247.include <meta.stage.mk>
248.endif
249.endif
250
251