From 1171a23aec0fdfe73cac02356ec6184241b7e7c3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 20 Nov 2024 14:44:28 +0100 Subject: [PATCH] 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. --- Makefile | 16 +++++++++------- include/make/errors.mk | 9 +++++++++ include/make/options.mk | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 include/make/errors.mk diff --git a/Makefile b/Makefile index e70891ee2d..2b9a6670de 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/include/make/errors.mk b/include/make/errors.mk new file mode 100644 index 0000000000..ad138b8310 --- /dev/null +++ b/include/make/errors.mk @@ -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),) + +ifneq ($(ERR:0=),) +complain = error +else +complain = warning +endif diff --git a/include/make/options.mk b/include/make/options.mk index d2125866f1..75c84e605b 100644 --- a/include/make/options.mk +++ b/include/make/options.mk @@ -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)))