Willy Tarreau | 69e7b7f | 2022-12-22 19:32:24 +0100 | [diff] [blame] | 1 | # 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. |
| 9 | default_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. |
| 13 | ignore_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. |
| 21 | build_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 Tarreau | 848362f | 2022-12-22 19:51:30 +0100 | [diff] [blame] | 26 | build_features = $(foreach opt,$(patsubst USE_%,%,$(sort $(use_opts))),$(if $(USE_$(opt)),+$(opt),-$(opt))) |
Willy Tarreau | 69e7b7f | 2022-12-22 19:32:24 +0100 | [diff] [blame] | 27 | |
| 28 | # This returns a list of -DUSE_* for all known USE_* that are set |
| 29 | opts_as_defines = $(foreach opt,$(use_opts),$(if $($(opt)),-D$(opt),)) |
| 30 | |
| 31 | # Lists all enabled or disabled options without the "USE_" prefix |
| 32 | enabled_opts = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),$(opt),)) |
| 33 | disabled_opts = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(if $(USE_$(opt)),,$(opt))) |
Willy Tarreau | b14e89e | 2022-12-22 15:47:47 +0100 | [diff] [blame] | 34 | |
| 35 | # preset all XXX_{INC,LIB,CFLAGS,LDFLAGS,SRC} variables to empty for $1=XXX |
| 36 | reset_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 Tarreau | 6a2cd33 | 2022-12-23 15:01:54 +0100 | [diff] [blame] | 39 | reset_opts_vars = $(foreach opt,$(patsubst USE_%,%,$(use_opts)),$(call reset_opt_vars,$(opt))) |
Willy Tarreau | 8fa2f49 | 2022-12-22 19:44:35 +0100 | [diff] [blame] | 40 | |
| 41 | # append $(1)_{C,LD}FLAGS into OPTIONS_{C,LD}FLAGS if not empty |
| 42 | define 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 |
| 49 | endef |
| 50 | |
Willy Tarreau | 6e70a39 | 2022-12-23 15:08:38 +0100 | [diff] [blame] | 51 | # collect all enabled USE_foo's foo_{C,LD}FLAGS into OPTIONS_{C,LD}FLAGS |
| 52 | collect_opts_flags = $(foreach opt,$(enabled_opts),$(eval $(call collect_opt_flags,$(opt)))) |