]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: makefile: initialize all build options' variables at once
authorWilly Tarreau <w@1wt.eu>
Thu, 22 Dec 2022 14:47:47 +0000 (15:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 23 Dec 2022 15:53:35 +0000 (16:53 +0100)
A lot of _SRC, _INC, _LIB etc variables are set and expected to be
initialized to an empty string by default. However, an in-depth
review of all of them showed that WOLFSSL_{INC,LIB}, SSL_{INC,LIB},
LUA_{INC,LIB}, and maybe others were not always initialized and could
sometimes leak from the environment and as such cause strange build
issues when running from cascaded scripts that had exported them.

The approach taken here consists in iterating over all USE_* options
and unsetting any _SRC, _INC, _LIB, _CFLAGS and _LDFLAGS that follows
the same name. For the few variable names options that don't exactly
match the build option (SSL & WOLFSSL), these ones are specifically
added to the list. The few that were explicitly cleared in their own
sections were just removed since not needed anymore. Note that an
"undefine" command appeared in GNU make 3.82 but since we support
older ones we can only initialize the variables to an empty string
here. It's not a problem in practice.

We're now certain that these variables are empty wherever they are
used, and that it is possible to just append to them, or use them
as-is.

Makefile
include/make/options.mk

index 31004e5a4ea9fe72147c78bb4d162e433571c3ae..98a13995318102100c55637753fd0296c442a5d1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -308,6 +308,9 @@ use_opts = USE_EPOLL USE_KQUEUE USE_NETFILTER                                 \
            USE_THREAD_DUMP USE_EVPORTS USE_OT USE_QUIC USE_PROMEX             \
            USE_MEMORY_PROFILING USE_SHM_OPEN
 
+# preset all variables for all supported build options among use_opts
+$(reset_opts_vars)
+
 #### Target system options
 
 # poll() is always supported, unless explicitly disabled by passing USE_POLL=""
@@ -515,8 +518,6 @@ endif
 
 ifneq ($(USE_ZLIB),)
 # Use ZLIB_INC and ZLIB_LIB to force path to zlib.h and libz.{a,so} if needed.
-ZLIB_INC =
-ZLIB_LIB =
 OPTIONS_CFLAGS  += $(if $(ZLIB_INC),-I$(ZLIB_INC))
 OPTIONS_LDFLAGS += $(if $(ZLIB_LIB),-L$(ZLIB_LIB)) -lz
 endif
@@ -562,8 +563,6 @@ OPTIONS_OBJS   += src/cpuset.o
 endif
 
 ifneq ($(USE_OPENSSL),)
-SSL_INC =
-SSL_LIB =
 # OpenSSL is packaged in various forms and with various dependencies.
 # In general -lssl is enough, but on some platforms, -lcrypto may be needed,
 # reason why it's added by default. Some even need -lz, then you'll need to
@@ -650,7 +649,6 @@ endif
 ifneq ($(USE_DEVICEATLAS),)
 # Use DEVICEATLAS_SRC and possibly DEVICEATLAS_INC and DEVICEATLAS_LIB to force path
 # to DeviceAtlas headers and libraries if needed.
-DEVICEATLAS_SRC =
 DEVICEATLAS_INC = $(DEVICEATLAS_SRC)
 DEVICEATLAS_LIB = $(DEVICEATLAS_SRC)
 ifeq ($(DEVICEATLAS_SRC),)
@@ -683,7 +681,6 @@ endif
 ifneq ($(USE_51DEGREES)$(USE_51DEGREES_V4),)
 # Use 51DEGREES_SRC and possibly 51DEGREES_INC and 51DEGREES_LIB to force path
 # to 51degrees headers and libraries if needed.
-51DEGREES_SRC =
 51DEGREES_INC = $(51DEGREES_SRC)
 51DEGREES_LIB = $(51DEGREES_SRC)
 ifneq ($(USE_51DEGREES_V4),)
@@ -718,7 +715,6 @@ endif
 ifneq ($(USE_WURFL),)
 # Use WURFL_SRC and possibly WURFL_INC and WURFL_LIB to force path
 # to WURFL headers and libraries if needed.
-WURFL_SRC =
 WURFL_INC = $(WURFL_SRC)
 WURFL_LIB = $(WURFL_SRC)
 OPTIONS_OBJS    += addons/wurfl/wurfl.o
index db4502c4b949c1636e7a765ce6e28afd540ab92c..f439be345a91c34a70d3a2cb3b97707e72389ca1 100644 (file)
@@ -31,3 +31,9 @@ opts_as_defines = $(foreach opt,$(use_opts),$(if $($(opt)),-D$(opt),))
 # Lists all enabled or disabled options without the "USE_" prefix
 enabled_opts    = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),$(opt),))
 disabled_opts   = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),,$(opt)))
+
+# preset all XXX_{INC,LIB,CFLAGS,LDFLAGS,SRC} variables to empty for $1=XXX
+reset_opt_vars = $(foreach name,INC LIB CFLAGS LDFLAGS SRC,$(eval $(1)_$(name)=))
+
+# preset all variables for all supported build options among use_opts
+reset_opts_vars = $(foreach opt,$(patsubst USE_%,%,$(use_opts)) SSL WOLFSSL,$(call reset_opt_vars,$(opt)))