Makefile.feature 7.7 KB

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