Makefile.feature 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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_BASIC := \
  26. backtrace \
  27. dwarf \
  28. dwarf_getlocations \
  29. fortify-source \
  30. sync-compare-and-swap \
  31. glibc \
  32. gtk2 \
  33. gtk2-infobar \
  34. libaudit \
  35. libbfd \
  36. libelf \
  37. libelf-getphdrnum \
  38. libelf-mmap \
  39. libnuma \
  40. numa_num_possible_cpus \
  41. libperl \
  42. libpython \
  43. libpython-version \
  44. libslang \
  45. libcrypto \
  46. libunwind \
  47. pthread-attr-setaffinity-np \
  48. stackprotector-all \
  49. timerfd \
  50. libdw-dwarf-unwind \
  51. zlib \
  52. lzma \
  53. get_cpuid \
  54. bpf
  55. # FEATURE_TESTS_BASIC + FEATURE_TESTS_EXTRA is the complete list
  56. # of all feature tests
  57. FEATURE_TESTS_EXTRA := \
  58. bionic \
  59. compile-32 \
  60. compile-x32 \
  61. cplus-demangle \
  62. hello \
  63. libbabeltrace \
  64. liberty \
  65. liberty-z \
  66. libunwind-debug-frame
  67. FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
  68. ifeq ($(FEATURE_TESTS),all)
  69. FEATURE_TESTS := $(FEATURE_TESTS_BASIC) $(FEATURE_TESTS_EXTRA)
  70. endif
  71. FEATURE_DISPLAY ?= \
  72. dwarf \
  73. dwarf_getlocations \
  74. glibc \
  75. gtk2 \
  76. libaudit \
  77. libbfd \
  78. libelf \
  79. libnuma \
  80. numa_num_possible_cpus \
  81. libperl \
  82. libpython \
  83. libslang \
  84. libcrypto \
  85. libunwind \
  86. libdw-dwarf-unwind \
  87. zlib \
  88. lzma \
  89. get_cpuid \
  90. bpf
  91. # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
  92. # If in the future we need per-feature checks/flags for features not
  93. # mentioned in this list we need to refactor this ;-).
  94. set_test_all_flags = $(eval $(set_test_all_flags_code))
  95. define set_test_all_flags_code
  96. FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
  97. FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
  98. endef
  99. $(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
  100. #
  101. # Special fast-path for the 'all features are available' case:
  102. #
  103. $(call feature_check,all,$(MSG))
  104. #
  105. # Just in case the build freshly failed, make sure we print the
  106. # feature matrix:
  107. #
  108. ifeq ($(feature-all), 1)
  109. #
  110. # test-all.c passed - just set all the core feature flags to 1:
  111. #
  112. $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
  113. #
  114. # test-all.c does not comprise these tests, so we need to
  115. # for this case to get features proper values
  116. #
  117. $(call feature_check,compile-32)
  118. $(call feature_check,compile-x32)
  119. $(call feature_check,bionic)
  120. $(call feature_check,libbabeltrace)
  121. else
  122. $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
  123. endif
  124. #
  125. # Print the result of the feature test:
  126. #
  127. feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
  128. define feature_print_status_code
  129. ifeq ($(feature-$(1)), 1)
  130. MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
  131. else
  132. MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
  133. endif
  134. endef
  135. feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
  136. define feature_print_text_code
  137. MSG = $(shell printf '...%30s: %s' $(1) $(2))
  138. endef
  139. #
  140. # generates feature value assignment for name, like:
  141. # $(call feature_assign,dwarf) == feature-dwarf=1
  142. #
  143. feature_assign = feature-$(1)=$(feature-$(1))
  144. FEATURE_DUMP_FILENAME = $(OUTPUT)FEATURE-DUMP$(FEATURE_USER)
  145. FEATURE_DUMP := $(shell touch $(FEATURE_DUMP_FILENAME); cat $(FEATURE_DUMP_FILENAME))
  146. feature_dump_check = $(eval $(feature_dump_check_code))
  147. define feature_dump_check_code
  148. ifeq ($(findstring $(1),$(FEATURE_DUMP)),)
  149. $(2) := 1
  150. endif
  151. endef
  152. #
  153. # First check if any test from FEATURE_DISPLAY
  154. # and set feature_display := 1 if it does
  155. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_display))
  156. #
  157. # Now also check if any other test changed,
  158. # so we force FEATURE-DUMP generation
  159. $(foreach feat,$(FEATURE_TESTS),$(call feature_dump_check,$(call feature_assign,$(feat)),feature_dump_changed))
  160. # The $(feature_display) controls the default detection message
  161. # output. It's set if:
  162. # - detected features differes from stored features from
  163. # last build (in $(FEATURE_DUMP_FILENAME) file)
  164. # - one of the $(FEATURE_DISPLAY) is not detected
  165. # - VF is enabled
  166. ifeq ($(feature_dump_changed),1)
  167. $(shell rm -f $(FEATURE_DUMP_FILENAME))
  168. $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))
  169. endif
  170. feature_display_check = $(eval $(feature_check_display_code))
  171. define feature_check_display_code
  172. ifneq ($(feature-$(1)), 1)
  173. feature_display := 1
  174. endif
  175. endef
  176. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
  177. ifeq ($(VF),1)
  178. feature_display := 1
  179. feature_verbose := 1
  180. endif
  181. ifeq ($(feature_display),1)
  182. $(info )
  183. $(info Auto-detecting system features:)
  184. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
  185. ifneq ($(feature_verbose),1)
  186. $(info )
  187. endif
  188. endif
  189. ifeq ($(feature_verbose),1)
  190. TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
  191. $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
  192. $(info )
  193. endif