Makefile.feature 5.7 KB

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