Makefile.feature 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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) 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 ?= \
  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. libperl \
  40. libpython \
  41. libpython-version \
  42. libslang \
  43. libunwind \
  44. pthread-attr-setaffinity-np \
  45. stackprotector-all \
  46. timerfd \
  47. libdw-dwarf-unwind \
  48. zlib \
  49. lzma
  50. FEATURE_DISPLAY ?= \
  51. dwarf \
  52. glibc \
  53. gtk2 \
  54. libaudit \
  55. libbfd \
  56. libelf \
  57. libnuma \
  58. libperl \
  59. libpython \
  60. libslang \
  61. libunwind \
  62. libdw-dwarf-unwind \
  63. zlib \
  64. lzma
  65. # Set FEATURE_CHECK_(C|LD)FLAGS-all for all FEATURE_TESTS features.
  66. # If in the future we need per-feature checks/flags for features not
  67. # mentioned in this list we need to refactor this ;-).
  68. set_test_all_flags = $(eval $(set_test_all_flags_code))
  69. define set_test_all_flags_code
  70. FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
  71. FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
  72. endef
  73. $(foreach feat,$(FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
  74. #
  75. # Special fast-path for the 'all features are available' case:
  76. #
  77. $(call feature_check,all,$(MSG))
  78. #
  79. # Just in case the build freshly failed, make sure we print the
  80. # feature matrix:
  81. #
  82. ifeq ($(feature-all), 1)
  83. #
  84. # test-all.c passed - just set all the core feature flags to 1:
  85. #
  86. $(foreach feat,$(FEATURE_TESTS),$(call feature_set,$(feat)))
  87. else
  88. $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C $(feature_dir) $(addsuffix .bin,$(FEATURE_TESTS)) >/dev/null 2>&1)
  89. $(foreach feat,$(FEATURE_TESTS),$(call feature_check,$(feat)))
  90. endif
  91. #
  92. # Print the result of the feature test:
  93. #
  94. feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
  95. define feature_print_status_code
  96. ifeq ($(feature-$(1)), 1)
  97. MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
  98. else
  99. MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
  100. endif
  101. endef
  102. feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
  103. define feature_print_text_code
  104. MSG = $(shell printf '...%30s: %s' $(1) $(2))
  105. endef
  106. FEATURE_DUMP := $(foreach feat,$(FEATURE_DISPLAY),feature-$(feat)($(feature-$(feat))))
  107. FEATURE_DUMP_FILE := $(shell touch $(OUTPUT)FEATURE-DUMP; cat $(OUTPUT)FEATURE-DUMP)
  108. ifeq ($(dwarf-post-unwind),1)
  109. FEATURE_DUMP += dwarf-post-unwind($(dwarf-post-unwind-text))
  110. endif
  111. # The $(feature_display) controls the default detection message
  112. # output. It's set if:
  113. # - detected features differes from stored features from
  114. # last build (in FEATURE-DUMP file)
  115. # - one of the $(FEATURE_DISPLAY) is not detected
  116. # - VF is enabled
  117. ifneq ("$(FEATURE_DUMP)","$(FEATURE_DUMP_FILE)")
  118. $(shell echo "$(FEATURE_DUMP)" > $(OUTPUT)FEATURE-DUMP)
  119. feature_display := 1
  120. endif
  121. feature_display_check = $(eval $(feature_check_code))
  122. define feature_display_check_code
  123. ifneq ($(feature-$(1)), 1)
  124. feature_display := 1
  125. endif
  126. endef
  127. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_display_check,$(feat)))
  128. ifeq ($(VF),1)
  129. feature_display := 1
  130. feature_verbose := 1
  131. endif
  132. ifeq ($(feature_display),1)
  133. $(info )
  134. $(info Auto-detecting system features:)
  135. $(foreach feat,$(FEATURE_DISPLAY),$(call feature_print_status,$(feat),))
  136. ifeq ($(dwarf-post-unwind),1)
  137. $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
  138. endif
  139. ifneq ($(feature_verbose),1)
  140. $(info )
  141. endif
  142. endif
  143. ifeq ($(feature_verbose),1)
  144. TMP := $(filter-out $(FEATURE_DISPLAY),$(FEATURE_TESTS))
  145. $(foreach feat,$(TMP),$(call feature_print_status,$(feat),))
  146. $(info )
  147. endif