blob: ea83a92630c00d41ca14861e935e79a1dddd76db [file] [log] [blame]
Jiri Olsa970e87b2015-03-01 21:12:25 +01001feature_dir := $(srctree)/tools/perf/config/feature-checks
2
Jiri Olsa0afc5ca2015-03-01 21:04:01 +01003ifneq ($(OUTPUT),)
4 OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
5 $(shell mkdir -p $(OUTPUT_FEATURES))
6endif
7
8feature_check = $(eval $(feature_check_code))
9define feature_check_code
Jiri Olsa970e87b2015-03-01 21:12:25 +010010 feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
Jiri Olsa0afc5ca2015-03-01 21:04:01 +010011endef
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#
30FEATURE_TESTS = \
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 \
44 libperl \
45 libpython \
46 libpython-version \
47 libslang \
48 libunwind \
49 pthread-attr-setaffinity-np \
50 stackprotector-all \
51 timerfd \
52 libdw-dwarf-unwind \
53 zlib
54
55FEATURE_DISPLAY = \
56 dwarf \
57 glibc \
58 gtk2 \
59 libaudit \
60 libbfd \
61 libelf \
62 libnuma \
63 libperl \
64 libpython \
65 libslang \
66 libunwind \
67 libdw-dwarf-unwind \
68 zlib
69
70# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
71# If in the future we need per-feature checks/flags for features not
72# mentioned in this list we need to refactor this ;-).
73set_test_all_flags = $(eval $(set_test_all_flags_code))
74define set_test_all_flags_code
75 FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
76 FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
77endef
78
79$(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
80
81#
82# Special fast-path for the 'all features are available' case:
83#
84$(call feature_check,all,$(MSG))
85
86#
87# Just in case the build freshly failed, make sure we print the
88# feature matrix:
89#
90ifeq ($(feature-all), 1)
91 #
92 # test-all.c passed - just set all the core feature flags to 1:
93 #
94 $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
95else
Jiri Olsa970e87b2015-03-01 21:12:25 +010096 $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C $(feature_dir) $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1)
Jiri Olsa0afc5ca2015-03-01 21:04:01 +010097 $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
98endif
99
100#
101# Print the result of the feature test:
102#
103feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
104
105define feature_print_status_code
106 ifeq ($(feature-$(1)), 1)
107 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
108 else
109 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
110 endif
111endef
112
113feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
114define feature_print_text_code
115 MSG = $(shell printf '...%30s: %s' $(1) $(2))
116endef
117
118FEATURE_DUMP := $(foreach feat,$(FEATURE_DISPLAY),feature-$(feat)($(feature-$(feat))))
119FEATURE_DUMP_FILE := $(shell touch $(OUTPUT)FEATURE-DUMP; cat $(OUTPUT)FEATURE-DUMP)
120
121ifeq ($(dwarf-post-unwind),1)
122 FEATURE_DUMP += dwarf-post-unwind($(dwarf-post-unwind-text))
123endif
124
125# The $(feature_display) controls the default detection message
126# output. It's set if:
127# - detected features differes from stored features from
128# last build (in FEATURE-DUMP file)
129# - one of the $(FEATURE_DISPLAY) is not detected
130# - VF is enabled
131
132ifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)")
133 $(shell echo "$(FEATURE_DUMP)" > $(OUTPUT)FEATURE-DUMP)
134 feature_display := 1
135endif
136
137feature_display_check = $(eval $(feature_check_code))
138define feature_display_check_code
139 ifneq ($(feature-$(1)), 1)
140 feature_display := 1
141 endif
142endef
143
144$(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
145
146ifeq ($(VF),1)
147 feature_display := 1
148 feature_verbose := 1
149endif
150
151ifeq ($(feature_display),1)
152 $(info )
153 $(info Auto-detecting system features:)
154 $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
155
156 ifeq ($(dwarf-post-unwind),1)
157 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
158 endif
159
160 ifneq ($(feature_verbose),1)
161 $(info )
162 endif
163endif
164
165ifeq ($(feature_verbose),1)
166 TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
167 $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
168 $(info )
169endif