warnings.mk revision 296637
164880Sphk# RCSid: 264880Sphk# $Id: warnings.mk,v 1.9 2016/02/20 02:00:58 sjg Exp $ 364880Sphk# 464880Sphk# @(#) Copyright (c) 2002, Simon J. Gerraty 564880Sphk# 664880Sphk# This file is provided in the hope that it will 764880Sphk# be of use. There is absolutely NO WARRANTY. 864880Sphk# Permission to copy, redistribute or otherwise 964880Sphk# use this file is hereby granted provided that 1064880Sphk# the above copyright notice and this notice are 1164880Sphk# left intact. 1264880Sphk# 1364880Sphk# Please send copies of changes and bug-fixes to: 1464880Sphk# sjg@crufty.net 1564880Sphk# 1664880Sphk 1764880Sphk.ifndef _w_cflags 1864880Sphk# make sure we get the behavior we expect 1964880Sphk.MAKE.SAVE_DOLLARS = no 2064880Sphk 2164880Sphk# Any number of warnings sets can be added. 2264880Sphk.-include "warnings-sets.mk" 2364880Sphk 2464880Sphk# Modest defaults - put more elaborate sets in warnings-sets.mk 2564880Sphk# -Wunused etc are here so you can set 2664880Sphk# W_unused=-Wno-unused etc. 2764880SphkMIN_WARNINGS?= -Wall \ 2864880Sphk -Wformat \ 2964880Sphk -Wimplicit \ 3064880Sphk -Wunused \ 3164880Sphk -Wuninitialized 3264880Sphk 3364880SphkLOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes 3464880Sphk 3564880SphkMEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror 3664880Sphk 3764880SphkHIGH_WARNINGS?= ${MEDIUM_WARNINGS} \ 3864880Sphk -Wcast-align \ 3964880Sphk -Wcast-qual \ 4064880Sphk -Wparentheses \ 4164880Sphk -Wpointer-arith \ 4264880Sphk -Wmissing-declarations \ 4364880Sphk -Wreturn-type \ 4464880Sphk -Wswitch \ 4565132Sphk -Wwrite-strings 4665132Sphk 4765132SphkEXTRA_WARNINGS?= ${HIGH_WARNINGS} -Wextra 4865132Sphk 4965132Sphk# The two step default makes it easier to test build with different defaults. 5065132SphkDEFAULT_WARNINGS_SET?= MIN 5165132SphkWARNINGS_SET?= ${DEFAULT_WARNINGS_SET} 5265132Sphk 5365132Sphk# If you add sets, besure to list them (you don't have to touch this list). 5465132SphkALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH EXTRA 5565132Sphk 5665132Sphk.if !empty(WARNINGS_SET) 5765132Sphk.for ws in ${WARNINGS_SET} 5865132Sphk.if empty(${ws}_WARNINGS) 5965132Sphk.if ${MAKE_VERSION:[1]:C/.*-//} >= 20050530 6064880Sphk.BEGIN: _empty_warnings 6164880Sphk_empty_warnings: .PHONY 6264880Sphk.else 6364880Sphk.BEGIN: 6464880Sphk.endif 6564880Sphk @echo "ERROR: Invalid: WARNINGS_SET=${ws}" 6664880Sphk @echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1 6764880Sphk 6864880Sphk.endif 6964880Sphk.endfor 7064880Sphk.endif 7164880Sphk 7264880Sphk# Without -O or if we've set -O0 somewhere - to make debugging more effective, 7364880Sphk# we need to turn off -Wuninitialized as otherwise we get a warning that 7464880Sphk# -Werror turns into an error. To be safe, set W_uninitialized blank. 7565051Sphk_w_cflags:= ${CFLAGS} ${CPPFLAGS} 7665051Sphk.if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != "" 7764880SphkW_uninitialized= 7864880Sphk.endif 7964880Sphk 8065051Sphk 8165051Sphk# .for loops have the [dis]advantage of being evaluated when read, 8264880Sphk# so adding to WARNINGS_SET[_${MACHINE_ARCH}] after this file is 8365051Sphk# read has no effect. 8464880Sphk# Replacing the above .for loops with the WARNINGS+= below solves that 8564880Sphk# but tiggers a double free bug in bmake-20040118 and earlier. 8665051Sphk# Don't try and read this too fast! 8764880Sphk# 8865051Sphk# The first :@ "loop" handles multiple sets in WARNINGS_SET 8965051Sphk# 9065051Sphk# In the second :@ "loop", the ::?= noise sets W_foo?=-Wfoo etc 9165051Sphk# which makes it easy to turn off override individual flags 9265051Sphk# (see W_uninitialized above). 9365051Sphk# 9465051Sphk# The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}} 9564880Sphk# which is the bit we ultimately want. It allows W_* to be set on a 9664880Sphk# per target basis. 9765051Sphk# 9865051Sphk# NOTE: that we force the target extension to be .o 9965051Sphk# 10065051Sphk 10165051Sphk# define this once, we use it a couple of times below (hence the doubled $$). 10265051SphkM_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_/}}}}}@ 10365051Sphk 10465051Sphk# first a list of warnings from the chosen set 10565051Sphk_warnings = ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:${M_warnings_list}} 10665051Sphk# now a list of all -Wno-* overrides not just those defined by WARNINGS_SET 10765051Sphk# since things like -Wall imply lots of others. 10865051Sphk# this should be a super-set of the -Wno-* in _warnings, but 10965051Sphk# just in case... 11064880Sphk_no_warnings = ${_warnings:M-Wno-*} ${ALL_WARNINGS_SETS:${M_warnings_list}:M-Wno-*} 11164880Sphk# -Wno-* must follow any others 11264880SphkWARNINGS += ${_warnings:N-Wno-*} ${_no_warnings:O:u} 11365051Sphk 11465051Sphk.ifndef NO_CFLAGS_WARNINGS 11564880Sphk# Just ${WARNINGS} should do, but this is more flexible? 11664880SphkCFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}} 11764880Sphk.endif 11864880Sphk 11964880Sphk# it is rather silly that g++ blows up on some warning flags 12064880SphkNO_CXX_WARNINGS+= \ 12164880Sphk missing-declarations \ 12264880Sphk missing-prototypes \ 12364880Sphk nested-externs \ 12464880Sphk shadow \ 12565051Sphk strict-prototypes 12664880Sphk 12764880Sphk.for s in ${SRCS:M*.c*:N*.c:N*h} 12864880Sphk.for w in ${NO_CXX_WARNINGS} 12964880SphkW_$w_${s:T:R}.o= 13065051Sphk.endfor 13164880Sphk.endfor 13264880Sphk 13364880Sphk.endif # _w_cflags 13464880Sphk