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