blob: 1f9aaba69142c12130833466b1885350e150b0c7 [file] [log] [blame]
Willy Tarreau69e7b7f2022-12-22 19:32:24 +01001# this contains various functions and macros used to manipulate USE_* options
2# and their flags
3
4# Depending on the target platform, some options are set, as well as some
5# CFLAGS and LDFLAGS. All variables pre-set here will not appear in the build
6# options string. They may be set to any value, but are historically set to
7# "implicit" which eases debugging. You should not have to change anything
8# there unless you're adding support for a new platform.
9default_opts = $(foreach name,$(1),$(eval $(name)=implicit))
10
11# Return USE_xxx=$(USE_xxx) if the variable was set from the environment or the
12# command line.
13ignore_implicit = $(if $(subst environment,,$(origin $(1))), \
14 $(if $(subst command line,,$(origin $(1))),, \
15 $(1)=$($(1))), \
16 $(1)=$($(1))) \
17
18# This macro collects all USE_* values except those set to "implicit". This
19# is used to report a list of all flags which were used to build this version.
20# Do not assign anything to it.
21build_options = $(foreach opt,$(use_opts),$(call ignore_implicit,$(opt)))
22
23# Make a list of all known features with +/- prepended depending on their
24# activation status. Must be a macro so that dynamically enabled ones are
25# evaluated with their current status.
Willy Tarreau848362f2022-12-22 19:51:30 +010026build_features = $(foreach opt,$(patsubst USE_%,%,$(sort $(use_opts))),$(if $(USE_$(opt)),+$(opt),-$(opt)))
Willy Tarreau69e7b7f2022-12-22 19:32:24 +010027
28# This returns a list of -DUSE_* for all known USE_* that are set
29opts_as_defines = $(foreach opt,$(use_opts),$(if $($(opt)),-D$(opt),))
30
31# Lists all enabled or disabled options without the "USE_" prefix
32enabled_opts = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),$(opt),))
33disabled_opts = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),,$(opt)))
Willy Tarreaub14e89e2022-12-22 15:47:47 +010034
35# preset all XXX_{INC,LIB,CFLAGS,LDFLAGS,SRC} variables to empty for $1=XXX
36reset_opt_vars = $(foreach name,INC LIB CFLAGS LDFLAGS SRC,$(eval $(1)_$(name)=))
37
38# preset all variables for all supported build options among use_opts
Willy Tarreau6a2cd332022-12-23 15:01:54 +010039reset_opts_vars = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(call reset_opt_vars,$(opt)))
Willy Tarreau8fa2f492022-12-22 19:44:35 +010040
41# append $(1)_{C,LD}FLAGS into OPTIONS_{C,LD}FLAGS if not empty
42define collect_opt_flags =
43 ifneq ($$($(1)_CFLAGS),)
44 OPTIONS_CFLAGS += $$($(1)_CFLAGS)
45 endif
46 ifneq ($$($(1)_LDFLAGS),)
47 OPTIONS_LDFLAGS += $$($(1)_LDFLAGS)
48 endif
49endef
50
Willy Tarreau6e70a392022-12-23 15:08:38 +010051# collect all enabled USE_foo's foo_{C,LD}FLAGS into OPTIONS_{C,LD}FLAGS
52collect_opts_flags = $(foreach opt,$(enabled_opts),$(eval $(call collect_opt_flags,$(opt))))