BUILD: makefile: make ERR apply to build options as well

Once in a while we find some makefiles ignoring some outdated arguments
and just emit a warning. What's annoying is that if users (say, distro
packagers), have purposely added ERR=1 to their build scripts to make
sure to fail on any warning, these ones will be ignored and the build
can continue with invalid or missing options.

William rightfully suggested that ERR=1 should also catch make's warnings
so this patch implements this, by creating a new "complain" variable that
points either to "error" or "warning" depending on $(ERR), and that is
used to send the messages using $(call $(complain),...). This does the
job right at little effort (tested from GNU make 3.82 to 4.3).

Note that for this purpose the ERR declaration was upped in the makefile
so that it appears before the new errors.mk file is included.
This commit is contained in:
Willy Tarreau 2024-11-20 14:44:28 +01:00
parent b861dc9371
commit 1171a23aec
3 changed files with 19 additions and 8 deletions

View File

@ -134,7 +134,12 @@
# VTEST_PROGRAM : location of the vtest program to run reg-tests.
# DEBUG_USE_ABORT: use abort() for program termination, see include/haproxy/bug.h for details
#### Add -Werror when set to non-empty, and make Makefile stop on warnings.
#### It must be declared before includes because it's used there.
ERR =
include include/make/verbose.mk
include include/make/errors.mk
include include/make/compiler.mk
include include/make/options.mk
@ -158,7 +163,7 @@ TARGET =
CPU =
ifneq ($(CPU),)
ifneq ($(CPU),generic)
$(warning Warning: the "CPU" variable was forced to "$(CPU)" but is no longer \
$(call $(complain),the "CPU" variable was forced to "$(CPU)" but is no longer \
used and will be ignored. For native builds, modern compilers generally \
prefer that the string "-march=native" is passed in CPU_CFLAGS or CFLAGS. \
For other CPU-specific options, please read suggestions in the INSTALL file.)
@ -168,7 +173,7 @@ endif
#### No longer used
ARCH =
ifneq ($(ARCH),)
$(warning Warning: the "ARCH" variable was forced to "$(ARCH)" but is no \
$(call $(complain),the "ARCH" variable was forced to "$(ARCH)" but is no \
longer used and will be ignored. Please check the INSTALL file for other \
options, but usually in order to pass arch-specific options, ARCH_FLAGS, \
CFLAGS or LDFLAGS are preferred.)
@ -186,7 +191,7 @@ OPT_CFLAGS = -O2
#### No longer used
DEBUG_CFLAGS =
ifneq ($(DEBUG_CFLAGS),)
$(warning Warning: DEBUG_CFLAGS was forced to "$(DEBUG_CFLAGS)" but is no \
$(call $(complain),DEBUG_CFLAGS was forced to "$(DEBUG_CFLAGS)" but is no \
longer used and will be ignored. If you have ported this build setting from \
and older version, it is likely that you just want to pass these options \
to the CFLAGS variable. If you are passing some debugging-related options \
@ -194,9 +199,6 @@ $(warning Warning: DEBUG_CFLAGS was forced to "$(DEBUG_CFLAGS)" but is no \
both the compilation and linking stages.)
endif
#### Add -Werror when set to non-empty
ERR =
#### May be used to force running a specific set of reg-tests
REG_TEST_FILES =
REG_TEST_SCRIPT=./scripts/run-regtests.sh
@ -246,7 +248,7 @@ endif
#### No longer used
SMALL_OPTS =
ifneq ($(SMALL_OPTS),)
$(warning Warning: SMALL_OPTS was forced to "$(SMALL_OPTS)" but is no longer \
$(call $(complain),SMALL_OPTS was forced to "$(SMALL_OPTS)" but is no longer \
used and will be ignored. Please check if this setting are still relevant, \
and move it either to DEFINE or to CFLAGS instead.)
endif

9
include/make/errors.mk Normal file
View File

@ -0,0 +1,9 @@
# error handling: define a "complain" function that maps either to "warning" or
# "error" depending on the "ERR" variable. The callers must use:
# $(call $(complain),<msg>)
ifneq ($(ERR:0=),)
complain = error
else
complain = warning
endif

View File

@ -62,4 +62,4 @@ warn_unknown_options = \
$(filter-out $(foreach opt,$(use_opts),$(opt:==%)), \
$(foreach opt,$(MAKEOVERRIDES), \
$(strip $(filter USE_%,$(opt))))), \
$(warning Warning: ignoring unknown build option: $(unknown)))
$(call $(complain),ignoring unknown build option: $(unknown)))