Skip to content

Commit 1171a23

Browse files
committed
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.
1 parent b861dc9 commit 1171a23

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@
134134
# VTEST_PROGRAM : location of the vtest program to run reg-tests.
135135
# DEBUG_USE_ABORT: use abort() for program termination, see include/haproxy/bug.h for details
136136

137+
#### Add -Werror when set to non-empty, and make Makefile stop on warnings.
138+
#### It must be declared before includes because it's used there.
139+
ERR =
140+
137141
include include/make/verbose.mk
142+
include include/make/errors.mk
138143
include include/make/compiler.mk
139144
include include/make/options.mk
140145

@@ -158,7 +163,7 @@ TARGET =
158163
CPU =
159164
ifneq ($(CPU),)
160165
ifneq ($(CPU),generic)
161-
$(warning Warning: the "CPU" variable was forced to "$(CPU)" but is no longer \
166+
$(call $(complain),the "CPU" variable was forced to "$(CPU)" but is no longer \
162167
used and will be ignored. For native builds, modern compilers generally \
163168
prefer that the string "-march=native" is passed in CPU_CFLAGS or CFLAGS. \
164169
For other CPU-specific options, please read suggestions in the INSTALL file.)
@@ -168,7 +173,7 @@ endif
168173
#### No longer used
169174
ARCH =
170175
ifneq ($(ARCH),)
171-
$(warning Warning: the "ARCH" variable was forced to "$(ARCH)" but is no \
176+
$(call $(complain),the "ARCH" variable was forced to "$(ARCH)" but is no \
172177
longer used and will be ignored. Please check the INSTALL file for other \
173178
options, but usually in order to pass arch-specific options, ARCH_FLAGS, \
174179
CFLAGS or LDFLAGS are preferred.)
@@ -186,17 +191,14 @@ OPT_CFLAGS = -O2
186191
#### No longer used
187192
DEBUG_CFLAGS =
188193
ifneq ($(DEBUG_CFLAGS),)
189-
$(warning Warning: DEBUG_CFLAGS was forced to "$(DEBUG_CFLAGS)" but is no \
194+
$(call $(complain),DEBUG_CFLAGS was forced to "$(DEBUG_CFLAGS)" but is no \
190195
longer used and will be ignored. If you have ported this build setting from \
191196
and older version, it is likely that you just want to pass these options \
192197
to the CFLAGS variable. If you are passing some debugging-related options \
193198
such as -g/-ggdb3/-pg etc, they can now be passed in ARCH_FLAGS at once for \
194199
both the compilation and linking stages.)
195200
endif
196201

197-
#### Add -Werror when set to non-empty
198-
ERR =
199-
200202
#### May be used to force running a specific set of reg-tests
201203
REG_TEST_FILES =
202204
REG_TEST_SCRIPT=./scripts/run-regtests.sh
@@ -246,7 +248,7 @@ endif
246248
#### No longer used
247249
SMALL_OPTS =
248250
ifneq ($(SMALL_OPTS),)
249-
$(warning Warning: SMALL_OPTS was forced to "$(SMALL_OPTS)" but is no longer \
251+
$(call $(complain),SMALL_OPTS was forced to "$(SMALL_OPTS)" but is no longer \
250252
used and will be ignored. Please check if this setting are still relevant, \
251253
and move it either to DEFINE or to CFLAGS instead.)
252254
endif

include/make/errors.mk

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# error handling: define a "complain" function that maps either to "warning" or
2+
# "error" depending on the "ERR" variable. The callers must use:
3+
# $(call $(complain),<msg>)
4+
5+
ifneq ($(ERR:0=),)
6+
complain = error
7+
else
8+
complain = warning
9+
endif

include/make/options.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,4 @@ warn_unknown_options = \
6262
$(filter-out $(foreach opt,$(use_opts),$(opt:==%)), \
6363
$(foreach opt,$(MAKEOVERRIDES), \
6464
$(strip $(filter USE_%,$(opt))))), \
65-
$(warning Warning: ignoring unknown build option: $(unknown)))
65+
$(call $(complain),ignoring unknown build option: $(unknown)))

0 commit comments

Comments
 (0)