Makefile.feature 5.9 KB

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