1# RCSid: 2# $Id: warnings.mk,v 1.9 2016/02/20 02:00:58 sjg Exp $ 3# 4# @(#) Copyright (c) 2002, Simon J. Gerraty 5# 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. 12# 13# Please send copies of changes and bug-fixes to: 14# sjg@crufty.net 15# 16 17.ifndef _w_cflags 18# make sure we get the behavior we expect 19.MAKE.SAVE_DOLLARS = no 20 21# Any number of warnings sets can be added. 22.-include "warnings-sets.mk" 23 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. 27MIN_WARNINGS?= -Wall \ 28 -Wformat \ 29 -Wimplicit \ 30 -Wunused \ 31 -Wuninitialized 32 33LOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes 34 35MEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror 36 37HIGH_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 46 47EXTRA_WARNINGS?= ${HIGH_WARNINGS} -Wextra 48 49# The two step default makes it easier to test build with different defaults. 50DEFAULT_WARNINGS_SET?= MIN 51WARNINGS_SET?= ${DEFAULT_WARNINGS_SET} 52 53# If you add sets, besure to list them (you don't have to touch this list). 54ALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH EXTRA 55 56.if !empty(WARNINGS_SET) 57.for ws in ${WARNINGS_SET} 58.if empty(${ws}_WARNINGS) 59.if ${MAKE_VERSION:[1]:C/.*-//} >= 20050530 60.BEGIN: _empty_warnings 61_empty_warnings: .PHONY 62.else 63.BEGIN: 64.endif 65 @echo "ERROR: Invalid: WARNINGS_SET=${ws}" 66 @echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1 67 68.endif 69.endfor 70.endif 71 72# Without -O or if we've set -O0 somewhere - to make debugging more effective, 73# we need to turn off -Wuninitialized as otherwise we get a warning that 74# -Werror turns into an error. To be safe, set W_uninitialized blank. 75_w_cflags:= ${CFLAGS} ${CPPFLAGS} 76.if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != "" 77W_uninitialized= 78.endif 79 80 81# .for loops have the [dis]advantage of being evaluated when read, 82# so adding to WARNINGS_SET[_${MACHINE_ARCH}] after this file is 83# read has no effect. 84# Replacing the above .for loops with the WARNINGS+= below solves that 85# but tiggers a double free bug in bmake-20040118 and earlier. 86# Don't try and read this too fast! 87# 88# The first :@ "loop" handles multiple sets in WARNINGS_SET 89# 90# In the second :@ "loop", the ::?= noise sets W_foo?=-Wfoo etc 91# which makes it easy to turn off override individual flags 92# (see W_uninitialized above). 93# 94# The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}} 95# which is the bit we ultimately want. It allows W_* to be set on a 96# per target basis. 97# 98# NOTE: that we force the target extension to be .o 99# 100 101# define this once, we use it a couple of times below (hence the doubled $$). 102M_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_/}}}}}@ 103 104# first a list of warnings from the chosen set 105_warnings = ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:${M_warnings_list}} 106# now a list of all -Wno-* overrides not just those defined by WARNINGS_SET 107# since things like -Wall imply lots of others. 108# this should be a super-set of the -Wno-* in _warnings, but 109# just in case... 110_no_warnings = ${_warnings:M-Wno-*} ${ALL_WARNINGS_SETS:${M_warnings_list}:M-Wno-*} 111# -Wno-* must follow any others 112WARNINGS += ${_warnings:N-Wno-*} ${_no_warnings:O:u} 113 114.ifndef NO_CFLAGS_WARNINGS 115# Just ${WARNINGS} should do, but this is more flexible? 116CFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}} 117.endif 118 119# it is rather silly that g++ blows up on some warning flags 120NO_CXX_WARNINGS+= \ 121 missing-declarations \ 122 missing-prototypes \ 123 nested-externs \ 124 shadow \ 125 strict-prototypes 126 127.for s in ${SRCS:M*.c*:N*.c:N*h} 128.for w in ${NO_CXX_WARNINGS} 129W_$w_${s:T:R}.o= 130.endfor 131.endfor 132 133.endif # _w_cflags 134