xref: /dflybsd-src/contrib/bmake/mk/warnings.mk (revision a34d5fb143d34c0e1d2580296c500e2c8a5bc5dc)
15f1e34d9SAlexandre Perrin# RCSid:
2*a34d5fb1SAntonio Huete Jimenez#	$Id: warnings.mk,v 1.15 2020/08/19 17:51:53 sjg Exp $
35f1e34d9SAlexandre Perrin#
45f1e34d9SAlexandre Perrin#	@(#) Copyright (c) 2002, Simon J. Gerraty
55f1e34d9SAlexandre Perrin#
65f1e34d9SAlexandre Perrin#	This file is provided in the hope that it will
75f1e34d9SAlexandre Perrin#	be of use.  There is absolutely NO WARRANTY.
85f1e34d9SAlexandre Perrin#	Permission to copy, redistribute or otherwise
95f1e34d9SAlexandre Perrin#	use this file is hereby granted provided that
105f1e34d9SAlexandre Perrin#	the above copyright notice and this notice are
115f1e34d9SAlexandre Perrin#	left intact.
125f1e34d9SAlexandre Perrin#
135f1e34d9SAlexandre Perrin#	Please send copies of changes and bug-fixes to:
145f1e34d9SAlexandre Perrin#	sjg@crufty.net
155f1e34d9SAlexandre Perrin#
165f1e34d9SAlexandre Perrin
175f1e34d9SAlexandre Perrin.ifndef _w_cflags
18f445c897SJohn Marino# make sure we get the behavior we expect
19f445c897SJohn Marino.MAKE.SAVE_DOLLARS = no
205f1e34d9SAlexandre Perrin
215f1e34d9SAlexandre Perrin# Any number of warnings sets can be added.
22f445c897SJohn Marino.-include <warnings-sets.mk>
235f1e34d9SAlexandre Perrin
245f1e34d9SAlexandre Perrin# Modest defaults - put more elaborate sets in warnings-sets.mk
255f1e34d9SAlexandre Perrin# -Wunused  etc are here so you can set
265f1e34d9SAlexandre Perrin# W_unused=-Wno-unused etc.
275f1e34d9SAlexandre PerrinMIN_WARNINGS?= -Wall \
285f1e34d9SAlexandre Perrin	-Wformat \
295f1e34d9SAlexandre Perrin	-Wimplicit \
305f1e34d9SAlexandre Perrin	-Wunused \
315f1e34d9SAlexandre Perrin	-Wuninitialized
325f1e34d9SAlexandre Perrin
335f1e34d9SAlexandre PerrinLOW_WARNINGS?= ${MIN_WARNINGS} -W -Wstrict-prototypes -Wmissing-prototypes
345f1e34d9SAlexandre Perrin
355f1e34d9SAlexandre PerrinMEDIUM_WARNINGS?= ${LOW_WARNINGS} -Werror
365f1e34d9SAlexandre Perrin
375f1e34d9SAlexandre PerrinHIGH_WARNINGS?= ${MEDIUM_WARNINGS} \
385f1e34d9SAlexandre Perrin	-Wcast-align \
395f1e34d9SAlexandre Perrin	-Wcast-qual \
405f1e34d9SAlexandre Perrin	-Wparentheses \
415f1e34d9SAlexandre Perrin	-Wpointer-arith \
425f1e34d9SAlexandre Perrin	-Wmissing-declarations \
435f1e34d9SAlexandre Perrin	-Wreturn-type \
445f1e34d9SAlexandre Perrin	-Wswitch \
455f1e34d9SAlexandre Perrin	-Wwrite-strings
465f1e34d9SAlexandre Perrin
476a91b982SJohn MarinoEXTRA_WARNINGS?= ${HIGH_WARNINGS} -Wextra
486a91b982SJohn Marino
495f1e34d9SAlexandre Perrin# The two step default makes it easier to test build with different defaults.
505f1e34d9SAlexandre PerrinDEFAULT_WARNINGS_SET?= MIN
515f1e34d9SAlexandre PerrinWARNINGS_SET?= ${DEFAULT_WARNINGS_SET}
525f1e34d9SAlexandre Perrin
53f445c897SJohn Marino# There is always someone who wants more...
54f445c897SJohn Marino.if !empty(WARNINGS_XTRAS)
55f445c897SJohn Marino${WARNINGS_SET}_WARNINGS += ${WARNINGS_XTRAS}
56f445c897SJohn Marino.endif
57f445c897SJohn Marino
585f1e34d9SAlexandre Perrin# If you add sets, besure to list them (you don't have to touch this list).
596a91b982SJohn MarinoALL_WARNINGS_SETS+= MIN LOW MEDIUM HIGH EXTRA
605f1e34d9SAlexandre Perrin
616a91b982SJohn Marino.if !empty(WARNINGS_SET)
626a91b982SJohn Marino.for ws in ${WARNINGS_SET}
636a91b982SJohn Marino.if empty(${ws}_WARNINGS)
646a91b982SJohn Marino.if ${MAKE_VERSION:[1]:C/.*-//} >= 20050530
655f1e34d9SAlexandre Perrin.BEGIN:	_empty_warnings
665f1e34d9SAlexandre Perrin_empty_warnings: .PHONY
675f1e34d9SAlexandre Perrin.else
685f1e34d9SAlexandre Perrin.BEGIN:
695f1e34d9SAlexandre Perrin.endif
706a91b982SJohn Marino	@echo "ERROR: Invalid: WARNINGS_SET=${ws}"
715f1e34d9SAlexandre Perrin	@echo "ERROR: Try one of: ${ALL_WARNINGS_SETS:O:u}"; exit 1
725f1e34d9SAlexandre Perrin
735f1e34d9SAlexandre Perrin.endif
746a91b982SJohn Marino.endfor
756a91b982SJohn Marino.endif
765f1e34d9SAlexandre Perrin
775f1e34d9SAlexandre Perrin# Without -O or if we've set -O0 somewhere - to make debugging more effective,
785f1e34d9SAlexandre Perrin# we need to turn off -Wuninitialized as otherwise we get a warning that
795f1e34d9SAlexandre Perrin# -Werror turns into an error.  To be safe, set W_uninitialized blank.
80f445c897SJohn Marino_w_cflags= ${CFLAGS} ${CFLAGS_LAST} ${CPPFLAGS}
815f1e34d9SAlexandre Perrin.if ${_w_cflags:M-O*} == "" || ${_w_cflags:M-O0} != ""
825f1e34d9SAlexandre PerrinW_uninitialized=
835f1e34d9SAlexandre Perrin.endif
845f1e34d9SAlexandre Perrin
855f1e34d9SAlexandre Perrin
865f1e34d9SAlexandre Perrin# .for loops have the [dis]advantage of being evaluated when read,
875f1e34d9SAlexandre Perrin# so adding to WARNINGS_SET[_${MACHINE_ARCH}] after this file is
885f1e34d9SAlexandre Perrin# read has no effect.
895f1e34d9SAlexandre Perrin# Replacing the above .for loops with the WARNINGS+= below solves that
905f1e34d9SAlexandre Perrin# but tiggers a double free bug in bmake-20040118 and earlier.
915f1e34d9SAlexandre Perrin# Don't try and read this too fast!
925f1e34d9SAlexandre Perrin#
935f1e34d9SAlexandre Perrin# The first :@ "loop" handles multiple sets in WARNINGS_SET
945f1e34d9SAlexandre Perrin#
955f1e34d9SAlexandre Perrin# In the second :@ "loop", the ::?= noise sets W_foo?=-Wfoo etc
965f1e34d9SAlexandre Perrin# which makes it easy to turn off override individual flags
975f1e34d9SAlexandre Perrin# (see W_uninitialized above).
985f1e34d9SAlexandre Perrin#
995f1e34d9SAlexandre Perrin# The last bit expands to ${W_foo_${.TARGET:T}:U${W_foo}}
1005f1e34d9SAlexandre Perrin# which is the bit we ultimately want.  It allows W_* to be set on a
1015f1e34d9SAlexandre Perrin# per target basis.
1025f1e34d9SAlexandre Perrin#
1035f1e34d9SAlexandre Perrin# NOTE: that we force the target extension to be .o
1045f1e34d9SAlexandre Perrin#
1055f1e34d9SAlexandre Perrin
1066a91b982SJohn Marino# define this once, we use it a couple of times below (hence the doubled $$).
1076a91b982SJohn MarinoM_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_/}}}}}@
1086a91b982SJohn Marino
1096a91b982SJohn Marino# first a list of warnings from the chosen set
1106a91b982SJohn Marino_warnings = ${WARNINGS_SET_${MACHINE_ARCH}:U${WARNINGS_SET}:${M_warnings_list}}
1116a91b982SJohn Marino# now a list of all -Wno-* overrides not just those defined by WARNINGS_SET
1126a91b982SJohn Marino# since things like -Wall imply lots of others.
1136a91b982SJohn Marino# this should be a super-set of the -Wno-* in _warnings, but
1146a91b982SJohn Marino# just in case...
1156a91b982SJohn Marino_no_warnings = ${_warnings:M-Wno-*} ${ALL_WARNINGS_SETS:${M_warnings_list}:M-Wno-*}
1166a91b982SJohn Marino# -Wno-* must follow any others
1176a91b982SJohn MarinoWARNINGS += ${_warnings:N-Wno-*} ${_no_warnings:O:u}
1185f1e34d9SAlexandre Perrin
1195f1e34d9SAlexandre Perrin.ifndef NO_CFLAGS_WARNINGS
1205f1e34d9SAlexandre Perrin# Just ${WARNINGS} should do, but this is more flexible?
1215f1e34d9SAlexandre PerrinCFLAGS+= ${WARNINGS_${.TARGET:T:R}.o:U${WARNINGS}}
1225f1e34d9SAlexandre Perrin.endif
1235f1e34d9SAlexandre Perrin
1245f1e34d9SAlexandre Perrin# it is rather silly that g++ blows up on some warning flags
1255f1e34d9SAlexandre PerrinNO_CXX_WARNINGS+= \
126f445c897SJohn Marino	implicit \
1275f1e34d9SAlexandre Perrin	missing-declarations \
1285f1e34d9SAlexandre Perrin	missing-prototypes \
1295f1e34d9SAlexandre Perrin	nested-externs \
1306a91b982SJohn Marino	shadow \
1315f1e34d9SAlexandre Perrin	strict-prototypes
1325f1e34d9SAlexandre Perrin
1336a91b982SJohn Marino.for s in ${SRCS:M*.c*:N*.c:N*h}
1345f1e34d9SAlexandre Perrin.for w in ${NO_CXX_WARNINGS}
1355f1e34d9SAlexandre PerrinW_$w_${s:T:R}.o=
1365f1e34d9SAlexandre Perrin.endfor
1375f1e34d9SAlexandre Perrin.endfor
1385f1e34d9SAlexandre Perrin
1395f1e34d9SAlexandre Perrin.endif # _w_cflags
140