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 101925459bSJosh Poimboeuf 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) 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 \ 55b0063dbfSArnaldo Carvalho de Melo lzma \ 56ed63f34cSWang Nan get_cpuid \ 57ed63f34cSWang Nan bpf 58e6c76d62SJiri Olsa 598135c8c7SWang NanFEATURE_DISPLAY ?= \ 60e6c76d62SJiri Olsa dwarf \ 61e6c76d62SJiri Olsa glibc \ 62e6c76d62SJiri Olsa gtk2 \ 63e6c76d62SJiri Olsa libaudit \ 64e6c76d62SJiri Olsa libbfd \ 65e6c76d62SJiri Olsa libelf \ 66e6c76d62SJiri Olsa libnuma \ 67f8ac8606SArnaldo Carvalho de Melo numa_num_possible_cpus \ 68e6c76d62SJiri Olsa libperl \ 69e6c76d62SJiri Olsa libpython \ 70e6c76d62SJiri Olsa libslang \ 71e6c76d62SJiri Olsa libunwind \ 72e6c76d62SJiri Olsa libdw-dwarf-unwind \ 736c6f0f61SJiri Olsa zlib \ 74b0063dbfSArnaldo Carvalho de Melo lzma \ 75ed63f34cSWang Nan get_cpuid \ 76ed63f34cSWang Nan bpf 77e6c76d62SJiri Olsa 78e6c76d62SJiri Olsa# Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features. 79e6c76d62SJiri Olsa# If in the future we need per-feature checks/flags for features not 80e6c76d62SJiri Olsa# mentioned in this list we need to refactor this ;-). 81e6c76d62SJiri Olsaset_test_all_flags = $(eval $(set_test_all_flags_code)) 82e6c76d62SJiri Olsadefine set_test_all_flags_code 83e6c76d62SJiri Olsa FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1)) 84e6c76d62SJiri Olsa FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1)) 85e6c76d62SJiri Olsaendef 86e6c76d62SJiri Olsa 87e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat))) 88e6c76d62SJiri Olsa 89e6c76d62SJiri Olsa# 90e6c76d62SJiri Olsa# Special fast-path for the 'all features are available' case: 91e6c76d62SJiri Olsa# 92e6c76d62SJiri Olsa$(call feature_check,all,$(MSG)) 93e6c76d62SJiri Olsa 94e6c76d62SJiri Olsa# 95e6c76d62SJiri Olsa# Just in case the build freshly failed, make sure we print the 96e6c76d62SJiri Olsa# feature matrix: 97e6c76d62SJiri Olsa# 98e6c76d62SJiri Olsaifeq ($(feature-all), 1) 99e6c76d62SJiri Olsa # 100e6c76d62SJiri Olsa # test-all.c passed - just set all the core feature flags to 1: 101e6c76d62SJiri Olsa # 102e6c76d62SJiri Olsa $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat))) 103e6c76d62SJiri Olsaelse 104e6c76d62SJiri Olsa $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat))) 105e6c76d62SJiri Olsaendif 106e6c76d62SJiri Olsa 107e6c76d62SJiri Olsa# 108e6c76d62SJiri Olsa# Print the result of the feature test: 109e6c76d62SJiri Olsa# 110e6c76d62SJiri Olsafeature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG)) 111e6c76d62SJiri Olsa 112e6c76d62SJiri Olsadefine feature_print_status_code 113e6c76d62SJiri Olsa ifeq ($(feature-$(1)), 1) 114e6c76d62SJiri Olsa MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1)) 115e6c76d62SJiri Olsa else 116e6c76d62SJiri Olsa MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1)) 117e6c76d62SJiri Olsa endif 118e6c76d62SJiri Olsaendef 119e6c76d62SJiri Olsa 120e6c76d62SJiri Olsafeature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG)) 121e6c76d62SJiri Olsadefine feature_print_text_code 122e6c76d62SJiri Olsa MSG = $(shell printf '...%30s: %s' $(1) $(2)) 123e6c76d62SJiri Olsaendef 124e6c76d62SJiri Olsa 125c6a5f88fSJiri Olsa# 126c6a5f88fSJiri Olsa# generates feature value assignment for name, like: 127c6a5f88fSJiri Olsa# $(call feature_assign,dwarf) == feature-dwarf=1 128c6a5f88fSJiri Olsa# 129c6a5f88fSJiri Olsafeature_assign = feature-$(1)=$(feature-$(1)) 130c6a5f88fSJiri Olsa 13113e96db6SArnaldo Carvalho de MeloFEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER) 132936d120dSJiri OlsaFEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME)) 133936d120dSJiri Olsa 134936d120dSJiri Olsafeature_dump_check = $(eval $(feature_dump_check_code)) 135936d120dSJiri Olsadefine feature_dump_check_code 136936d120dSJiri Olsa ifeq ($(findstring $(1),$(FEATURE_DUMP)),) 137936d120dSJiri Olsa $(2) := 1 138936d120dSJiri Olsa endif 139936d120dSJiri Olsaendef 140936d120dSJiri Olsa 141936d120dSJiri Olsa# 142936d120dSJiri Olsa# First check if any test from FEATURE_DISPLAY 143936d120dSJiri Olsa# and set feature_display := 1 if it does 144936d120dSJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display)) 145936d120dSJiri Olsa 146936d120dSJiri Olsa# 147936d120dSJiri Olsa# Now also check if any other test changed, 148936d120dSJiri Olsa# so we force FEATURE-DUMP generation 149936d120dSJiri Olsa$(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed)) 150e6c76d62SJiri Olsa 151e6c76d62SJiri Olsa# The $(feature_display) controls the default detection message 152e6c76d62SJiri Olsa# output. It's set if: 153e6c76d62SJiri Olsa# - detected features differes from stored features from 15413e96db6SArnaldo Carvalho de Melo# last build (in $(FEATURE_DUMP_FILENAME) file) 155e6c76d62SJiri Olsa# - one of the $(FEATURE_DISPLAY) is not detected 156e6c76d62SJiri Olsa# - VF is enabled 157e6c76d62SJiri Olsa 158936d120dSJiri Olsaifeq ($(feature_dump_changed),1) 159936d120dSJiri Olsa $(shell rm -f $(FEATURE_DUMP_FILENAME)) 160936d120dSJiri Olsa $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME))) 161e6c76d62SJiri Olsaendif 162e6c76d62SJiri Olsa 1636076e2a4SArnaldo Carvalho de Melofeature_display_check = $(eval $(feature_check_display_code)) 164d0018b49SJiri Olsadefine feature_check_display_code 165e6c76d62SJiri Olsa ifneq ($(feature-$(1)), 1) 166e6c76d62SJiri Olsa feature_display := 1 167e6c76d62SJiri Olsa endif 168e6c76d62SJiri Olsaendef 169e6c76d62SJiri Olsa 170e6c76d62SJiri Olsa$(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat))) 171e6c76d62SJiri Olsa 172e6c76d62SJiri Olsaifeq ($(VF),1) 173e6c76d62SJiri Olsa feature_display := 1 174e6c76d62SJiri Olsa feature_verbose := 1 175e6c76d62SJiri Olsaendif 176e6c76d62SJiri Olsa 177e6c76d62SJiri Olsaifeq ($(feature_display),1) 178e6c76d62SJiri Olsa $(info ) 179e6c76d62SJiri Olsa $(info Auto-detecting system features:) 180e6c76d62SJiri Olsa $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),)) 181e6c76d62SJiri Olsa ifneq ($(feature_verbose),1) 182e6c76d62SJiri Olsa $(info ) 183e6c76d62SJiri Olsa endif 184e6c76d62SJiri Olsaendif 185e6c76d62SJiri Olsa 186e6c76d62SJiri Olsaifeq ($(feature_verbose),1) 187e6c76d62SJiri Olsa TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS)) 188e6c76d62SJiri Olsa $(foreach feat,$(TMP),$(call feature_print_status,$(feat),)) 189e6c76d62SJiri Olsa $(info ) 190e6c76d62SJiri Olsaendif 191