Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0-only
0002 feature_dir := $(srctree)/tools/build/feature
0003 
0004 ifneq ($(OUTPUT),)
0005   OUTPUT_FEATURES = $(OUTPUT)feature/
0006   $(shell mkdir -p $(OUTPUT_FEATURES))
0007 endif
0008 
0009 feature_check = $(eval $(feature_check_code))
0010 define feature_check_code
0011   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)
0012 endef
0013 
0014 feature_set = $(eval $(feature_set_code))
0015 define feature_set_code
0016   feature-$(1) := 1
0017 endef
0018 
0019 #
0020 # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
0021 #
0022 
0023 #
0024 # Note that this is not a complete list of all feature tests, just
0025 # those that are typically built on a fully configured system.
0026 #
0027 # [ Feature tests not mentioned here have to be built explicitly in
0028 #   the rule that uses them - an example for that is the 'bionic'
0029 #   feature check. ]
0030 #
0031 FEATURE_TESTS_BASIC :=                  \
0032         backtrace                       \
0033         dwarf                           \
0034         dwarf_getlocations              \
0035         eventfd                         \
0036         fortify-source                  \
0037         get_current_dir_name            \
0038         gettid                          \
0039         glibc                           \
0040         libbfd                          \
0041         libbfd-buildid                  \
0042         libcap                          \
0043         libelf                          \
0044         libelf-getphdrnum               \
0045         libelf-gelf_getnote             \
0046         libelf-getshdrstrndx            \
0047         libnuma                         \
0048         numa_num_possible_cpus          \
0049         libperl                         \
0050         libpython                       \
0051         libslang                        \
0052         libslang-include-subdir         \
0053         libtraceevent                   \
0054         libtracefs                      \
0055         libcrypto                       \
0056         libunwind                       \
0057         pthread-attr-setaffinity-np     \
0058         pthread-barrier                 \
0059         reallocarray                    \
0060         stackprotector-all              \
0061         timerfd                         \
0062         libdw-dwarf-unwind              \
0063         zlib                            \
0064         lzma                            \
0065         get_cpuid                       \
0066         bpf                             \
0067         sched_getcpu                    \
0068         sdt                             \
0069         setns                           \
0070         libaio                          \
0071         libzstd                         \
0072         disassembler-four-args          \
0073         disassembler-init-styled        \
0074         file-handle
0075 
0076 # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
0077 # of all feature tests
0078 FEATURE_TESTS_EXTRA :=                  \
0079          bionic                         \
0080          compile-32                     \
0081          compile-x32                    \
0082          cplus-demangle                 \
0083          gtk2                           \
0084          gtk2-infobar                   \
0085          hello                          \
0086          libbabeltrace                  \
0087          libbfd-liberty                 \
0088          libbfd-liberty-z               \
0089          libopencsd                     \
0090          libunwind-x86                  \
0091          libunwind-x86_64               \
0092          libunwind-arm                  \
0093          libunwind-aarch64              \
0094          libunwind-debug-frame          \
0095          libunwind-debug-frame-arm      \
0096          libunwind-debug-frame-aarch64  \
0097          cxx                            \
0098          llvm                           \
0099          llvm-version                   \
0100          clang                          \
0101          libbpf                         \
0102          libbpf-btf__load_from_kernel_by_id \
0103          libbpf-bpf_prog_load           \
0104          libbpf-bpf_object__next_program \
0105          libbpf-bpf_object__next_map    \
0106          libbpf-bpf_create_map          \
0107          libpfm4                        \
0108          libdebuginfod                  \
0109          clang-bpf-co-re
0110 
0111 
0112 FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
0113 
0114 ifeq ($(FEATURE_TESTS),all)
0115   FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
0116 endif
0117 
0118 FEATURE_DISPLAY ?=              \
0119          dwarf                  \
0120          dwarf_getlocations     \
0121          glibc                  \
0122          libbfd                 \
0123          libbfd-buildid         \
0124          libcap                 \
0125          libelf                 \
0126          libnuma                \
0127          numa_num_possible_cpus \
0128          libperl                \
0129          libpython              \
0130          libcrypto              \
0131          libunwind              \
0132          libdw-dwarf-unwind     \
0133          zlib                   \
0134          lzma                   \
0135          get_cpuid              \
0136          bpf                    \
0137          libaio                 \
0138          libzstd
0139 
0140 # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
0141 # If in the future we need per-feature checks/flags for features not
0142 # mentioned in this list we need to refactor this ;-).
0143 set_test_all_flags = $(eval $(set_test_all_flags_code))
0144 define set_test_all_flags_code
0145   FEATURE_CHECK_CFLAGS-all  += $(FEATURE_CHECK_CFLAGS-$(1))
0146   FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
0147 endef
0148 
0149 $(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
0150 
0151 #
0152 # Special fast-path for the 'all features are available' case:
0153 #
0154 $(call feature_check,all,$(MSG))
0155 
0156 #
0157 # Just in case the build freshly failed, make sure we print the
0158 # feature matrix:
0159 #
0160 ifeq ($(feature-all), 1)
0161   #
0162   # test-all.c passed - just set all the core feature flags to 1:
0163   #
0164   $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
0165   #
0166   # test-all.c does not comprise these tests, so we need to
0167   # for this case to get features proper values
0168   #
0169   $(call feature_check,compile-32)
0170   $(call feature_check,compile-x32)
0171   $(call feature_check,bionic)
0172   $(call feature_check,libbabeltrace)
0173 else
0174   $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
0175 endif
0176 
0177 #
0178 # Print the result of the feature test:
0179 #
0180 feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
0181 
0182 define feature_print_status_code
0183   ifeq ($(feature-$(1)), 1)
0184     MSG = $(shell printf '...%30s: [ \033[32mon\033[m  ]' $(1))
0185   else
0186     MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
0187   endif
0188 endef
0189 
0190 feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
0191 define feature_print_text_code
0192     MSG = $(shell printf '...%30s: %s' $(1) $(2))
0193 endef
0194 
0195 #
0196 # generates feature value assignment for name, like:
0197 #   $(call feature_assign,dwarf) == feature-dwarf=1
0198 #
0199 feature_assign = feature-$(1)=$(feature-$(1))
0200 
0201 FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
0202 FEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
0203 
0204 feature_dump_check = $(eval $(feature_dump_check_code))
0205 define feature_dump_check_code
0206   ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
0207     $(2) := 1
0208   endif
0209 endef
0210 
0211 #
0212 # First check if any test from FEATURE_DISPLAY
0213 # and set feature_display := 1 if it does
0214 $(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
0215 
0216 #
0217 # Now also check if any other test changed,
0218 # so we force FEATURE-DUMP generation
0219 $(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
0220 
0221 # The $(feature_display) controls the default detection message
0222 # output. It's set if:
0223 # - detected features differes from stored features from
0224 #   last build (in $(FEATURE_DUMP_FILENAME) file)
0225 # - one of the $(FEATURE_DISPLAY) is not detected
0226 # - VF is enabled
0227 
0228 ifeq ($(feature_dump_changed),1)
0229   $(shell rm -f $(FEATURE_DUMP_FILENAME))
0230   $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
0231 endif
0232 
0233 feature_display_check = $(eval $(feature_check_display_code))
0234 define feature_check_display_code
0235   ifneq ($(feature-$(1)), 1)
0236     feature_display := 1
0237   endif
0238 endef
0239 
0240 $(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
0241 
0242 ifeq ($(VF),1)
0243   feature_display := 1
0244   feature_verbose := 1
0245 endif
0246 
0247 feature_display_entries = $(eval $(feature_display_entries_code))
0248 define feature_display_entries_code
0249   ifeq ($(feature_display),1)
0250     $(info )
0251     $(info Auto-detecting system features:)
0252     $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
0253     ifneq ($(feature_verbose),1)
0254       $(info )
0255     endif
0256   endif
0257 
0258   ifeq ($(feature_verbose),1)
0259     TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
0260     $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
0261     $(info )
0262   endif
0263 endef
0264 
0265 ifeq ($(FEATURE_DISPLAY_DEFERRED),)
0266   $(call feature_display_entries)
0267 endif