GNU Linux-libre 4.14.266-gnu1
[releases.git] / tools / build / Makefile.feature
1 feature_dir := $(srctree)/tools/build/feature
2
3 ifneq ($(OUTPUT),)
4   OUTPUT_FEATURES = $(OUTPUT)feature/
5   $(shell mkdir -p $(OUTPUT_FEATURES))
6 endif
7
8 feature_check = $(eval $(feature_check_code))
9 define feature_check_code
10   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)
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 #
30 FEATURE_TESTS_BASIC :=                  \
31         backtrace                       \
32         dwarf                           \
33         dwarf_getlocations              \
34         eventfd                         \
35         fortify-source                  \
36         sync-compare-and-swap           \
37         get_current_dir_name            \
38         gettid                          \
39         glibc                           \
40         gtk2                            \
41         gtk2-infobar                    \
42         libaudit                        \
43         libbfd                          \
44         libelf                          \
45         libelf-getphdrnum               \
46         libelf-gelf_getnote             \
47         libelf-getshdrstrndx            \
48         libelf-mmap                     \
49         libnuma                         \
50         numa_num_possible_cpus          \
51         libperl                         \
52         libpython                       \
53         libpython-version               \
54         libslang                        \
55         libcrypto                       \
56         libunwind                       \
57         libunwind-x86                   \
58         libunwind-x86_64                \
59         libunwind-arm                   \
60         libunwind-aarch64               \
61         pthread-attr-setaffinity-np     \
62         pthread-barrier                 \
63         stackprotector-all              \
64         timerfd                         \
65         libdw-dwarf-unwind              \
66         zlib                            \
67         lzma                            \
68         get_cpuid                       \
69         bpf                             \
70         sched_getcpu                    \
71         sdt                             \
72         setns
73
74 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
75 # of all feature tests
76 FEATURE_TESTS_EXTRA :=                  \
77          bionic                         \
78          compile-32                     \
79          compile-x32                    \
80          cplus-demangle                 \
81          hello                          \
82          libbabeltrace                  \
83          liberty                        \
84          liberty-z                      \
85          libunwind-debug-frame          \
86          libunwind-debug-frame-arm      \
87          libunwind-debug-frame-aarch64
88
89 FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
90
91 ifeq ($(FEATURE_TESTS),all)
92   FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
93 endif
94
95 FEATURE_DISPLAY ?=              \
96          dwarf                  \
97          dwarf_getlocations     \
98          glibc                  \
99          gtk2                   \
100          libaudit               \
101          libbfd                 \
102          libelf                 \
103          libnuma                \
104          numa_num_possible_cpus \
105          libperl                \
106          libpython              \
107          libslang               \
108          libcrypto              \
109          libunwind              \
110          libdw-dwarf-unwind     \
111          zlib                   \
112          lzma                   \
113          get_cpuid              \
114          bpf
115
116 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
117 # If in the future we need per-feature checks/flags for features not
118 # mentioned in this list we need to refactor this ;-).
119 set_test_all_flags = $(eval $(set_test_all_flags_code))
120 define set_test_all_flags_code
121   FEATURE_CHECK_CFLAGS-all  += $(FEATURE_CHECK_CFLAGS-$(1))
122   FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
123 endef
124
125 $(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
126
127 #
128 # Special fast-path for the 'all features are available' case:
129 #
130 $(call feature_check,all,$(MSG))
131
132 #
133 # Just in case the build freshly failed, make sure we print the
134 # feature matrix:
135 #
136 ifeq ($(feature-all), 1)
137   #
138   # test-all.c passed - just set all the core feature flags to 1:
139   #
140   $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
141   #
142   # test-all.c does not comprise these tests, so we need to
143   # for this case to get features proper values
144   #
145   $(call feature_check,compile-32)
146   $(call feature_check,compile-x32)
147   $(call feature_check,bionic)
148   $(call feature_check,libbabeltrace)
149 else
150   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
151 endif
152
153 #
154 # Print the result of the feature test:
155 #
156 feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
157
158 define feature_print_status_code
159   ifeq ($(feature-$(1)), 1)
160     MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
161   else
162     MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
163   endif
164 endef
165
166 feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
167 define feature_print_text_code
168     MSG = $(shell printf '...%30s: %s' $(1) $(2))
169 endef
170
171 #
172 # generates feature value assignment for name, like:
173 #   $(call feature_assign,dwarf) == feature-dwarf=1
174 #
175 feature_assign = feature-$(1)=$(feature-$(1))
176
177 FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
178 FEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
179
180 feature_dump_check = $(eval $(feature_dump_check_code))
181 define feature_dump_check_code
182   ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
183     $(2) := 1
184   endif
185 endef
186
187 #
188 # First check if any test from FEATURE_DISPLAY
189 # and set feature_display := 1 if it does
190 $(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
191
192 #
193 # Now also check if any other test changed,
194 # so we force FEATURE-DUMP generation
195 $(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
196
197 # The $(feature_display) controls the default detection message
198 # output. It's set if:
199 # - detected features differes from stored features from
200 #   last build (in $(FEATURE_DUMP_FILENAME) file)
201 # - one of the $(FEATURE_DISPLAY) is not detected
202 # - VF is enabled
203
204 ifeq ($(feature_dump_changed),1)
205   $(shell rm -f $(FEATURE_DUMP_FILENAME))
206   $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
207 endif
208
209 feature_display_check = $(eval $(feature_check_display_code))
210 define feature_check_display_code
211   ifneq ($(feature-$(1)), 1)
212     feature_display := 1
213   endif
214 endef
215
216 $(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
217
218 ifeq ($(VF),1)
219   feature_display := 1
220   feature_verbose := 1
221 endif
222
223 ifeq ($(feature_display),1)
224   $(info )
225   $(info Auto-detecting system features:)
226   $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
227   ifneq ($(feature_verbose),1)
228     $(info )
229   endif
230 endif
231
232 ifeq ($(feature_verbose),1)
233   TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
234   $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
235   $(info )
236 endif