xref: /openbmc/linux/tools/build/Makefile.feature (revision 87095f7d)
1e6c76d62SJiri Olsafeature_dir := $(srctree)/tools/build/feature
2e6c76d62SJiri Olsa
3e6c76d62SJiri Olsaifneq ($(OUTPUT),)
4e6c76d62SJiri Olsa  OUTPUT_FEATURES = $(OUTPUT)feature/
5e6c76d62SJiri Olsa  $(shell mkdir -p $(OUTPUT_FEATURES))
6e6c76d62SJiri Olsaendif
7e6c76d62SJiri Olsa
8e6c76d62SJiri Olsafeature_check = $(eval $(feature_check_code))
9e6c76d62SJiri Olsadefine feature_check_code
1087095f7dSWang Nan  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) 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)
11e6c76d62SJiri Olsaendef
12e6c76d62SJiri Olsa
13e6c76d62SJiri Olsafeature_set = $(eval $(feature_set_code))
14e6c76d62SJiri Olsadefine feature_set_code
15e6c76d62SJiri Olsa  feature-$(1) := 1
16e6c76d62SJiri Olsaendef
17e6c76d62SJiri Olsa
18e6c76d62SJiri Olsa#
19e6c76d62SJiri Olsa# Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
20e6c76d62SJiri Olsa#
21e6c76d62SJiri Olsa
22e6c76d62SJiri Olsa#
23e6c76d62SJiri Olsa# Note that this is not a complete list of all feature tests, just
24e6c76d62SJiri Olsa# those that are typically built on a fully configured system.
25e6c76d62SJiri Olsa#
26e6c76d62SJiri Olsa# [ Feature tests not mentioned here have to be built explicitly in
27e6c76d62SJiri Olsa#   the rule that uses them - an example for that is the 'bionic'
28e6c76d62SJiri Olsa#   feature check. ]
29e6c76d62SJiri Olsa#
309fd4186aSWang NanFEATURE_TESTS_BASIC :=			\
31e6c76d62SJiri Olsa	backtrace			\
32e6c76d62SJiri Olsa	dwarf				\
33bd0419e2SArnaldo Carvalho de Melo	dwarf_getlocations		\
34e6c76d62SJiri Olsa	fortify-source			\
35e6c76d62SJiri Olsa	sync-compare-and-swap		\
36e6c76d62SJiri Olsa	glibc				\
37e6c76d62SJiri Olsa	gtk2				\
38e6c76d62SJiri Olsa	gtk2-infobar			\
39e6c76d62SJiri Olsa	libaudit			\
40e6c76d62SJiri Olsa	libbfd				\
41e6c76d62SJiri Olsa	libelf				\
42e6c76d62SJiri Olsa	libelf-getphdrnum		\
431c1a3a47SArnaldo Carvalho de Melo	libelf-gelf_getnote		\
442492c465SArnaldo Carvalho de Melo	libelf-getshdrstrndx		\
45e6c76d62SJiri Olsa	libelf-mmap			\
46e6c76d62SJiri Olsa	libnuma				\
47f8ac8606SArnaldo Carvalho de Melo	numa_num_possible_cpus		\
48e6c76d62SJiri Olsa	libperl				\
49e6c76d62SJiri Olsa	libpython			\
50e6c76d62SJiri Olsa	libpython-version		\
51e6c76d62SJiri Olsa	libslang			\
528ee46460SStephane Eranian	libcrypto			\
53e6c76d62SJiri Olsa	libunwind			\
54b1d96000SHe Kuang	libunwind-x86			\
55b1d96000SHe Kuang	libunwind-x86_64		\
56b1d96000SHe Kuang	libunwind-arm			\
57b1d96000SHe Kuang	libunwind-aarch64		\
58e6c76d62SJiri Olsa	pthread-attr-setaffinity-np	\
59e6c76d62SJiri Olsa	stackprotector-all		\
60e6c76d62SJiri Olsa	timerfd				\
61e6c76d62SJiri Olsa	libdw-dwarf-unwind		\
626c6f0f61SJiri Olsa	zlib				\
63b0063dbfSArnaldo Carvalho de Melo	lzma				\
64ed63f34cSWang Nan	get_cpuid			\
65e26e63beSMasami Hiramatsu	bpf				\
66e26e63beSMasami Hiramatsu	sdt
67e6c76d62SJiri Olsa
689fd4186aSWang Nan# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
699fd4186aSWang Nan# of all feature tests
709fd4186aSWang NanFEATURE_TESTS_EXTRA :=			\
719fd4186aSWang Nan	bionic				\
729fd4186aSWang Nan	compile-32			\
739fd4186aSWang Nan	compile-x32			\
749fd4186aSWang Nan	cplus-demangle			\
759fd4186aSWang Nan	hello				\
769fd4186aSWang Nan	libbabeltrace			\
779fd4186aSWang Nan	liberty				\
789fd4186aSWang Nan	liberty-z			\
79f9be7eefSHe Kuang	libunwind-debug-frame		\
80f9be7eefSHe Kuang	libunwind-debug-frame-arm	\
81f9be7eefSHe Kuang	libunwind-debug-frame-aarch64
829fd4186aSWang Nan
839fd4186aSWang NanFEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
849fd4186aSWang Nan
859fd4186aSWang Nanifeq ($(FEATURE_TESTS),all)
869fd4186aSWang Nan  FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
879fd4186aSWang Nanendif
889fd4186aSWang Nan
898135c8c7SWang NanFEATURE_DISPLAY ?=			\
90e6c76d62SJiri Olsa	dwarf				\
91bd0419e2SArnaldo Carvalho de Melo	dwarf_getlocations		\
92e6c76d62SJiri Olsa	glibc				\
93e6c76d62SJiri Olsa	gtk2				\
94e6c76d62SJiri Olsa	libaudit			\
95e6c76d62SJiri Olsa	libbfd				\
96e6c76d62SJiri Olsa	libelf				\
97e6c76d62SJiri Olsa	libnuma				\
98f8ac8606SArnaldo Carvalho de Melo	numa_num_possible_cpus		\
99e6c76d62SJiri Olsa	libperl				\
100e6c76d62SJiri Olsa	libpython			\
101e6c76d62SJiri Olsa	libslang			\
1028ee46460SStephane Eranian	libcrypto			\
103e6c76d62SJiri Olsa	libunwind			\
104e6c76d62SJiri Olsa	libdw-dwarf-unwind		\
1056c6f0f61SJiri Olsa	zlib				\
106b0063dbfSArnaldo Carvalho de Melo	lzma				\
107ed63f34cSWang Nan	get_cpuid			\
108ed63f34cSWang Nan	bpf
109e6c76d62SJiri Olsa
110e6c76d62SJiri Olsa# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
111e6c76d62SJiri Olsa# If in the future we need per-feature checks/flags for features not
112e6c76d62SJiri Olsa# mentioned in this list we need to refactor this ;-).
113e6c76d62SJiri Olsaset_test_all_flags = $(eval $(set_test_all_flags_code))
114e6c76d62SJiri Olsadefine set_test_all_flags_code
115e6c76d62SJiri Olsa  FEATURE_CHECK_CFLAGS-all  += $(FEATURE_CHECK_CFLAGS-$(1))
116e6c76d62SJiri Olsa  FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
117e6c76d62SJiri Olsaendef
118e6c76d62SJiri Olsa
119e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
120e6c76d62SJiri Olsa
121e6c76d62SJiri Olsa#
122e6c76d62SJiri Olsa# Special fast-path for the 'all features are available' case:
123e6c76d62SJiri Olsa#
124e6c76d62SJiri Olsa$(call feature_check,all,$(MSG))
125e6c76d62SJiri Olsa
126e6c76d62SJiri Olsa#
127e6c76d62SJiri Olsa# Just in case the build freshly failed, make sure we print the
128e6c76d62SJiri Olsa# feature matrix:
129e6c76d62SJiri Olsa#
130e6c76d62SJiri Olsaifeq ($(feature-all), 1)
131e6c76d62SJiri Olsa  #
132e6c76d62SJiri Olsa  # test-all.c passed - just set all the core feature flags to 1:
133e6c76d62SJiri Olsa  #
134e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
13576c4aaecSJiri Olsa  #
13676c4aaecSJiri Olsa  # test-all.c does not comprise these tests, so we need to
13776c4aaecSJiri Olsa  # for this case to get features proper values
13876c4aaecSJiri Olsa  #
13976c4aaecSJiri Olsa  $(call feature_check,compile-32)
14076c4aaecSJiri Olsa  $(call feature_check,compile-x32)
14176c4aaecSJiri Olsa  $(call feature_check,bionic)
14276c4aaecSJiri Olsa  $(call feature_check,libbabeltrace)
143e6c76d62SJiri Olsaelse
144e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
145e6c76d62SJiri Olsaendif
146e6c76d62SJiri Olsa
147e6c76d62SJiri Olsa#
148e6c76d62SJiri Olsa# Print the result of the feature test:
149e6c76d62SJiri Olsa#
150e6c76d62SJiri Olsafeature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
151e6c76d62SJiri Olsa
152e6c76d62SJiri Olsadefine feature_print_status_code
153e6c76d62SJiri Olsa  ifeq ($(feature-$(1)), 1)
154e6c76d62SJiri Olsa    MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
155e6c76d62SJiri Olsa  else
156e6c76d62SJiri Olsa    MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
157e6c76d62SJiri Olsa  endif
158e6c76d62SJiri Olsaendef
159e6c76d62SJiri Olsa
160e6c76d62SJiri Olsafeature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
161e6c76d62SJiri Olsadefine feature_print_text_code
162e6c76d62SJiri Olsa    MSG = $(shell printf '...%30s: %s' $(1) $(2))
163e6c76d62SJiri Olsaendef
164e6c76d62SJiri Olsa
165c6a5f88fSJiri Olsa#
166c6a5f88fSJiri Olsa# generates feature value assignment for name, like:
167c6a5f88fSJiri Olsa#   $(call feature_assign,dwarf) == feature-dwarf=1
168c6a5f88fSJiri Olsa#
169c6a5f88fSJiri Olsafeature_assign = feature-$(1)=$(feature-$(1))
170c6a5f88fSJiri Olsa
17113e96db6SArnaldo Carvalho de MeloFEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
172936d120dSJiri OlsaFEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
173936d120dSJiri Olsa
174936d120dSJiri Olsafeature_dump_check = $(eval $(feature_dump_check_code))
175936d120dSJiri Olsadefine feature_dump_check_code
176936d120dSJiri Olsa  ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
177936d120dSJiri Olsa    $(2) := 1
178936d120dSJiri Olsa  endif
179936d120dSJiri Olsaendef
180936d120dSJiri Olsa
181936d120dSJiri Olsa#
182936d120dSJiri Olsa# First check if any test from FEATURE_DISPLAY
183936d120dSJiri Olsa# and set feature_display := 1 if it does
184936d120dSJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
185936d120dSJiri Olsa
186936d120dSJiri Olsa#
187936d120dSJiri Olsa# Now also check if any other test changed,
188936d120dSJiri Olsa# so we force FEATURE-DUMP generation
189936d120dSJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
190e6c76d62SJiri Olsa
191e6c76d62SJiri Olsa# The $(feature_display) controls the default detection message
192e6c76d62SJiri Olsa# output. It's set if:
193e6c76d62SJiri Olsa# - detected features differes from stored features from
19413e96db6SArnaldo Carvalho de Melo#   last build (in $(FEATURE_DUMP_FILENAME) file)
195e6c76d62SJiri Olsa# - one of the $(FEATURE_DISPLAY) is not detected
196e6c76d62SJiri Olsa# - VF is enabled
197e6c76d62SJiri Olsa
198936d120dSJiri Olsaifeq ($(feature_dump_changed),1)
199936d120dSJiri Olsa  $(shell rm -f $(FEATURE_DUMP_FILENAME))
200936d120dSJiri Olsa  $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
201e6c76d62SJiri Olsaendif
202e6c76d62SJiri Olsa
2036076e2a4SArnaldo Carvalho de Melofeature_display_check = $(eval $(feature_check_display_code))
204d0018b49SJiri Olsadefine feature_check_display_code
205e6c76d62SJiri Olsa  ifneq ($(feature-$(1)), 1)
206e6c76d62SJiri Olsa    feature_display := 1
207e6c76d62SJiri Olsa  endif
208e6c76d62SJiri Olsaendef
209e6c76d62SJiri Olsa
210e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
211e6c76d62SJiri Olsa
212e6c76d62SJiri Olsaifeq ($(VF),1)
213e6c76d62SJiri Olsa  feature_display := 1
214e6c76d62SJiri Olsa  feature_verbose := 1
215e6c76d62SJiri Olsaendif
216e6c76d62SJiri Olsa
217e6c76d62SJiri Olsaifeq ($(feature_display),1)
218e6c76d62SJiri Olsa  $(info )
219e6c76d62SJiri Olsa  $(info Auto-detecting system features:)
220e6c76d62SJiri Olsa  $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
221e6c76d62SJiri Olsa  ifneq ($(feature_verbose),1)
222e6c76d62SJiri Olsa    $(info )
223e6c76d62SJiri Olsa  endif
224e6c76d62SJiri Olsaendif
225e6c76d62SJiri Olsa
226e6c76d62SJiri Olsaifeq ($(feature_verbose),1)
227e6c76d62SJiri Olsa  TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
228e6c76d62SJiri Olsa  $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
229e6c76d62SJiri Olsa  $(info )
230e6c76d62SJiri Olsaendif
231