Commit | Line | Data |
---|---|---|
e6c76d62 | 1 | feature_dir := $(srctree)/tools/build/feature |
970e87b3 | 2 | |
0afc5cad | 3 | ifneq ($(OUTPUT),) |
e6c76d62 | 4 | OUTPUT_FEATURES = $(OUTPUT)feature/ |
0afc5cad JO |
5 | $(shell mkdir -p $(OUTPUT_FEATURES)) |
6 | endif | |
7 | ||
8 | feature_check = $(eval $(feature_check_code)) | |
9 | define 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 |
11 | endef |
12 | ||
13 | feature_set = $(eval $(feature_set_code)) | |
14 | define feature_set_code | |
15 | feature-$(1) := 1 | |
16 | endef | |
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 | 30 | FEATURE_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 | |
61 | FEATURE_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 | ||
72 | FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC) | |
73 | ||
74 | ifeq ($(FEATURE_TESTS),all) | |
75 | FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA) | |
76 | endif | |
77 | ||
8135c8c7 | 78 | FEATURE_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 ;-). | |
100 | set_test_all_flags = $(eval $(set_test_all_flags_code)) | |
101 | define set_test_all_flags_code | |
102 | FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1)) | |
103 | FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1)) | |
104 | endef | |
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 | # | |
117 | ifeq ($(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))) | |
76c4aaec JO |
122 | # |
123 | # test-all.c does not comprise these tests, so we need to | |
124 | # for this case to get features proper values | |
125 | # | |
126 | $(call feature_check,compile-32) | |
127 | $(call feature_check,compile-x32) | |
128 | $(call feature_check,bionic) | |
129 | $(call feature_check,libbabeltrace) | |
0afc5cad | 130 | else |
0afc5cad JO |
131 | $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat))) |
132 | endif | |
133 | ||
134 | # | |
135 | # Print the result of the feature test: | |
136 | # | |
137 | feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG)) | |
138 | ||
139 | define feature_print_status_code | |
140 | ifeq ($(feature-$(1)), 1) | |
141 | MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1)) | |
142 | else | |
143 | MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1)) | |
144 | endif | |
145 | endef | |
146 | ||
147 | feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG)) | |
148 | define feature_print_text_code | |
149 | MSG = $(shell printf '...%30s: %s' $(1) $(2)) | |
150 | endef | |
151 | ||
c6a5f88f JO |
152 | # |
153 | # generates feature value assignment for name, like: | |
154 | # $(call feature_assign,dwarf) == feature-dwarf=1 | |
155 | # | |
156 | feature_assign = feature-$(1)=$(feature-$(1)) | |
157 | ||
13e96db6 | 158 | FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER) |
936d120d JO |
159 | FEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME)) |
160 | ||
161 | feature_dump_check = $(eval $(feature_dump_check_code)) | |
162 | define feature_dump_check_code | |
163 | ifeq ($(findstring $(1),$(FEATURE_DUMP)),) | |
164 | $(2) := 1 | |
165 | endif | |
166 | endef | |
167 | ||
168 | # | |
169 | # First check if any test from FEATURE_DISPLAY | |
170 | # and set feature_display := 1 if it does | |
171 | $(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display)) | |
172 | ||
173 | # | |
174 | # Now also check if any other test changed, | |
175 | # so we force FEATURE-DUMP generation | |
176 | $(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed)) | |
0afc5cad | 177 | |
0afc5cad JO |
178 | # The $(feature_display) controls the default detection message |
179 | # output. It's set if: | |
180 | # - detected features differes from stored features from | |
13e96db6 | 181 | # last build (in $(FEATURE_DUMP_FILENAME) file) |
0afc5cad JO |
182 | # - one of the $(FEATURE_DISPLAY) is not detected |
183 | # - VF is enabled | |
184 | ||
936d120d JO |
185 | ifeq ($(feature_dump_changed),1) |
186 | $(shell rm -f $(FEATURE_DUMP_FILENAME)) | |
187 | $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME))) | |
0afc5cad JO |
188 | endif |
189 | ||
6076e2a4 | 190 | feature_display_check = $(eval $(feature_check_display_code)) |
d0018b49 | 191 | define feature_check_display_code |
0afc5cad JO |
192 | ifneq ($(feature-$(1)), 1) |
193 | feature_display := 1 | |
194 | endif | |
195 | endef | |
196 | ||
197 | $(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat))) | |
198 | ||
199 | ifeq ($(VF),1) | |
200 | feature_display := 1 | |
201 | feature_verbose := 1 | |
202 | endif | |
203 | ||
204 | ifeq ($(feature_display),1) | |
205 | $(info ) | |
206 | $(info Auto-detecting system features:) | |
207 | $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),)) | |
0afc5cad JO |
208 | ifneq ($(feature_verbose),1) |
209 | $(info ) | |
210 | endif | |
211 | endif | |
212 | ||
213 | ifeq ($(feature_verbose),1) | |
214 | TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS)) | |
215 | $(foreach feat,$(TMP),$(call feature_print_status,$(feat),)) | |
216 | $(info ) | |
217 | endif |