Makefile.feature 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. feature_dir := $(srctree)/tools/build/feature
  2. ifneq ($(OUTPUT),)
  3. OUTPUT_FEATURES = $(OUTPUT)feature/
  4. $(shell mkdir -p $(OUTPUT_FEATURES))
  5. endif
  6. feature_check = $(eval $(feature_check_code))
  7. define feature_check_code
  8. 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)
  9. endef
  10. feature_set = $(eval $(feature_set_code))
  11. define feature_set_code
  12. feature-$(1) := 1
  13. endef
  14. #
  15. # Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
  16. #
  17. #
  18. # Note that this is not a complete list of all feature tests, just
  19. # those that are typically built on a fully configured system.
  20. #
  21. # [ Feature tests not mentioned here have to be built explicitly in
  22. # the rule that uses them - an example for that is the 'bionic'
  23. # feature check. ]
  24. #
  25. FEATURE_TESTS ?= \
  26. backtrace \
  27. dwarf \
  28. fortify-source \
  29. sync-compare-and-swap \
  30. glibc \
  31. gtk2 \
  32. gtk2-infobar \
  33. libaudit \
  34. libbfd \
  35. libelf \
  36. libelf-getphdrnum \
  37. libelf-mmap \
  38. libnuma \
  39. numa_num_possible_cpus \
  40. libperl \
  41. libpython \
  42. libpython-version \
  43. libslang \
  44. libunwind \
  45. pthread-attr-setaffinity-np \
  46. stackprotector-all \
  47. timerfd \
  48. libdw-dwarf-unwind \
  49. zlib \
  50. lzma \
  51. get_cpuid \
  52. bpf
  53. FEATURE_DISPLAY ?= \
  54. dwarf \
  55. glibc \
  56. gtk2 \
  57. libaudit \
  58. libbfd \
  59. libelf \
  60. libnuma \
  61. numa_num_possible_cpus \
  62. libperl \
  63. libpython \
  64. libslang \
  65. libunwind \
  66. libdw-dwarf-unwind \
  67. zlib \
  68. lzma \
  69. get_cpuid \
  70. bpf
  71. # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
  72. # If in the future we need per-feature checks/flags for features not
  73. # mentioned in this list we need to refactor this ;-).
  74. set_test_all_flags = $(eval $(set_test_all_flags_code))
  75. define set_test_all_flags_code
  76. FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
  77. FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
  78. endef
  79. $(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
  80. #
  81. # Special fast-path for the 'all features are available' case:
  82. #
  83. $(call feature_check,all,$(MSG))
  84. #
  85. # Just in case the build freshly failed, make sure we print the
  86. # feature matrix:
  87. #
  88. ifeq ($(feature-all), 1)
  89. #
  90. # test-all.c passed - just set all the core feature flags to 1:
  91. #
  92. $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
  93. else
  94. $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
  95. endif
  96. #
  97. # Print the result of the feature test:
  98. #
  99. feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
  100. define feature_print_status_code
  101. ifeq ($(feature-$(1)), 1)
  102. MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
  103. else
  104. MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
  105. endif
  106. endef
  107. feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
  108. define feature_print_text_code
  109. MSG = $(shell printf '...%30s: %s' $(1) $(2))
  110. endef
  111. #
  112. # generates feature value assignment for name, like:
  113. # $(call feature_assign,dwarf) == feature-dwarf=1
  114. #
  115. feature_assign = feature-$(1)=$(feature-$(1))
  116. FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
  117. FEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
  118. feature_dump_check = $(eval $(feature_dump_check_code))
  119. define feature_dump_check_code
  120. ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
  121. $(2) := 1
  122. endif
  123. endef
  124. #
  125. # First check if any test from FEATURE_DISPLAY
  126. # and set feature_display := 1 if it does
  127. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
  128. #
  129. # Now also check if any other test changed,
  130. # so we force FEATURE-DUMP generation
  131. $(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
  132. # The $(feature_display) controls the default detection message
  133. # output. It's set if:
  134. # - detected features differes from stored features from
  135. # last build (in $(FEATURE_DUMP_FILENAME) file)
  136. # - one of the $(FEATURE_DISPLAY) is not detected
  137. # - VF is enabled
  138. ifeq ($(feature_dump_changed),1)
  139. $(shell rm -f $(FEATURE_DUMP_FILENAME))
  140. $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
  141. endif
  142. feature_display_check = $(eval $(feature_check_display_code))
  143. define feature_check_display_code
  144. ifneq ($(feature-$(1)), 1)
  145. feature_display := 1
  146. endif
  147. endef
  148. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
  149. ifeq ($(VF),1)
  150. feature_display := 1
  151. feature_verbose := 1
  152. endif
  153. ifeq ($(feature_display),1)
  154. $(info )
  155. $(info Auto-detecting system features:)
  156. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
  157. ifneq ($(feature_verbose),1)
  158. $(info )
  159. endif
  160. endif
  161. ifeq ($(feature_verbose),1)
  162. TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
  163. $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
  164. $(info )
  165. endif