xref: /dragonfly/share/mk/bsd.sys.mk (revision dccc281f)
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?=	gnu99
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} == "gcc50")
38CWARNFLAGS	+=	-Werror
39.   endif
40.  endif
41.  if ${WARNS} >= 2
42CWARNFLAGS	+=	-Wall -Wformat-security -Winit-self
43_cnowarnflags	+=	-Wno-pointer-sign
44.  endif
45.  if ${WARNS} >= 3
46CWARNFLAGS	+=	-Wextra -Wstrict-prototypes\
47			-Wmissing-prototypes -Wpointer-arith\
48			-Wold-style-definition
49_cnowarnflags	+=	-Wno-unused-parameter
50.  endif
51.  if ${WARNS} >= 4
52CWARNFLAGS	+=	-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch\
53			-Wshadow -Wcast-align -Wunused-parameter
54.  endif
55.  if ${WARNS} >= 6
56CWARNFLAGS	+=	-Wchar-subscripts -Winline -Wnested-externs\
57			-Wredundant-decls
58.  endif
59.  if ${WARNS} >= 2 && ${WARNS} <= 4
60# XXX Delete -Wmaybe-uninitialized by default for now -- the compiler doesn't
61# XXX always get it right.
62.   if ${_WCCVER:Mgcc*}
63_cnowarnflags	+=	-Wno-maybe-uninitialized
64.   else
65_cnowarnflags	+=	-Wno-uninitialized
66.   endif
67.  endif
68# Activate gcc47's -Wunused-but-set-variable (which is in -Wall) and
69# -Wunused-but-set-parameter (which is in -Wextra) only at WARNS >= 4
70# (which is the level when also -Wunused-parameter comes into play).
71.  if ${WARNS} >= 2 && ${WARNS} <= 3 && ${_WCCVER:Mgcc*}
72_cnowarnflags	+=	-Wno-unused-but-set-variable
73.  endif
74.  if ${WARNS} == 3 && ${_WCCVER:Mgcc*}
75_cnowarnflags	+=	-Wno-unused-but-set-parameter
76.  endif
77.  if ${WARNS} == 3 && (${_WCCVER:Mgcc49} || ${_WCCVER:Mgcc[5-]*})
78_cnowarnflags	+=	-Wno-unused-value
79.  endif
80.  if ${WARNS} >= 2 && ${_WCCVER:Mgcc4[789]}
81_cnowarnflags	+=	-Wno-error=maybe-uninitialized\
82			-Wno-error=uninitialized\
83			-Wno-error=shadow
84.  endif
85# Disable -Werror selectively for -Os and -Og compilations.  Both -Winline and
86# -Wmaybe-uninitialized are noisy and should be caught by standard -O and -O2.
87# These are still useful diagnostics while investigating compilation issues.
88.  if defined(WORLD_CCOPTLEVEL) && (${WORLD_CCOPTLEVEL:Mg} || ${WORLD_CCOPTLEVEL:Ms})
89.   if ${WARNS} >= 6
90CWARNFLAGS	+=	-Wno-error=inline
91.   endif
92.   if ${WARNS} >= 5 && ${_WCCVER:Mgcc*}
93CWARNFLAGS	+=	-Wno-error=maybe-uninitialized
94.   endif
95.  endif
96. endif
97
98. if defined(FORMAT_AUDIT)
99WFORMAT		=	1
100. endif
101. if defined(WFORMAT)
102.  if ${WFORMAT} > 0
103CWARNFLAGS	+=	-Wformat=2
104.   if !defined(NO_WERROR) && (${_WCCVER} == "gcc47" || ${_WCCVER} == "gcc50")
105CWARNFLAGS	+=	-Werror
106.   endif
107.  endif
108. endif
109.endif
110
111.if defined(NO_WCAST_FUNCTION_TYPE) && ${WARNS} >= 3 && ${_WCCVER:Mgcc8*}
112_cnowarnflags	+=      -Wno-cast-function-type
113.endif
114.if defined(NO_WARRAY_BOUNDS)
115_cnowarnflags	+=      -Wno-array-bounds
116.endif
117.if defined(NO_STRICT_OVERFLOW)
118CFLAGS		+=	-fno-strict-overflow
119.endif
120.if defined(NO_STRICT_ALIASING)
121CFLAGS		+=      -fno-strict-aliasing
122.endif
123
124
125# Add -Wno-foo flags last
126.if !defined(WARNS_AUDIT)
127CWARNFLAGS	+=	${_cnowarnflags}
128.endif
129
130# Allow user-specified additional warning flags
131CFLAGS		+=	${CWARNFLAGS}
132
133# Tell bmake not to mistake standard targets for things to be searched for
134# or expect to ever be up-to-date
135PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
136	beforelinking build build-tools buildfiles buildincludes \
137	checkdpadd clean cleandepend cleandir cleanobj configure \
138	depend dependall distclean distribute exe extract fetch \
139	html includes install installfiles installincludes lint \
140	obj objlink objs objwarn patch realall realdepend \
141	realinstall regress subdir-all subdir-depend subdir-install \
142	tags whereobj
143
144# if given PROG matches anything in the PHONY list, exclude it.
145.PHONY: ${PHONY_NOTMAIN:N${PROG:U}}
146.NOTMAIN: ${PHONY_NOTMAIN}
147