xref: /openbmc/linux/tools/build/Makefile.feature (revision fbcdaa19)
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                  \
37e6c76d62SJiri Olsa        sync-compare-and-swap           \
388feb8efeSArnaldo Carvalho de Melo        get_current_dir_name            \
394541a8bbSArnaldo Carvalho de Melo        gettid				\
40e6c76d62SJiri Olsa        glibc                           \
41e6c76d62SJiri Olsa        libbfd                          \
42e71e19a9SArnaldo Carvalho de Melo        libbfd-buildid			\
4374d5f3d0SIgor Lubashev        libcap                          \
44e6c76d62SJiri Olsa        libelf                          \
45e6c76d62SJiri Olsa        libelf-getphdrnum               \
461c1a3a47SArnaldo Carvalho de Melo        libelf-gelf_getnote             \
472492c465SArnaldo Carvalho de Melo        libelf-getshdrstrndx            \
48e6c76d62SJiri Olsa        libnuma                         \
49f8ac8606SArnaldo Carvalho de Melo        numa_num_possible_cpus          \
50e6c76d62SJiri Olsa        libperl                         \
51e6c76d62SJiri Olsa        libpython                       \
52e6c76d62SJiri Olsa        libpython-version               \
53e6c76d62SJiri Olsa        libslang                        \
54cbefd24fSArnaldo Carvalho de Melo        libslang-include-subdir         \
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                             \
67120010cbSArnaldo Carvalho de Melo        sched_getcpu			\
6886bcdb5aSArnaldo Carvalho de Melo        sdt				\
69aa6292f4SMathieu Poirier        setns				\
708a1b1718SSong Liu        libaio				\
713b1c5d96SAlexey Budankov        libzstd				\
7249f550eaSNamhyung Kim        disassembler-four-args		\
7349f550eaSNamhyung Kim        file-handle
74e6c76d62SJiri Olsa
759fd4186aSWang Nan# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
769fd4186aSWang Nan# of all feature tests
779fd4186aSWang NanFEATURE_TESTS_EXTRA :=                  \
789fd4186aSWang Nan         bionic                         \
799fd4186aSWang Nan         compile-32                     \
809fd4186aSWang Nan         compile-x32                    \
819fd4186aSWang Nan         cplus-demangle                 \
824751bdddSArnaldo Carvalho de Melo         gtk2                           \
834751bdddSArnaldo Carvalho de Melo         gtk2-infobar                   \
849fd4186aSWang Nan         hello                          \
859fd4186aSWang Nan         libbabeltrace                  \
8614541b1eSStanislav Fomichev         libbfd-liberty                 \
8714541b1eSStanislav Fomichev         libbfd-liberty-z               \
881c3b28fdSArnaldo Carvalho de Melo         libopencsd                     \
895c4d7c82SArnaldo Carvalho de Melo         libunwind-x86                  \
905c4d7c82SArnaldo Carvalho de Melo         libunwind-x86_64               \
915c4d7c82SArnaldo Carvalho de Melo         libunwind-arm                  \
925c4d7c82SArnaldo Carvalho de Melo         libunwind-aarch64              \
93f9be7eefSHe Kuang         libunwind-debug-frame          \
94f9be7eefSHe Kuang         libunwind-debug-frame-arm      \
95bd476684SJiri Olsa         libunwind-debug-frame-aarch64  \
96bd476684SJiri Olsa         cxx                            \
97bd476684SJiri Olsa         llvm                           \
98bd476684SJiri Olsa         llvm-version                   \
997b65e203SJiri Olsa         clang                          \
1005ef86146SStephane Eranian         libbpf                         \
101c7a14fdcSFrank Ch. Eigler         libpfm4                        \
102*fbcdaa19SSong Liu         libdebuginfod			\
103*fbcdaa19SSong Liu         clang-bpf-co-re
104*fbcdaa19SSong Liu
1059fd4186aSWang Nan
1069fd4186aSWang NanFEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
1079fd4186aSWang Nan
1089fd4186aSWang Nanifeq ($(FEATURE_TESTS),all)
1099fd4186aSWang Nan  FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
1109fd4186aSWang Nanendif
1119fd4186aSWang Nan
1128135c8c7SWang NanFEATURE_DISPLAY ?=              \
113e6c76d62SJiri Olsa         dwarf                  \
114bd0419e2SArnaldo Carvalho de Melo         dwarf_getlocations     \
115e6c76d62SJiri Olsa         glibc                  \
116e6c76d62SJiri Olsa         libbfd                 \
117e71e19a9SArnaldo Carvalho de Melo         libbfd-buildid		\
11874d5f3d0SIgor Lubashev         libcap                 \
119e6c76d62SJiri Olsa         libelf                 \
120e6c76d62SJiri Olsa         libnuma                \
121f8ac8606SArnaldo Carvalho de Melo         numa_num_possible_cpus \
122e6c76d62SJiri Olsa         libperl                \
123e6c76d62SJiri Olsa         libpython              \
1248ee46460SStephane Eranian         libcrypto              \
125e6c76d62SJiri Olsa         libunwind              \
126e6c76d62SJiri Olsa         libdw-dwarf-unwind     \
1276c6f0f61SJiri Olsa         zlib                   \
128b0063dbfSArnaldo Carvalho de Melo         lzma                   \
129ed63f34cSWang Nan         get_cpuid              \
1302a07d814SAlexey Budankov         bpf			\
1318a1b1718SSong Liu         libaio			\
1323b1c5d96SAlexey Budankov         libzstd		\
1338a1b1718SSong Liu         disassembler-four-args
134e6c76d62SJiri Olsa
135e6c76d62SJiri Olsa# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
136e6c76d62SJiri Olsa# If in the future we need per-feature checks/flags for features not
137e6c76d62SJiri Olsa# mentioned in this list we need to refactor this ;-).
138e6c76d62SJiri Olsaset_test_all_flags = $(eval $(set_test_all_flags_code))
139e6c76d62SJiri Olsadefine set_test_all_flags_code
140e6c76d62SJiri Olsa  FEATURE_CHECK_CFLAGS-all  += $(FEATURE_CHECK_CFLAGS-$(1))
141e6c76d62SJiri Olsa  FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
142e6c76d62SJiri Olsaendef
143e6c76d62SJiri Olsa
144e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
145e6c76d62SJiri Olsa
146e6c76d62SJiri Olsa#
147e6c76d62SJiri Olsa# Special fast-path for the 'all features are available' case:
148e6c76d62SJiri Olsa#
149e6c76d62SJiri Olsa$(call feature_check,all,$(MSG))
150e6c76d62SJiri Olsa
151e6c76d62SJiri Olsa#
152e6c76d62SJiri Olsa# Just in case the build freshly failed, make sure we print the
153e6c76d62SJiri Olsa# feature matrix:
154e6c76d62SJiri Olsa#
155e6c76d62SJiri Olsaifeq ($(feature-all), 1)
156e6c76d62SJiri Olsa  #
157e6c76d62SJiri Olsa  # test-all.c passed - just set all the core feature flags to 1:
158e6c76d62SJiri Olsa  #
159e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
16076c4aaecSJiri Olsa  #
16176c4aaecSJiri Olsa  # test-all.c does not comprise these tests, so we need to
16276c4aaecSJiri Olsa  # for this case to get features proper values
16376c4aaecSJiri Olsa  #
16476c4aaecSJiri Olsa  $(call feature_check,compile-32)
16576c4aaecSJiri Olsa  $(call feature_check,compile-x32)
16676c4aaecSJiri Olsa  $(call feature_check,bionic)
16776c4aaecSJiri Olsa  $(call feature_check,libbabeltrace)
168e6c76d62SJiri Olsaelse
169e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
170e6c76d62SJiri Olsaendif
171e6c76d62SJiri Olsa
172e6c76d62SJiri Olsa#
173e6c76d62SJiri Olsa# Print the result of the feature test:
174e6c76d62SJiri Olsa#
175e6c76d62SJiri Olsafeature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
176e6c76d62SJiri Olsa
177e6c76d62SJiri Olsadefine feature_print_status_code
178e6c76d62SJiri Olsa  ifeq ($(feature-$(1)), 1)
179e6c76d62SJiri Olsa    MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
180e6c76d62SJiri Olsa  else
181e6c76d62SJiri Olsa    MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
182e6c76d62SJiri Olsa  endif
183e6c76d62SJiri Olsaendef
184e6c76d62SJiri Olsa
185e6c76d62SJiri Olsafeature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
186e6c76d62SJiri Olsadefine feature_print_text_code
187e6c76d62SJiri Olsa    MSG = $(shell printf '...%30s: %s' $(1) $(2))
188e6c76d62SJiri Olsaendef
189e6c76d62SJiri Olsa
190c6a5f88fSJiri Olsa#
191c6a5f88fSJiri Olsa# generates feature value assignment for name, like:
192c6a5f88fSJiri Olsa#   $(call feature_assign,dwarf) == feature-dwarf=1
193c6a5f88fSJiri Olsa#
194c6a5f88fSJiri Olsafeature_assign = feature-$(1)=$(feature-$(1))
195c6a5f88fSJiri Olsa
19613e96db6SArnaldo Carvalho de MeloFEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
197936d120dSJiri OlsaFEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
198936d120dSJiri Olsa
199936d120dSJiri Olsafeature_dump_check = $(eval $(feature_dump_check_code))
200936d120dSJiri Olsadefine feature_dump_check_code
201936d120dSJiri Olsa  ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
202936d120dSJiri Olsa    $(2) := 1
203936d120dSJiri Olsa  endif
204936d120dSJiri Olsaendef
205936d120dSJiri Olsa
206936d120dSJiri Olsa#
207936d120dSJiri Olsa# First check if any test from FEATURE_DISPLAY
208936d120dSJiri Olsa# and set feature_display := 1 if it does
209936d120dSJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
210936d120dSJiri Olsa
211936d120dSJiri Olsa#
212936d120dSJiri Olsa# Now also check if any other test changed,
213936d120dSJiri Olsa# so we force FEATURE-DUMP generation
214936d120dSJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
215e6c76d62SJiri Olsa
216e6c76d62SJiri Olsa# The $(feature_display) controls the default detection message
217e6c76d62SJiri Olsa# output. It's set if:
218e6c76d62SJiri Olsa# - detected features differes from stored features from
21913e96db6SArnaldo Carvalho de Melo#   last build (in $(FEATURE_DUMP_FILENAME) file)
220e6c76d62SJiri Olsa# - one of the $(FEATURE_DISPLAY) is not detected
221e6c76d62SJiri Olsa# - VF is enabled
222e6c76d62SJiri Olsa
223936d120dSJiri Olsaifeq ($(feature_dump_changed),1)
224936d120dSJiri Olsa  $(shell rm -f $(FEATURE_DUMP_FILENAME))
225936d120dSJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
226e6c76d62SJiri Olsaendif
227e6c76d62SJiri Olsa
2286076e2a4SArnaldo Carvalho de Melofeature_display_check = $(eval $(feature_check_display_code))
229d0018b49SJiri Olsadefine feature_check_display_code
230e6c76d62SJiri Olsa  ifneq ($(feature-$(1)), 1)
231e6c76d62SJiri Olsa    feature_display := 1
232e6c76d62SJiri Olsa  endif
233e6c76d62SJiri Olsaendef
234e6c76d62SJiri Olsa
235e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
236e6c76d62SJiri Olsa
237e6c76d62SJiri Olsaifeq ($(VF),1)
238e6c76d62SJiri Olsa  feature_display := 1
239e6c76d62SJiri Olsa  feature_verbose := 1
240e6c76d62SJiri Olsaendif
241e6c76d62SJiri Olsa
242e6c76d62SJiri Olsaifeq ($(feature_display),1)
243e6c76d62SJiri Olsa  $(info )
244e6c76d62SJiri Olsa  $(info Auto-detecting system features:)
245e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
246e6c76d62SJiri Olsa  ifneq ($(feature_verbose),1)
247e6c76d62SJiri Olsa    $(info )
248e6c76d62SJiri Olsa  endif
249e6c76d62SJiri Olsaendif
250e6c76d62SJiri Olsa
251e6c76d62SJiri Olsaifeq ($(feature_verbose),1)
252e6c76d62SJiri Olsa  TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
253e6c76d62SJiri Olsa  $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
254e6c76d62SJiri Olsa  $(info )
255e6c76d62SJiri Olsaendif
256