xref: /openbmc/linux/tools/build/Makefile.feature (revision 9e03608e)
1ec8f24b7SThomas Gleixner# SPDX-License-Identifier: GPL-2.0-only
2e6c76d62SJiri Olsafeature_dir := $(srctree)/tools/build/feature
3e6c76d62SJiri Olsa
4e6c76d62SJiri Olsaifneq ($(OUTPUT),)
5e6c76d62SJiri Olsa  OUTPUT_FEATURES = $(OUTPUT)feature/
6e6c76d62SJiri Olsa  $(shell mkdir -p $(OUTPUT_FEATURES))
7e6c76d62SJiri Olsaendif
8e6c76d62SJiri Olsa
9e6c76d62SJiri Olsafeature_check = $(eval $(feature_check_code))
10e6c76d62SJiri Olsadefine feature_check_code
11fa5c8931SDaniel Díaz  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CC="$(CC)" CXX="$(CXX)" CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" CXXFLAGS="$(EXTRA_CXXFLAGS) $(FEATURE_CHECK_CXXFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
12e6c76d62SJiri Olsaendef
13e6c76d62SJiri Olsa
14e6c76d62SJiri Olsafeature_set = $(eval $(feature_set_code))
15e6c76d62SJiri Olsadefine feature_set_code
16e6c76d62SJiri Olsa  feature-$(1) := 1
17e6c76d62SJiri Olsaendef
18e6c76d62SJiri Olsa
19e6c76d62SJiri Olsa#
20e6c76d62SJiri Olsa# Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
21e6c76d62SJiri Olsa#
22e6c76d62SJiri Olsa
23e6c76d62SJiri Olsa#
24e6c76d62SJiri Olsa# Note that this is not a complete list of all feature tests, just
25e6c76d62SJiri Olsa# those that are typically built on a fully configured system.
26e6c76d62SJiri Olsa#
27e6c76d62SJiri Olsa# [ Feature tests not mentioned here have to be built explicitly in
28e6c76d62SJiri Olsa#   the rule that uses them - an example for that is the 'bionic'
29e6c76d62SJiri Olsa#   feature check. ]
30e6c76d62SJiri Olsa#
319fd4186aSWang NanFEATURE_TESTS_BASIC :=                  \
32e6c76d62SJiri Olsa        backtrace                       \
33e6c76d62SJiri Olsa        dwarf                           \
34bd0419e2SArnaldo Carvalho de Melo        dwarf_getlocations              \
3511c6cbe7SArnaldo Carvalho de Melo        eventfd                         \
36e6c76d62SJiri Olsa        fortify-source                  \
378feb8efeSArnaldo Carvalho de Melo        get_current_dir_name            \
384541a8bbSArnaldo Carvalho de Melo        gettid				\
39e6c76d62SJiri Olsa        glibc                           \
40e6c76d62SJiri Olsa        libbfd                          \
41e71e19a9SArnaldo Carvalho de Melo        libbfd-buildid			\
4274d5f3d0SIgor Lubashev        libcap                          \
43e6c76d62SJiri Olsa        libelf                          \
44e6c76d62SJiri Olsa        libelf-getphdrnum               \
451c1a3a47SArnaldo Carvalho de Melo        libelf-gelf_getnote             \
462492c465SArnaldo Carvalho de Melo        libelf-getshdrstrndx            \
47e6c76d62SJiri Olsa        libnuma                         \
48f8ac8606SArnaldo Carvalho de Melo        numa_num_possible_cpus          \
49e6c76d62SJiri Olsa        libperl                         \
50e6c76d62SJiri Olsa        libpython                       \
51e6c76d62SJiri Olsa        libslang                        \
52cbefd24fSArnaldo Carvalho de Melo        libslang-include-subdir         \
5356d32d4cSMichael Petlan        libtraceevent                   \
54b758a61bSIan Rogers        libtracefs                      \
558ee46460SStephane Eranian        libcrypto                       \
56e6c76d62SJiri Olsa        libunwind                       \
57e6c76d62SJiri Olsa        pthread-attr-setaffinity-np     \
5825ab5abfSArnaldo Carvalho de Melo        pthread-barrier     		\
59db42a21aSJakub Kicinski        reallocarray                    \
60e6c76d62SJiri Olsa        stackprotector-all              \
61e6c76d62SJiri Olsa        timerfd                         \
62e6c76d62SJiri Olsa        libdw-dwarf-unwind              \
636c6f0f61SJiri Olsa        zlib                            \
64b0063dbfSArnaldo Carvalho de Melo        lzma                            \
65ed63f34cSWang Nan        get_cpuid                       \
66e26e63beSMasami Hiramatsu        bpf                             \
67*9e03608eSArnaldo Carvalho de Melo        scandirat			\
68120010cbSArnaldo Carvalho de Melo        sched_getcpu			\
6986bcdb5aSArnaldo Carvalho de Melo        sdt				\
70aa6292f4SMathieu Poirier        setns				\
718a1b1718SSong Liu        libaio				\
723b1c5d96SAlexey Budankov        libzstd				\
7349f550eaSNamhyung Kim        disassembler-four-args		\
74cfd59ca9SAndres Freund        disassembler-init-styled	\
7549f550eaSNamhyung Kim        file-handle
76e6c76d62SJiri Olsa
779fd4186aSWang Nan# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
789fd4186aSWang Nan# of all feature tests
799fd4186aSWang NanFEATURE_TESTS_EXTRA :=                  \
809fd4186aSWang Nan         bionic                         \
819fd4186aSWang Nan         compile-32                     \
829fd4186aSWang Nan         compile-x32                    \
839fd4186aSWang Nan         cplus-demangle                 \
844c72e2b3SIan Rogers         cxa-demangle                   \
854751bdddSArnaldo Carvalho de Melo         gtk2                           \
864751bdddSArnaldo Carvalho de Melo         gtk2-infobar                   \
879fd4186aSWang Nan         hello                          \
889fd4186aSWang Nan         libbabeltrace                  \
8914541b1eSStanislav Fomichev         libbfd-liberty                 \
9014541b1eSStanislav Fomichev         libbfd-liberty-z               \
911c3b28fdSArnaldo Carvalho de Melo         libopencsd                     \
925c4d7c82SArnaldo Carvalho de Melo         libunwind-x86                  \
935c4d7c82SArnaldo Carvalho de Melo         libunwind-x86_64               \
945c4d7c82SArnaldo Carvalho de Melo         libunwind-arm                  \
955c4d7c82SArnaldo Carvalho de Melo         libunwind-aarch64              \
96f9be7eefSHe Kuang         libunwind-debug-frame          \
97f9be7eefSHe Kuang         libunwind-debug-frame-arm      \
98bd476684SJiri Olsa         libunwind-debug-frame-aarch64  \
99bd476684SJiri Olsa         cxx                            \
100bd476684SJiri Olsa         llvm                           \
101bd476684SJiri Olsa         llvm-version                   \
1027b65e203SJiri Olsa         clang                          \
1035ef86146SStephane Eranian         libbpf                         \
1040ae065a5SArnaldo Carvalho de Melo         libbpf-btf__load_from_kernel_by_id \
1055c83eff3SJiri Olsa         libbpf-bpf_prog_load           \
1068916d725SJiri Olsa         libbpf-bpf_object__next_program \
107739c9180SJiri Olsa         libbpf-bpf_object__next_map    \
108f1bdebbbSArnaldo Carvalho de Melo         libbpf-bpf_program__set_insns  \
109df76e003SArnaldo Carvalho de Melo         libbpf-bpf_create_map		\
110c7a14fdcSFrank Ch. Eigler         libpfm4                        \
111fbcdaa19SSong Liu         libdebuginfod			\
112fbcdaa19SSong Liu         clang-bpf-co-re
113fbcdaa19SSong Liu
1149fd4186aSWang Nan
1159fd4186aSWang NanFEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
1169fd4186aSWang Nan
1179fd4186aSWang Nanifeq ($(FEATURE_TESTS),all)
1189fd4186aSWang Nan  FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
1199fd4186aSWang Nanendif
1209fd4186aSWang Nan
1218135c8c7SWang NanFEATURE_DISPLAY ?=              \
122e6c76d62SJiri Olsa         dwarf                  \
123bd0419e2SArnaldo Carvalho de Melo         dwarf_getlocations     \
124e6c76d62SJiri Olsa         glibc                  \
125e6c76d62SJiri Olsa         libbfd                 \
126e71e19a9SArnaldo Carvalho de Melo         libbfd-buildid		\
12774d5f3d0SIgor Lubashev         libcap                 \
128e6c76d62SJiri Olsa         libelf                 \
129e6c76d62SJiri Olsa         libnuma                \
130f8ac8606SArnaldo Carvalho de Melo         numa_num_possible_cpus \
131e6c76d62SJiri Olsa         libperl                \
132e6c76d62SJiri Olsa         libpython              \
1338ee46460SStephane Eranian         libcrypto              \
134e6c76d62SJiri Olsa         libunwind              \
135e6c76d62SJiri Olsa         libdw-dwarf-unwind     \
1366c6f0f61SJiri Olsa         zlib                   \
137b0063dbfSArnaldo Carvalho de Melo         lzma                   \
138ed63f34cSWang Nan         get_cpuid              \
1392a07d814SAlexey Budankov         bpf			\
1408a1b1718SSong Liu         libaio			\
141516ddaadSAndres Freund         libzstd
142e6c76d62SJiri Olsa
14374ef1cc9SRoberto Sassu#
14474ef1cc9SRoberto Sassu# Declare group members of a feature to display the logical OR of the detection
14574ef1cc9SRoberto Sassu# result instead of each member result.
14674ef1cc9SRoberto Sassu#
14774ef1cc9SRoberto SassuFEATURE_GROUP_MEMBERS-libbfd = libbfd-liberty libbfd-liberty-z
14874ef1cc9SRoberto Sassu
149e6c76d62SJiri Olsa# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
150e6c76d62SJiri Olsa# If in the future we need per-feature checks/flags for features not
151e6c76d62SJiri Olsa# mentioned in this list we need to refactor this ;-).
152e6c76d62SJiri Olsaset_test_all_flags = $(eval $(set_test_all_flags_code))
153e6c76d62SJiri Olsadefine set_test_all_flags_code
154e6c76d62SJiri Olsa  FEATURE_CHECK_CFLAGS-all  += $(FEATURE_CHECK_CFLAGS-$(1))
155e6c76d62SJiri Olsa  FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
156e6c76d62SJiri Olsaendef
157e6c76d62SJiri Olsa
158e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
159e6c76d62SJiri Olsa
160e6c76d62SJiri Olsa#
161e6c76d62SJiri Olsa# Special fast-path for the 'all features are available' case:
162e6c76d62SJiri Olsa#
163e6c76d62SJiri Olsa$(call feature_check,all,$(MSG))
164e6c76d62SJiri Olsa
165e6c76d62SJiri Olsa#
166e6c76d62SJiri Olsa# Just in case the build freshly failed, make sure we print the
167e6c76d62SJiri Olsa# feature matrix:
168e6c76d62SJiri Olsa#
169e6c76d62SJiri Olsaifeq ($(feature-all), 1)
170e6c76d62SJiri Olsa  #
171e6c76d62SJiri Olsa  # test-all.c passed - just set all the core feature flags to 1:
172e6c76d62SJiri Olsa  #
173e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
17476c4aaecSJiri Olsa  #
17576c4aaecSJiri Olsa  # test-all.c does not comprise these tests, so we need to
17676c4aaecSJiri Olsa  # for this case to get features proper values
17776c4aaecSJiri Olsa  #
17876c4aaecSJiri Olsa  $(call feature_check,compile-32)
17976c4aaecSJiri Olsa  $(call feature_check,compile-x32)
18076c4aaecSJiri Olsa  $(call feature_check,bionic)
18176c4aaecSJiri Olsa  $(call feature_check,libbabeltrace)
182e6c76d62SJiri Olsaelse
183e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
184e6c76d62SJiri Olsaendif
185e6c76d62SJiri Olsa
186e6c76d62SJiri Olsa#
187e6c76d62SJiri Olsa# Print the result of the feature test:
188e6c76d62SJiri Olsa#
189709533e5SRoberto Sassufeature_print_status = $(eval $(feature_print_status_code))
190e6c76d62SJiri Olsa
19174ef1cc9SRoberto Sassufeature_group = $(eval $(feature_gen_group)) $(GROUP)
19274ef1cc9SRoberto Sassu
19374ef1cc9SRoberto Sassudefine feature_gen_group
19474ef1cc9SRoberto Sassu  GROUP := $(1)
19574ef1cc9SRoberto Sassu  ifneq ($(feature_verbose),1)
19674ef1cc9SRoberto Sassu    GROUP += $(FEATURE_GROUP_MEMBERS-$(1))
19774ef1cc9SRoberto Sassu  endif
19874ef1cc9SRoberto Sassuendef
19974ef1cc9SRoberto Sassu
200e6c76d62SJiri Olsadefine feature_print_status_code
20174ef1cc9SRoberto Sassu  ifneq (,$(filter 1,$(foreach feat,$(call feature_group,$(feat)),$(feature-$(feat)))))
20274da7697SRoberto Sassu    MSG = $(shell printf '...%40s: [ \033[32mon\033[m  ]' $(1))
203e6c76d62SJiri Olsa  else
20474da7697SRoberto Sassu    MSG = $(shell printf '...%40s: [ \033[31mOFF\033[m ]' $(1))
205e6c76d62SJiri Olsa  endif
206e6c76d62SJiri Olsaendef
207e6c76d62SJiri Olsa
208709533e5SRoberto Sassufeature_print_text = $(eval $(feature_print_text_code))
209e6c76d62SJiri Olsadefine feature_print_text_code
21074da7697SRoberto Sassu    MSG = $(shell printf '...%40s: %s' $(1) $(2))
211e6c76d62SJiri Olsaendef
212e6c76d62SJiri Olsa
213c6a5f88fSJiri Olsa#
214c6a5f88fSJiri Olsa# generates feature value assignment for name, like:
215c6a5f88fSJiri Olsa#   $(call feature_assign,dwarf) == feature-dwarf=1
216c6a5f88fSJiri Olsa#
217c6a5f88fSJiri Olsafeature_assign = feature-$(1)=$(feature-$(1))
218c6a5f88fSJiri Olsa
21913e96db6SArnaldo Carvalho de MeloFEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
220936d120dSJiri OlsaFEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
221936d120dSJiri Olsa
222936d120dSJiri Olsafeature_dump_check = $(eval $(feature_dump_check_code))
223936d120dSJiri Olsadefine feature_dump_check_code
224936d120dSJiri Olsa  ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
225936d120dSJiri Olsa    $(2) := 1
226936d120dSJiri Olsa  endif
227936d120dSJiri Olsaendef
228936d120dSJiri Olsa
229936d120dSJiri Olsa#
230936d120dSJiri Olsa# First check if any test from FEATURE_DISPLAY
231936d120dSJiri Olsa# and set feature_display := 1 if it does
232936d120dSJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
233936d120dSJiri Olsa
234936d120dSJiri Olsa#
235936d120dSJiri Olsa# Now also check if any other test changed,
236936d120dSJiri Olsa# so we force FEATURE-DUMP generation
237936d120dSJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
238e6c76d62SJiri Olsa
239e6c76d62SJiri Olsa# The $(feature_display) controls the default detection message
240e6c76d62SJiri Olsa# output. It's set if:
241e6c76d62SJiri Olsa# - detected features differes from stored features from
24213e96db6SArnaldo Carvalho de Melo#   last build (in $(FEATURE_DUMP_FILENAME) file)
243e6c76d62SJiri Olsa# - one of the $(FEATURE_DISPLAY) is not detected
244e6c76d62SJiri Olsa# - VF is enabled
245e6c76d62SJiri Olsa
246936d120dSJiri Olsaifeq ($(feature_dump_changed),1)
247936d120dSJiri Olsa  $(shell rm -f $(FEATURE_DUMP_FILENAME))
248936d120dSJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
249e6c76d62SJiri Olsaendif
250e6c76d62SJiri Olsa
2516076e2a4SArnaldo Carvalho de Melofeature_display_check = $(eval $(feature_check_display_code))
252d0018b49SJiri Olsadefine feature_check_display_code
253e6c76d62SJiri Olsa  ifneq ($(feature-$(1)), 1)
254e6c76d62SJiri Olsa    feature_display := 1
255e6c76d62SJiri Olsa  endif
256e6c76d62SJiri Olsaendef
257e6c76d62SJiri Olsa
258e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
259e6c76d62SJiri Olsa
260e6c76d62SJiri Olsaifeq ($(VF),1)
261e6c76d62SJiri Olsa  feature_display := 1
262e6c76d62SJiri Olsa  feature_verbose := 1
263e6c76d62SJiri Olsaendif
264e6c76d62SJiri Olsa
26574ef1cc9SRoberto Sassuifneq ($(feature_verbose),1)
26674ef1cc9SRoberto Sassu  #
26774ef1cc9SRoberto Sassu  # Determine the features to omit from the displayed message, as only the
26874ef1cc9SRoberto Sassu  # logical OR of the detection result will be shown.
26974ef1cc9SRoberto Sassu  #
27074ef1cc9SRoberto Sassu  FEATURE_OMIT := $(foreach feat,$(FEATURE_DISPLAY),$(FEATURE_GROUP_MEMBERS-$(feat)))
27174ef1cc9SRoberto Sassuendif
27274ef1cc9SRoberto Sassu
27319177bc3SArnaldo Carvalho de Melofeature_display_entries = $(eval $(feature_display_entries_code))
27419177bc3SArnaldo Carvalho de Melodefine feature_display_entries_code
275e6c76d62SJiri Olsa  ifeq ($(feature_display),1)
276709533e5SRoberto Sassu    $$(info )
277709533e5SRoberto Sassu    $$(info Auto-detecting system features:)
27874ef1cc9SRoberto Sassu    $(foreach feat,$(filter-out $(FEATURE_OMIT),$(FEATURE_DISPLAY)),$(call feature_print_status,$(feat),) $$(info $(MSG)))
279e6c76d62SJiri Olsa  endif
280e6c76d62SJiri Olsa
281e6c76d62SJiri Olsa  ifeq ($(feature_verbose),1)
282709533e5SRoberto Sassu    $(eval TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS)))
283709533e5SRoberto Sassu    $(foreach feat,$(TMP),$(call feature_print_status,$(feat),) $$(info $(MSG)))
284e6c76d62SJiri Olsa  endif
28519177bc3SArnaldo Carvalho de Meloendef
28619177bc3SArnaldo Carvalho de Melo
28719177bc3SArnaldo Carvalho de Meloifeq ($(FEATURE_DISPLAY_DEFERRED),)
28819177bc3SArnaldo Carvalho de Melo  $(call feature_display_entries)
289709533e5SRoberto Sassu  $(info )
29019177bc3SArnaldo Carvalho de Meloendif
291