Makefile.feature 7.8 KB

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