getconf: don't include xpg4 bits, gcc7 includes xpg6 bits for us
[unleashed.git] / share / mk / warnings.mk
blob7fb3ebd4a8f893fea05e7f4803e12eeac7373cee
1 # RCSid:
2 # $Id: warnings.mk,v 1.14 2016/04/05 15:58:37 sjg Exp $
4 # @(#) Copyright (c) 2002, Simon J. Gerraty
6 # This file is provided in the hope that it will
7 # be of use. There is absolutely NO WARRANTY.
8 # Permission to copy, redistribute or otherwise
9 # use this file is hereby granted provided that
10 # the above copyright notice and this notice are
11 # left intact.
13 # Please send copies of changes and bug-fixes to:
14 # sjg@crufty.net
17 .ifndef _w_cflags
18 # make sure we get the behavior we expect
19 .MAKE.SAVE_DOLLARS = no
21 # Any number of warnings sets can be added.
22 .-include <warnings-sets.mk>
24 # Modest defaults - put more elaborate sets in warnings-sets.mk
25 # -Wunused etc are here so you can set
26 # W_unused=-Wno-unused etc.
27 MIN_WARNINGS?= -Wall \
28 -Wformat \
29 -Wimplicit \
30 -Wunused \
31 -Wuninitialized
33 LOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes
35 MEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror
37 HIGH_WARNINGS?= ${MEDIUM_WARNINGS} \
38 -Wcast-align \
39 -Wcast-qual \
40 -Wparentheses \
41 -Wpointer-arith \
42 -Wmissing-declarations \
43 -Wreturn-type \
44 -Wswitch \
45 -Wwrite-strings
47 EXTRA_WARNINGS?= ${HIGH_WARNINGS} -Wextra
49 # The two step default makes it easier to test build with different defaults.
50 DEFAULT_WARNINGS_SET?= MIN
51 WARNINGS_SET?= ${DEFAULT_WARNINGS_SET}
53 # There is always someone who wants more...
54 .if !empty(WARNINGS_XTRAS)
55 ${WARNINGS_SET}_WARNINGS += ${WARNINGS_XTRAS}
56 .endif
58 # If you add sets, besure to list them (you don't have to touch this list).
59 ALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH EXTRA
61 .if !empty(WARNINGS_SET)
62 .for ws in ${WARNINGS_SET}
63 .if empty(${ws}_WARNINGS)
64 .if ${MAKE_VERSION:[1]:C/.*-//} >= 20050530
65 .BEGIN: _empty_warnings
66 _empty_warnings: .PHONY
67 .else
68 .BEGIN:
69 .endif
70 @echo "ERROR: Invalid: WARNINGS_SET=${ws}"
71 @echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1
73 .endif
74 .endfor
75 .endif
77 # Without -O or if we've set -O0 somewhere - to make debugging more effective,
78 # we need to turn off -Wuninitialized as otherwise we get a warning that
79 # -Werror turns into an error. To be safe, set W_uninitialized blank.
80 _w_cflags= ${CFLAGS} ${CFLAGS_LAST} ${CPPFLAGS}
81 .if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != ""
82 W_uninitialized=
83 .endif
86 # .for loops have the [dis]advantage of being evaluated when read,
87 # so adding to WARNINGS_SET[_${MACHINE_ARCH}] after this file is
88 # read has no effect.
89 # Replacing the above .for loops with the WARNINGS+= below solves that
90 # but tiggers a double free bug in bmake-20040118 and earlier.
91 # Don't try and read this too fast!
93 # The first :@ "loop" handles multiple sets in WARNINGS_SET
95 # In the second :@ "loop", the ::?= noise sets W_foo?=-Wfoo etc
96 # which makes it easy to turn off override individual flags
97 # (see W_uninitialized above).
99 # The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}}
100 # which is the bit we ultimately want. It allows W_* to be set on a
101 # per target basis.
103 # NOTE: that we force the target extension to be .o
106 # define this once, we use it a couple of times below (hence the doubled $$).
107 M_warnings_list = @s@$${$$s_WARNINGS}@:O:u:@w@$${$${w:C/-(.)/\1_/}::?=$$w} $${$${w:C/-(.)/\1_/}_${MACHINE_ARCH}_${.TARGET:T:R}.o:U$${$${w:C/-(.)/\1_/}_${.TARGET:T:R}.o:U$${$${w:C/-(.)/\1_/}_${MACHINE_ARCH}:U$${$${w:C/-(.)/\1_/}}}}}@
109 # first a list of warnings from the chosen set
110 _warnings = ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:${M_warnings_list}}
111 # now a list of all -Wno-* overrides not just those defined by WARNINGS_SET
112 # since things like -Wall imply lots of others.
113 # this should be a super-set of the -Wno-* in _warnings, but
114 # just in case...
115 _no_warnings = ${_warnings:M-Wno-*} ${ALL_WARNINGS_SETS:${M_warnings_list}:M-Wno-*}
116 # -Wno-* must follow any others
117 WARNINGS += ${_warnings:N-Wno-*} ${_no_warnings:O:u}
119 .ifndef NO_CFLAGS_WARNINGS
120 # Just ${WARNINGS} should do, but this is more flexible?
121 CFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}}
122 .endif
124 # it is rather silly that g++ blows up on some warning flags
125 NO_CXX_WARNINGS+= \
126 implicit \
127 missing-declarations \
128 missing-prototypes \
129 nested-externs \
130 shadow \
131 strict-prototypes
133 .for s in ${SRCS:M*.c*:N*.c:N*h}
134 .for w in ${NO_CXX_WARNINGS}
135 W_$w_${s:T:R}.o=
136 .endfor
137 .endfor
139 .endif # _w_cflags