2 # $Id: warnings.mk,v 1.8 2014/04/02 19:20:23 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
13 # Please send copies of changes and bug-fixes to:
19 # Any number of warnings sets can be added.
20 .-include "warnings-sets.mk"
22 # Modest defaults - put more elaborate sets in warnings-sets.mk
23 # -Wunused etc are here so you can set
24 # W_unused=-Wno-unused etc.
25 MIN_WARNINGS?= -Wall \
31 LOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes
33 MEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror
35 HIGH_WARNINGS?= ${MEDIUM_WARNINGS} \
40 -Wmissing-declarations \
45 EXTRA_WARNINGS?= ${HIGH_WARNINGS} -Wextra
47 # The two step default makes it easier to test build with different defaults.
48 DEFAULT_WARNINGS_SET?= MIN
49 WARNINGS_SET?= ${DEFAULT_WARNINGS_SET}
51 # If you add sets, besure to list them (you don't have to touch this list).
52 ALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH EXTRA
54 .if !empty(WARNINGS_SET)
55 .for ws in ${WARNINGS_SET}
56 .if empty(${ws}_WARNINGS)
57 .if ${MAKE_VERSION:[1]:C/.*-//} >= 20050530
58 .BEGIN: _empty_warnings
59 _empty_warnings: .PHONY
63 @echo "ERROR: Invalid: WARNINGS_SET=${ws}"
64 @echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1
70 # Without -O or if we've set -O0 somewhere - to make debugging more effective,
71 # we need to turn off -Wuninitialized as otherwise we get a warning that
72 # -Werror turns into an error. To be safe, set W_uninitialized blank.
73 _w_cflags:= ${CFLAGS} ${CPPFLAGS}
74 .if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != ""
79 # .for loops have the [dis]advantage of being evaluated when read,
80 # so adding to WARNINGS_SET[_${MACHINE_ARCH}] after this file is
82 # Replacing the above .for loops with the WARNINGS+= below solves that
83 # but tiggers a double free bug in bmake-20040118 and earlier.
84 # Don't try and read this too fast!
86 # The first :@ "loop" handles multiple sets in WARNINGS_SET
88 # In the second :@ "loop", the ::?= noise sets W_foo?=-Wfoo etc
89 # which makes it easy to turn off override individual flags
90 # (see W_uninitialized above).
92 # The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}}
93 # which is the bit we ultimately want. It allows W_* to be set on a
96 # NOTE: that we force the target extension to be .o
99 # define this once, we use it a couple of times below (hence the doubled $$).
100 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_/}}}}}@
102 # first a list of warnings from the chosen set
103 _warnings = ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:${M_warnings_list}}
104 # now a list of all -Wno-* overrides not just those defined by WARNINGS_SET
105 # since things like -Wall imply lots of others.
106 # this should be a super-set of the -Wno-* in _warnings, but
108 _no_warnings = ${_warnings:M-Wno-*} ${ALL_WARNINGS_SETS:${M_warnings_list}:M-Wno-*}
109 # -Wno-* must follow any others
110 WARNINGS += ${_warnings:N-Wno-*} ${_no_warnings:O:u}
112 .ifndef NO_CFLAGS_WARNINGS
113 # Just ${WARNINGS} should do, but this is more flexible?
114 CFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}}
117 # it is rather silly that g++ blows up on some warning flags
119 missing-declarations \
125 .for s in ${SRCS:M*.c*:N*.c:N*h}
126 .for w in ${NO_CXX_WARNINGS}