Skip to content

Commit

Permalink
tools build: Display logical OR of a feature flavors
Browse files Browse the repository at this point in the history
Sometimes, features are simply different flavors of another feature, to
properly detect the exact dependencies needed by different Linux
distributions.

For example, libbfd has three flavors: libbfd if the distro does not
require any additional dependency; libbfd-liberty if it requires libiberty;
libbfd-liberty-z if it requires libiberty and libz.

It might not be clear to the user whether a feature has been successfully
detected or not, given that some of its flavors will be set to OFF, others
to ON.

Instead, display only the feature main flavor if not in verbose mode
(VF != 1), and set it to ON if at least one of its flavors has been
successfully detected (logical OR), OFF otherwise. Omit the other flavors.

Accomplish that by declaring a FEATURE_GROUP_MEMBERS-<feature main flavor>
variable, with the list of the other flavors as variable value. For now, do
it just for libbfd.

In verbose mode, of if no group is defined for a feature, show the feature
detection result as before.

Committer testing:

Collecting the output from:

  $ make -C tools/bpf/bpftool/ clean
  $ make -C tools/bpf/bpftool/ |& grep "Auto-detecting system features" -A10

  $ diff -u before after
  --- before	2022-08-18 10:06:40.422086966 -0300
  +++ after	2022-08-18 10:07:59.202138282 -0300
  @@ -1,6 +1,4 @@
   Auto-detecting system features:
   ...                                  libbfd: [ on  ]
  -...                          libbfd-liberty: [ on  ]
  -...                        libbfd-liberty-z: [ on  ]
   ...                                  libcap: [ on  ]
   ...                         clang-bpf-co-re: [ on  ]
  $

Signed-off-by: Roberto Sassu <[email protected]>
Tested-by: Arnaldo Carvalho de Melo <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Quentin Monnet <[email protected]>
Cc: [email protected]
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
robertosassu authored and acmel committed Oct 4, 2022
1 parent 74da769 commit 74ef1cc
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tools/build/Makefile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ FEATURE_DISPLAY ?= \
libaio \
libzstd

#
# Declare group members of a feature to display the logical OR of the detection
# result instead of each member result.
#
FEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z

# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
# If in the future we need per-feature checks/flags for features not
# mentioned in this list we need to refactor this ;-).
Expand Down Expand Up @@ -179,8 +185,17 @@ endif
#
feature_print_status = $(eval $(feature_print_status_code))

feature_group = $(eval $(feature_gen_group)) $(GROUP)

define feature_gen_group
GROUP := $(1)
ifneq ($(feature_verbose),1)
GROUP += $(FEATURE_GROUP_MEMBERS-$(1))
endif
endef

define feature_print_status_code
ifeq ($(feature-$(1)), 1)
ifneq (,$(filter 1,$(foreach feat,$(call feature_group,$(feat)),$(feature-$(feat)))))
MSG = $(shell printf '...%40s: [ \033[32mon\033[m ]' $(1))
else
MSG = $(shell printf '...%40s: [ \033[31mOFF\033[m ]' $(1))
Expand Down Expand Up @@ -244,12 +259,20 @@ ifeq ($(VF),1)
feature_verbose := 1
endif

ifneq ($(feature_verbose),1)
#
# Determine the features to omit from the displayed message, as only the
# logical OR of the detection result will be shown.
#
FEATURE_OMIT := $(foreach feat,$(FEATURE_DISPLAY),$(FEATURE_GROUP_MEMBERS-$(feat)))
endif

feature_display_entries = $(eval $(feature_display_entries_code))
define feature_display_entries_code
ifeq ($(feature_display),1)
$$(info )
$$(info Auto-detecting system features:)
$(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),) $$(info $(MSG)))
$(foreach feat,$(filter-out $(FEATURE_OMIT),$(FEATURE_DISPLAY)),$(call feature_print_status,$(feat),) $$(info $(MSG)))
endif

ifeq ($(feature_verbose),1)
Expand Down

0 comments on commit 74ef1cc

Please sign in to comment.