xref: /freebsd/share/mk/bsd.sys.mk (revision 4fd0d10e0fe684211328bc148edf89a792425b39)
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) && (${COMPILER_TYPE} != "clang" \
34    || !defined(NO_WERROR.clang))
35CWARNFLAGS+=	-Werror
36.endif # !NO_WERROR && (!CLANG || !NO_WERROR.clang)
37.endif # WARNS >= 1
38.if ${WARNS} >= 2
39CWARNFLAGS+=	-Wall -Wno-format-y2k
40.endif # WARNS >= 2
41.if ${WARNS} >= 3
42CWARNFLAGS+=	-W -Wno-unused-parameter -Wstrict-prototypes\
43		-Wmissing-prototypes -Wpointer-arith
44.endif # WARNS >= 3
45.if ${WARNS} >= 4
46CWARNFLAGS+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow\
47		-Wunused-parameter
48.if !defined(NO_WCAST_ALIGN) && (${COMPILER_TYPE} != "clang" \
49    || !defined(NO_WCAST_ALIGN.clang))
50CWARNFLAGS+=	-Wcast-align
51.endif # !NO_WCAST_ALIGN && (!CLANG || !NO_WCAST_ALIGN.clang)
52.endif # WARNS >= 4
53# BDECFLAGS
54.if ${WARNS} >= 6
55CWARNFLAGS+=	-Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls\
56		-Wold-style-definition
57.if ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD) && \
58    !defined(NO_WMISSING_VARIABLE_DECLARATIONS)
59CWARNFLAGS+=	-Wmissing-variable-declarations
60.endif
61.endif # WARNS >= 6
62.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-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 ${COMPILER_TYPE} == "clang" && !defined(EARLY_BUILD)
118CLANG_NO_IAS=	 -no-integrated-as
119CLANG_OPT_SMALL= -mstack-alignment=8 -mllvm -inline-threshold=3\
120		 -mllvm -enable-load-pre=false -mllvm -simplifycfg-dup-ret
121CFLAGS+=	 -Qunused-arguments
122.endif # CLANG
123
124.if ${MK_SSP} != "no" && ${MACHINE_CPUARCH} != "ia64" && \
125    ${MACHINE_CPUARCH} != "arm" && ${MACHINE_CPUARCH} != "mips"
126# Don't use -Wstack-protector as it breaks world with -Werror.
127SSP_CFLAGS?=	-fstack-protector
128CFLAGS+=	${SSP_CFLAGS}
129.endif # SSP && !IA64 && !ARM && !MIPS
130
131# Allow user-specified additional warning flags
132CFLAGS+=	${CWARNFLAGS}
133
134
135# Tell bmake not to mistake standard targets for things to be searched for
136# or expect to ever be up-to-date.
137PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
138		beforelinking build build-tools buildfiles buildincludes \
139		checkdpadd clean cleandepend cleandir cleanobj configure \
140		depend dependall distclean distribute exe extract fetch \
141		html includes install installfiles installincludes lint \
142		obj objlink objs objwarn patch realall realdepend \
143		realinstall regress subdir-all subdir-depend subdir-install \
144		tags whereobj
145
146.if defined(.PARSEDIR)
147# we don't want ${PROG} to be PHONY
148.PHONY: ${PHONY_NOTMAIN:N${PROG:U}}
149.else
150.PHONY: ${PHONY_NOTMAIN}
151.endif
152.NOTMAIN: ${PHONY_NOTMAIN}
153
154.if !defined(.PARSEDIR)
155# this is a no-op
156.WAIT:
157.endif
158
159.if ${MK_STAGING} != "no"
160.if defined(_SKIP_BUILD) || (!make(all) && !make(clean*))
161_SKIP_STAGING?= yes
162.endif
163.if ${_SKIP_STAGING:Uno} == "yes"
164staging stage_libs stage_files stage_as stage_links stage_symlinks:
165.else
166# allow targets like beforeinstall to be leveraged
167DESTDIR= ${STAGE_OBJTOP}
168
169.if commands(beforeinstall)
170.if !empty(_LIBS) || ${MK_STAGING_PROG} != "no"
171staging: beforeinstall
172.endif
173.endif
174
175# normally only libs and includes are staged
176.if ${MK_STAGING_PROG} != "no"
177STAGE_DIR.prog= ${STAGE_OBJTOP}${BINDIR}
178
179.if !empty(PROG) || !empty(PROGS)
180.if defined(PROGNAME)
181STAGE_AS_SETS+= prog
182STAGE_AS_${PROG}= ${PROGNAME}
183stage_as.prog: ${PROG}
184.else
185STAGE_SETS+= prog
186stage_files.prog: ${PROG}
187staging: stage_files
188.endif
189.endif
190.endif
191
192.if !empty(_LIBS) && !defined(INTERNALLIB)
193stage_libs: ${_LIBS}
194.if defined(SHLIB_NAME) && defined(DEBUG_FLAGS) && target(${SHLIB_NAME}.symbols)
195stage_libs: ${SHLIB_NAME}.symbols
196.endif
197.endif
198
199.if !empty(INCS) || !empty(INCSGROUPS) && target(buildincludes)
200beforebuild: buildincludes
201.endif
202
203.for t in stage_libs stage_files stage_as
204.if target($t)
205staging: $t
206.endif
207.endfor
208
209.if !empty(STAGE_AS_SETS)
210staging: stage_as
211.endif
212
213.if !empty(_LIBS) || ${MK_STAGING_PROG} != "no"
214
215.if !empty(LINKS)
216staging: stage_links
217.if ${MAKE_VERSION} < 20131001
218stage_links.links: ${_LIBS} ${PROG}
219.endif
220STAGE_SETS+= links
221STAGE_LINKS.links= ${LINKS}
222.endif
223
224.if !empty(SYMLINKS)
225staging: stage_symlinks
226STAGE_SETS+= links
227STAGE_SYMLINKS.links= ${SYMLINKS}
228.endif
229
230.endif
231
232.include <meta.stage.mk>
233.endif
234.endif
235
236