xref: /dragonfly/share/mk/bsd.sys.mk (revision efbafed1)
1# $FreeBSD: src/share/mk/bsd.sys.mk,v 1.3.2.5 2002/07/03 16:59:14 des Exp $
2#
3# This file contains common settings used for building DragonFly
4# sources.
5
6# Support handling -W flags for both host cc and target cc.
7.if defined(__USE_HOST_CCVER)
8_WCCVER=	${HOST_CCVER}
9.else
10_WCCVER=	${CCVER}
11.endif
12
13CSTD?=	gnu11
14
15.if ${CSTD} == "k&r"
16CFLAGS		+= -traditional
17.elif ${CSTD} == "c89" || ${CSTD} == "c90"
18CFLAGS		+= -std=iso9899:1990
19.elif ${CSTD} == "c94" || ${CSTD} == "c95"
20CFLAGS		+= -std=iso9899:199409
21.elif ${CSTD} == "c99"
22CFLAGS		+= -std=iso9899:1999
23.else
24CFLAGS		+= -std=${CSTD}
25.endif
26
27# Explicitly clear _cnowarnflags (should not be used in Makefiles).
28_cnowarnflags=
29
30# Enable various levels of compiler warning checks.  These may be
31# overridden (e.g. if using a non-gcc compiler) by defining NO_WARNS.
32
33.if !defined(NO_WARNS)
34. if defined(WARNS)
35.  if ${WARNS} >= 1
36CWARNFLAGS	+=	-Wmissing-include-dirs -Wsystem-headers
37.   if !defined(NO_WERROR) && (${_WCCVER} == "gcc47" || ${_WCCVER} == "gcc80")
38CWARNFLAGS	+=	-Werror
39.   endif
40.  endif
41.  if ${WARNS} >= 2
42CWARNFLAGS	+=	-Wall -Wformat-security -Winit-self
43.  endif
44.  if ${WARNS} >= 3
45CWARNFLAGS	+=	-Wextra -Wstrict-prototypes\
46			-Wmissing-prototypes -Wpointer-arith\
47			-Wold-style-definition
48.  endif
49.  if ${WARNS} >= 4
50CWARNFLAGS	+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch\
51			-Wshadow -Wcast-align -Wunused-parameter
52.  endif
53.  if ${WARNS} >= 6
54CWARNFLAGS	+=	-Wchar-subscripts -Winline -Wnested-externs\
55			-Wredundant-decls
56.  endif
57.  if ${WARNS} >= 2 && ${WARNS} <= 6
58# Delete -Wno-pointer-sign from -Wall by default (C only).
59_cnowarnflags	+=	-Wno-pointer-sign
60.  endif
61.  if ${WARNS} >= 2 && ${WARNS} <= 4
62# XXX Delete -Wmaybe-uninitialized by default for now -- the compiler doesn't
63# XXX always get it right.
64.   if ${_WCCVER:Mgcc*}
65_cnowarnflags	+=	-Wno-maybe-uninitialized
66.   else
67_cnowarnflags	+=	-Wno-uninitialized
68.   endif
69.  endif
70.  if ${WARNS} == 3
71# Delete -Wno-unused-parameter from -Wextra by default only if WARNS < 4.
72_cnowarnflags	+=	-Wno-unused-parameter
73.  endif
74# Delete -Wformat-* family that give little benefits, same for stringop.
75.  if ${WARNS} >= 2 && ${WARNS} <= 6 && ${_WCCVER:Mgcc8*}
76_cnowarnflags	+=	-Wno-format-overflow -Wno-format-truncation
77_cnowarnflags	+=	-Wno-stringop-truncation
78.  endif
79.  if ${WARNS} >= 1 && ${WARNS} <= 6 && ${_WCCVER:Mgcc8*}
80_cnowarnflags	+=	-Wno-stringop-overflow
81.  endif
82# Activate gcc47's -Wunused-but-set-variable (which is in -Wall) and
83# -Wunused-but-set-parameter (which is in -Wextra) only at WARNS >= 4
84# (which is the level when also -Wunused-parameter comes into play).
85.  if ${WARNS} >= 2 && ${WARNS} <= 3 && ${_WCCVER:Mgcc*}
86_cnowarnflags	+=	-Wno-unused-but-set-variable
87.  endif
88.  if ${WARNS} == 3 && ${_WCCVER:Mgcc*}
89_cnowarnflags	+=	-Wno-unused-but-set-parameter
90.  endif
91.  if ${WARNS} == 3 && (${_WCCVER:Mgcc49} || ${_WCCVER:Mgcc[5-]*})
92_cnowarnflags	+=	-Wno-unused-value
93.  endif
94.  if ${WARNS} == 3 && ${_WCCVER:Mgcc8*}
95_cnowarnflags	+=	-Wno-implicit-fallthrough
96.  endif
97.  if ${WARNS} >= 2 && ${_WCCVER:Mgcc4[789]}
98_cnowarnflags	+=	-Wno-error=maybe-uninitialized\
99			-Wno-error=uninitialized\
100			-Wno-error=shadow
101.  endif
102.  if ${WARNS} >= 3 && ${_WCCVER:Mgcc4[789]}
103_cnowarnflags	+=	-Wno-error=missing-field-initializers
104.  endif
105# Disable -Werror selectively for -Os and -Og compilations.  Both -Winline and
106# -Wmaybe-uninitialized are noisy and should be caught by standard -O and -O2.
107# These are still useful diagnostics while investigating compilation issues.
108.  if defined(WORLD_CCOPTLEVEL) && (${WORLD_CCOPTLEVEL:Mg} || ${WORLD_CCOPTLEVEL:Ms})
109.   if ${WARNS} >= 6
110CWARNFLAGS	+=	-Wno-error=inline
111.   endif
112.   if ${WARNS} >= 5 && ${_WCCVER:Mgcc*}
113CWARNFLAGS	+=	-Wno-error=maybe-uninitialized
114.   endif
115.  endif
116. endif
117
118. if defined(FORMAT_AUDIT)
119WFORMAT		=	1
120. endif
121. if defined(WFORMAT)
122.  if ${WFORMAT} > 0
123CWARNFLAGS	+=	-Wformat=2
124.   if !defined(NO_WERROR) && (${_WCCVER} == "gcc47" || ${_WCCVER} == "gcc80")
125CWARNFLAGS	+=	-Werror
126.   endif
127.  endif
128. endif
129.endif
130
131# Build world with -fno-common. This will be default with GCC 10.
132#
133.if ${_WCCVER:Ngcc1[0-9][0-9]}
134CFLAGS		+=	-fno-common
135.endif
136
137.if defined(NO_WCAST_FUNCTION_TYPE) && ${WARNS} >= 3 && ${_WCCVER:Mgcc8*}
138_cnowarnflags	+=      -Wno-cast-function-type
139.endif
140.if defined(NO_WARRAY_BOUNDS)
141_cnowarnflags	+=      -Wno-array-bounds
142.endif
143.if defined(NO_STRICT_OVERFLOW)
144CFLAGS		+=	-fno-strict-overflow
145.endif
146.if defined(NO_STRICT_ALIASING)
147CFLAGS		+=      -fno-strict-aliasing
148.endif
149
150
151# Add -Wno-foo flags last
152.if !defined(WARNS_AUDIT)
153CWARNFLAGS	+=	${_cnowarnflags}
154.endif
155
156# Allow user-specified additional warning flags
157CFLAGS		+=	${CWARNFLAGS}
158
159# Tell bmake not to mistake standard targets for things to be searched for
160# or expect to ever be up-to-date
161PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
162	beforelinking build build-tools buildfiles buildincludes \
163	checkdpadd clean cleandepend cleandir cleanobj configure \
164	depend dependall distclean distribute exe extract fetch \
165	html includes install installfiles installincludes lint \
166	obj objlink objs objwarn patch realall realdepend \
167	realinstall regress subdir-all subdir-depend subdir-install \
168	tags whereobj
169
170# if given PROG matches anything in the PHONY list, exclude it.
171.PHONY: ${PHONY_NOTMAIN:N${PROG:U}}
172.NOTMAIN: ${PHONY_NOTMAIN}
173