1e6c76d62SJiri Olsafeature_dir := $(srctree)/tools/build/feature 2e6c76d62SJiri Olsa 3e6c76d62SJiri Olsaifneq ($(OUTPUT),) 4e6c76d62SJiri Olsa OUTPUT_FEATURES = $(OUTPUT)feature/ 5e6c76d62SJiri Olsa $(shell mkdir -p $(OUTPUT_FEATURES)) 6e6c76d62SJiri Olsaendif 7e6c76d62SJiri Olsa 8e6c76d62SJiri Olsafeature_check = $(eval $(feature_check_code)) 9e6c76d62SJiri Olsadefine feature_check_code 10e6c76d62SJiri Olsa 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) 11e6c76d62SJiri Olsaendef 12e6c76d62SJiri Olsa 13e6c76d62SJiri Olsafeature_set = $(eval $(feature_set_code)) 14e6c76d62SJiri Olsadefine feature_set_code 15e6c76d62SJiri Olsa feature-$(1) := 1 16e6c76d62SJiri Olsaendef 17e6c76d62SJiri Olsa 18e6c76d62SJiri Olsa# 19e6c76d62SJiri Olsa# Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output: 20e6c76d62SJiri Olsa# 21e6c76d62SJiri Olsa 22e6c76d62SJiri Olsa# 23e6c76d62SJiri Olsa# Note that this is not a complete list of all feature tests, just 24e6c76d62SJiri Olsa# those that are typically built on a fully configured system. 25e6c76d62SJiri Olsa# 26e6c76d62SJiri Olsa# [ Feature tests not mentioned here have to be built explicitly in 27e6c76d62SJiri Olsa# the rule that uses them - an example for that is the 'bionic' 28e6c76d62SJiri Olsa# feature check. ] 29e6c76d62SJiri Olsa# 308135c8c7SWang NanFEATURE_TESTS ?= \ 31e6c76d62SJiri Olsa backtrace \ 32e6c76d62SJiri Olsa dwarf \ 33e6c76d62SJiri Olsa fortify-source \ 34e6c76d62SJiri Olsa sync-compare-and-swap \ 35e6c76d62SJiri Olsa glibc \ 36e6c76d62SJiri Olsa gtk2 \ 37e6c76d62SJiri Olsa gtk2-infobar \ 38e6c76d62SJiri Olsa libaudit \ 39e6c76d62SJiri Olsa libbfd \ 40e6c76d62SJiri Olsa libelf \ 41e6c76d62SJiri Olsa libelf-getphdrnum \ 42e6c76d62SJiri Olsa libelf-mmap \ 43e6c76d62SJiri Olsa libnuma \ 44f8ac8606SArnaldo Carvalho de Melo numa_num_possible_cpus \ 45e6c76d62SJiri Olsa libperl \ 46e6c76d62SJiri Olsa libpython \ 47e6c76d62SJiri Olsa libpython-version \ 48e6c76d62SJiri Olsa libslang \ 49e6c76d62SJiri Olsa libunwind \ 50e6c76d62SJiri Olsa pthread-attr-setaffinity-np \ 51e6c76d62SJiri Olsa stackprotector-all \ 52e6c76d62SJiri Olsa timerfd \ 53e6c76d62SJiri Olsa libdw-dwarf-unwind \ 546c6f0f61SJiri Olsa zlib \ 556c6f0f61SJiri Olsa lzma 56e6c76d62SJiri Olsa 578135c8c7SWang NanFEATURE_DISPLAY ?= \ 58e6c76d62SJiri Olsa dwarf \ 59e6c76d62SJiri Olsa glibc \ 60e6c76d62SJiri Olsa gtk2 \ 61e6c76d62SJiri Olsa libaudit \ 62e6c76d62SJiri Olsa libbfd \ 63e6c76d62SJiri Olsa libelf \ 64e6c76d62SJiri Olsa libnuma \ 65f8ac8606SArnaldo Carvalho de Melo numa_num_possible_cpus \ 66e6c76d62SJiri Olsa libperl \ 67e6c76d62SJiri Olsa libpython \ 68e6c76d62SJiri Olsa libslang \ 69e6c76d62SJiri Olsa libunwind \ 70e6c76d62SJiri Olsa libdw-dwarf-unwind \ 716c6f0f61SJiri Olsa zlib \ 726c6f0f61SJiri Olsa lzma 73e6c76d62SJiri Olsa 74e6c76d62SJiri Olsa# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. 75e6c76d62SJiri Olsa# If in the future we need per-feature checks/flags for features not 76e6c76d62SJiri Olsa# mentioned in this list we need to refactor this ;-). 77e6c76d62SJiri Olsaset_test_all_flags = $(eval $(set_test_all_flags_code)) 78e6c76d62SJiri Olsadefine set_test_all_flags_code 79e6c76d62SJiri Olsa FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1)) 80e6c76d62SJiri Olsa FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1)) 81e6c76d62SJiri Olsaendef 82e6c76d62SJiri Olsa 83e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat))) 84e6c76d62SJiri Olsa 85e6c76d62SJiri Olsa# 86e6c76d62SJiri Olsa# Special fast-path for the 'all features are available' case: 87e6c76d62SJiri Olsa# 88e6c76d62SJiri Olsa$(call feature_check,all,$(MSG)) 89e6c76d62SJiri Olsa 90e6c76d62SJiri Olsa# 91e6c76d62SJiri Olsa# Just in case the build freshly failed, make sure we print the 92e6c76d62SJiri Olsa# feature matrix: 93e6c76d62SJiri Olsa# 94e6c76d62SJiri Olsaifeq ($(feature-all), 1) 95e6c76d62SJiri Olsa # 96e6c76d62SJiri Olsa # test-all.c passed - just set all the core feature flags to 1: 97e6c76d62SJiri Olsa # 98e6c76d62SJiri Olsa $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat))) 99e6c76d62SJiri Olsaelse 100e6c76d62SJiri Olsa $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C $(feature_dir) $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1) 101e6c76d62SJiri Olsa $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat))) 102e6c76d62SJiri Olsaendif 103e6c76d62SJiri Olsa 104e6c76d62SJiri Olsa# 105e6c76d62SJiri Olsa# Print the result of the feature test: 106e6c76d62SJiri Olsa# 107e6c76d62SJiri Olsafeature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG)) 108e6c76d62SJiri Olsa 109e6c76d62SJiri Olsadefine feature_print_status_code 110e6c76d62SJiri Olsa ifeq ($(feature-$(1)), 1) 111e6c76d62SJiri Olsa MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1)) 112e6c76d62SJiri Olsa else 113e6c76d62SJiri Olsa MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1)) 114e6c76d62SJiri Olsa endif 115e6c76d62SJiri Olsaendef 116e6c76d62SJiri Olsa 117e6c76d62SJiri Olsafeature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG)) 118e6c76d62SJiri Olsadefine feature_print_text_code 119e6c76d62SJiri Olsa MSG = $(shell printf '...%30s: %s' $(1) $(2)) 120e6c76d62SJiri Olsaendef 121e6c76d62SJiri Olsa 122e6c76d62SJiri OlsaFEATURE_DUMP := $(foreach feat,$(FEATURE_DISPLAY),feature-$(feat)($(feature-$(feat)))) 123e6c76d62SJiri OlsaFEATURE_DUMP_FILE := $(shell touch $(OUTPUT)FEATURE-DUMP; cat $(OUTPUT)FEATURE-DUMP) 124e6c76d62SJiri Olsa 125e6c76d62SJiri Olsaifeq ($(dwarf-post-unwind),1) 126e6c76d62SJiri Olsa FEATURE_DUMP += dwarf-post-unwind($(dwarf-post-unwind-text)) 127e6c76d62SJiri Olsaendif 128e6c76d62SJiri Olsa 129e6c76d62SJiri Olsa# The $(feature_display) controls the default detection message 130e6c76d62SJiri Olsa# output. It's set if: 131e6c76d62SJiri Olsa# - detected features differes from stored features from 132e6c76d62SJiri Olsa# last build (in FEATURE-DUMP file) 133e6c76d62SJiri Olsa# - one of the $(FEATURE_DISPLAY) is not detected 134e6c76d62SJiri Olsa# - VF is enabled 135e6c76d62SJiri Olsa 136e6c76d62SJiri Olsaifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)") 137e6c76d62SJiri Olsa $(shell echo "$(FEATURE_DUMP)" > $(OUTPUT)FEATURE-DUMP) 138e6c76d62SJiri Olsa feature_display := 1 139e6c76d62SJiri Olsaendif 140e6c76d62SJiri Olsa 141e6c76d62SJiri Olsafeature_display_check = $(eval $(feature_check_code)) 142e6c76d62SJiri Olsadefine feature_display_check_code 143e6c76d62SJiri Olsa ifneq ($(feature-$(1)), 1) 144e6c76d62SJiri Olsa feature_display := 1 145e6c76d62SJiri Olsa endif 146e6c76d62SJiri Olsaendef 147e6c76d62SJiri Olsa 148e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat))) 149e6c76d62SJiri Olsa 150e6c76d62SJiri Olsaifeq ($(VF),1) 151e6c76d62SJiri Olsa feature_display := 1 152e6c76d62SJiri Olsa feature_verbose := 1 153e6c76d62SJiri Olsaendif 154e6c76d62SJiri Olsa 155e6c76d62SJiri Olsaifeq ($(feature_display),1) 156e6c76d62SJiri Olsa $(info ) 157e6c76d62SJiri Olsa $(info Auto-detecting system features:) 158e6c76d62SJiri Olsa $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),)) 159e6c76d62SJiri Olsa 160e6c76d62SJiri Olsa ifeq ($(dwarf-post-unwind),1) 161e6c76d62SJiri Olsa $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) 162e6c76d62SJiri Olsa endif 163e6c76d62SJiri Olsa 164e6c76d62SJiri Olsa ifneq ($(feature_verbose),1) 165e6c76d62SJiri Olsa $(info ) 166e6c76d62SJiri Olsa endif 167e6c76d62SJiri Olsaendif 168e6c76d62SJiri Olsa 169e6c76d62SJiri Olsaifeq ($(feature_verbose),1) 170e6c76d62SJiri Olsa TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS)) 171e6c76d62SJiri Olsa $(foreach feat,$(TMP),$(call feature_print_status,$(feat),)) 172e6c76d62SJiri Olsa $(info ) 173e6c76d62SJiri Olsaendif 174