tools build: Check basic headers for test-compile feature checker
[deliverable/linux.git] / tools / build / Makefile.feature
CommitLineData
e6c76d62 1feature_dir := $(srctree)/tools/build/feature
970e87b3 2
0afc5cad 3ifneq ($(OUTPUT),)
e6c76d62 4 OUTPUT_FEATURES = $(OUTPUT)feature/
0afc5cad
JO
5 $(shell mkdir -p $(OUTPUT_FEATURES))
6endif
7
8feature_check = $(eval $(feature_check_code))
9define feature_check_code
1925459b 10 feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
0afc5cad
JO
11endef
12
13feature_set = $(eval $(feature_set_code))
14define feature_set_code
15 feature-$(1) := 1
16endef
17
18#
19# Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
20#
21
22#
23# Note that this is not a complete list of all feature tests, just
24# those that are typically built on a fully configured system.
25#
26# [ Feature tests not mentioned here have to be built explicitly in
27# the rule that uses them - an example for that is the 'bionic'
28# feature check. ]
29#
9fd4186a 30FEATURE_TESTS_BASIC := \
0afc5cad
JO
31 backtrace \
32 dwarf \
33 fortify-source \
34 sync-compare-and-swap \
35 glibc \
36 gtk2 \
37 gtk2-infobar \
38 libaudit \
39 libbfd \
40 libelf \
41 libelf-getphdrnum \
42 libelf-mmap \
43 libnuma \
f8ac8606 44 numa_num_possible_cpus \
0afc5cad
JO
45 libperl \
46 libpython \
47 libpython-version \
48 libslang \
49 libunwind \
50 pthread-attr-setaffinity-np \
51 stackprotector-all \
52 timerfd \
53 libdw-dwarf-unwind \
6c6f0f61 54 zlib \
b0063dbf 55 lzma \
ed63f34c
WN
56 get_cpuid \
57 bpf
0afc5cad 58
9fd4186a
WN
59# FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
60# of all feature tests
61FEATURE_TESTS_EXTRA := \
62 bionic \
63 compile-32 \
64 compile-x32 \
65 cplus-demangle \
66 hello \
67 libbabeltrace \
68 liberty \
69 liberty-z \
70 libunwind-debug-frame
71
72FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
73
74ifeq ($(FEATURE_TESTS),all)
75 FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
76endif
77
8135c8c7 78FEATURE_DISPLAY ?= \
0afc5cad
JO
79 dwarf \
80 glibc \
81 gtk2 \
82 libaudit \
83 libbfd \
84 libelf \
85 libnuma \
f8ac8606 86 numa_num_possible_cpus \
0afc5cad
JO
87 libperl \
88 libpython \
89 libslang \
90 libunwind \
91 libdw-dwarf-unwind \
6c6f0f61 92 zlib \
b0063dbf 93 lzma \
ed63f34c
WN
94 get_cpuid \
95 bpf
0afc5cad
JO
96
97# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
98# If in the future we need per-feature checks/flags for features not
99# mentioned in this list we need to refactor this ;-).
100set_test_all_flags = $(eval $(set_test_all_flags_code))
101define set_test_all_flags_code
102 FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
103 FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
104endef
105
106$(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
107
108#
109# Special fast-path for the 'all features are available' case:
110#
111$(call feature_check,all,$(MSG))
112
113#
114# Just in case the build freshly failed, make sure we print the
115# feature matrix:
116#
117ifeq ($(feature-all), 1)
118 #
119 # test-all.c passed - just set all the core feature flags to 1:
120 #
121 $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
122else
0afc5cad
JO
123 $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
124endif
125
126#
127# Print the result of the feature test:
128#
129feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
130
131define feature_print_status_code
132 ifeq ($(feature-$(1)), 1)
133 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
134 else
135 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
136 endif
137endef
138
139feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
140define feature_print_text_code
141 MSG = $(shell printf '...%30s: %s' $(1) $(2))
142endef
143
c6a5f88f
JO
144#
145# generates feature value assignment for name, like:
146# $(call feature_assign,dwarf) == feature-dwarf=1
147#
148feature_assign = feature-$(1)=$(feature-$(1))
149
13e96db6 150FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
936d120d
JO
151FEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
152
153feature_dump_check = $(eval $(feature_dump_check_code))
154define feature_dump_check_code
155 ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
156 $(2) := 1
157 endif
158endef
159
160#
161# First check if any test from FEATURE_DISPLAY
162# and set feature_display := 1 if it does
163$(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
164
165#
166# Now also check if any other test changed,
167# so we force FEATURE-DUMP generation
168$(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
0afc5cad 169
0afc5cad
JO
170# The $(feature_display) controls the default detection message
171# output. It's set if:
172# - detected features differes from stored features from
13e96db6 173# last build (in $(FEATURE_DUMP_FILENAME) file)
0afc5cad
JO
174# - one of the $(FEATURE_DISPLAY) is not detected
175# - VF is enabled
176
936d120d
JO
177ifeq ($(feature_dump_changed),1)
178 $(shell rm -f $(FEATURE_DUMP_FILENAME))
179 $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
0afc5cad
JO
180endif
181
6076e2a4 182feature_display_check = $(eval $(feature_check_display_code))
d0018b49 183define feature_check_display_code
0afc5cad
JO
184 ifneq ($(feature-$(1)), 1)
185 feature_display := 1
186 endif
187endef
188
189$(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
190
191ifeq ($(VF),1)
192 feature_display := 1
193 feature_verbose := 1
194endif
195
196ifeq ($(feature_display),1)
197 $(info )
198 $(info Auto-detecting system features:)
199 $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
0afc5cad
JO
200 ifneq ($(feature_verbose),1)
201 $(info )
202 endif
203endif
204
205ifeq ($(feature_verbose),1)
206 TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
207 $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
208 $(info )
209endif
This page took 0.078425 seconds and 5 git commands to generate.