Skip to content

Commit

Permalink
BUILD: makefile: make ERR apply to build options as well
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wtarreau committed Nov 20, 2024
1 parent b861dc9 commit 1171a23
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.)
Expand All @@ -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.)
Expand All @@ -186,17 +191,14 @@ 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 \
such as -g/-ggdb3/-pg etc, they can now be passed in ARCH_FLAGS at once for \
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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions include/make/errors.mk
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion include/make/options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

0 comments on commit 1171a23

Please sign in to comment.