make 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. include ../scripts/Makefile.include
  2. ifndef MK
  3. ifeq ($(MAKECMDGOALS),)
  4. # no target specified, trigger the whole suite
  5. all:
  6. @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile
  7. @echo "Testing Makefile.perf"; $(MAKE) -sf tests/make MK=Makefile.perf
  8. else
  9. # run only specific test over 'Makefile'
  10. %:
  11. @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile $@
  12. endif
  13. else
  14. PERF := .
  15. # As per kernel Makefile, avoid funny character set dependencies
  16. unexport LC_ALL
  17. LC_COLLATE=C
  18. LC_NUMERIC=C
  19. export LC_COLLATE LC_NUMERIC
  20. ifeq ($(srctree),)
  21. srctree := $(patsubst %/,%,$(dir $(shell pwd)))
  22. srctree := $(patsubst %/,%,$(dir $(srctree)))
  23. #$(info Determined 'srctree' to be $(srctree))
  24. endif
  25. include $(srctree)/tools/scripts/Makefile.arch
  26. # FIXME looks like x86 is the only arch running tests ;-)
  27. # we need some IS_(32/64) flag to make this generic
  28. ifeq ($(ARCH)$(IS_64_BIT), x861)
  29. lib = lib64
  30. else
  31. lib = lib
  32. endif
  33. has = $(shell which $1 2>/dev/null)
  34. # standard single make variable specified
  35. make_clean_all := clean all
  36. make_python_perf_so := python/perf.so
  37. make_debug := DEBUG=1
  38. make_no_libperl := NO_LIBPERL=1
  39. make_no_libpython := NO_LIBPYTHON=1
  40. make_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1
  41. make_no_newt := NO_NEWT=1
  42. make_no_slang := NO_SLANG=1
  43. make_no_gtk2 := NO_GTK2=1
  44. make_no_ui := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1
  45. make_no_demangle := NO_DEMANGLE=1
  46. make_no_libelf := NO_LIBELF=1
  47. make_no_libunwind := NO_LIBUNWIND=1
  48. make_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1
  49. make_no_backtrace := NO_BACKTRACE=1
  50. make_no_libnuma := NO_LIBNUMA=1
  51. make_no_libaudit := NO_LIBAUDIT=1
  52. make_no_libbionic := NO_LIBBIONIC=1
  53. make_no_auxtrace := NO_AUXTRACE=1
  54. make_no_libbpf := NO_LIBBPF=1
  55. make_tags := tags
  56. make_cscope := cscope
  57. make_help := help
  58. make_doc := doc
  59. make_perf_o := perf.o
  60. make_util_map_o := util/map.o
  61. make_util_pmu_bison_o := util/pmu-bison.o
  62. make_install := install
  63. make_install_bin := install-bin
  64. make_install_doc := install-doc
  65. make_install_man := install-man
  66. make_install_html := install-html
  67. make_install_info := install-info
  68. make_install_pdf := install-pdf
  69. make_install_prefix := install prefix=/tmp/krava
  70. make_install_prefix_slash := install prefix=/tmp/krava/
  71. make_static := LDFLAGS=-static
  72. # all the NO_* variable combined
  73. make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1
  74. make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1
  75. make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1
  76. make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1
  77. # $(run) contains all available tests
  78. run := make_pure
  79. # Targets 'clean all' can be run together only through top level
  80. # Makefile because we detect clean target in Makefile.perf and
  81. # disable features detection
  82. ifeq ($(MK),Makefile)
  83. run += make_clean_all
  84. endif
  85. run += make_python_perf_so
  86. run += make_debug
  87. run += make_no_libperl
  88. run += make_no_libpython
  89. run += make_no_scripts
  90. run += make_no_newt
  91. run += make_no_slang
  92. run += make_no_gtk2
  93. run += make_no_ui
  94. run += make_no_demangle
  95. run += make_no_libelf
  96. run += make_no_libunwind
  97. run += make_no_libdw_dwarf_unwind
  98. run += make_no_backtrace
  99. run += make_no_libnuma
  100. run += make_no_libaudit
  101. run += make_no_libbionic
  102. run += make_no_auxtrace
  103. run += make_no_libbpf
  104. run += make_help
  105. run += make_doc
  106. run += make_perf_o
  107. run += make_util_map_o
  108. run += make_util_pmu_bison_o
  109. run += make_install
  110. run += make_install_bin
  111. run += make_install_prefix
  112. run += make_install_prefix_slash
  113. # FIXME 'install-*' commented out till they're fixed
  114. # run += make_install_doc
  115. # run += make_install_man
  116. # run += make_install_html
  117. # run += make_install_info
  118. # run += make_install_pdf
  119. run += make_minimal
  120. run += make_static
  121. ifneq ($(call has,ctags),)
  122. run += make_tags
  123. endif
  124. ifneq ($(call has,cscope),)
  125. run += make_cscope
  126. endif
  127. # $(run_O) contains same portion of $(run) tests with '_O' attached
  128. # to distinguish O=... tests
  129. run_O := $(addsuffix _O,$(run))
  130. # disable some tests for O=...
  131. run_O := $(filter-out make_python_perf_so_O,$(run_O))
  132. # define test for each compile as 'test_NAME' variable
  133. # with the test itself as a value
  134. test_make_tags = test -f tags
  135. test_make_cscope = test -f cscope.out
  136. test_make_tags_O := $(test_make_tags)
  137. test_make_cscope_O := $(test_make_cscope)
  138. test_ok := true
  139. test_make_help := $(test_ok)
  140. test_make_doc := $(test_ok)
  141. test_make_help_O := $(test_ok)
  142. test_make_doc_O := $(test_ok)
  143. test_make_python_perf_so := test -f $(PERF)/python/perf.so
  144. test_make_perf_o := test -f $(PERF)/perf.o
  145. test_make_util_map_o := test -f $(PERF)/util/map.o
  146. test_make_util_pmu_bison_o := test -f $(PERF)/util/pmu-bison.o
  147. define test_dest_files
  148. for file in $(1); do \
  149. if [ ! -x $$TMP_DEST/$$file ]; then \
  150. echo " failed to find: $$file"; \
  151. fi \
  152. done
  153. endef
  154. installed_files_bin := bin/perf
  155. installed_files_bin += etc/bash_completion.d/perf
  156. installed_files_bin += libexec/perf-core/perf-archive
  157. installed_files_plugins := $(lib)/traceevent/plugins/plugin_cfg80211.so
  158. installed_files_plugins += $(lib)/traceevent/plugins/plugin_scsi.so
  159. installed_files_plugins += $(lib)/traceevent/plugins/plugin_xen.so
  160. installed_files_plugins += $(lib)/traceevent/plugins/plugin_function.so
  161. installed_files_plugins += $(lib)/traceevent/plugins/plugin_sched_switch.so
  162. installed_files_plugins += $(lib)/traceevent/plugins/plugin_mac80211.so
  163. installed_files_plugins += $(lib)/traceevent/plugins/plugin_kvm.so
  164. installed_files_plugins += $(lib)/traceevent/plugins/plugin_kmem.so
  165. installed_files_plugins += $(lib)/traceevent/plugins/plugin_hrtimer.so
  166. installed_files_plugins += $(lib)/traceevent/plugins/plugin_jbd2.so
  167. installed_files_all := $(installed_files_bin)
  168. installed_files_all += $(installed_files_plugins)
  169. test_make_install := $(call test_dest_files,$(installed_files_all))
  170. test_make_install_O := $(call test_dest_files,$(installed_files_all))
  171. test_make_install_bin := $(call test_dest_files,$(installed_files_bin))
  172. test_make_install_bin_O := $(call test_dest_files,$(installed_files_bin))
  173. # We prefix all installed files for make_install_prefix(_slash)
  174. # with '/tmp/krava' to match installed/prefix-ed files.
  175. installed_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all))
  176. test_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix))
  177. test_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix))
  178. test_make_install_prefix_slash := $(test_make_install_prefix)
  179. test_make_install_prefix_slash_O := $(test_make_install_prefix_O)
  180. # FIXME nothing gets installed
  181. test_make_install_man := test -f $$TMP_DEST/share/man/man1/perf.1
  182. test_make_install_man_O := $(test_make_install_man)
  183. # FIXME nothing gets installed
  184. test_make_install_doc := $(test_ok)
  185. test_make_install_doc_O := $(test_ok)
  186. # FIXME nothing gets installed
  187. test_make_install_html := $(test_ok)
  188. test_make_install_html_O := $(test_ok)
  189. # FIXME nothing gets installed
  190. test_make_install_info := $(test_ok)
  191. test_make_install_info_O := $(test_ok)
  192. # FIXME nothing gets installed
  193. test_make_install_pdf := $(test_ok)
  194. test_make_install_pdf_O := $(test_ok)
  195. test_make_python_perf_so_O := test -f $$TMP_O/python/perf.so
  196. test_make_perf_o_O := test -f $$TMP_O/perf.o
  197. test_make_util_map_o_O := test -f $$TMP_O/util/map.o
  198. test_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o
  199. test_default = test -x $(PERF)/perf
  200. test = $(if $(test_$1),$(test_$1),$(test_default))
  201. test_default_O = test -x $$TMP_O/perf
  202. test_O = $(if $(test_$1),$(test_$1),$(test_default_O))
  203. all:
  204. ifdef SHUF
  205. run := $(shell shuf -e $(run))
  206. run_O := $(shell shuf -e $(run_O))
  207. endif
  208. ifdef DEBUG
  209. d := $(info run $(run))
  210. d := $(info run_O $(run_O))
  211. endif
  212. MAKEFLAGS := --no-print-directory
  213. clean := @(cd $(PERF); make -s -f $(MK) clean >/dev/null)
  214. $(run):
  215. $(call clean)
  216. @TMP_DEST=$$(mktemp -d); \
  217. cmd="cd $(PERF) && make -f $(MK) DESTDIR=$$TMP_DEST $($@)"; \
  218. echo "- $@: $$cmd" && echo $$cmd > $@ && \
  219. ( eval $$cmd ) >> $@ 2>&1; \
  220. echo " test: $(call test,$@)" >> $@ 2>&1; \
  221. $(call test,$@) && \
  222. rm -rf $@ $$TMP_DEST || (cat $@ ; false)
  223. $(run_O):
  224. $(call clean)
  225. @TMP_O=$$(mktemp -d); \
  226. TMP_DEST=$$(mktemp -d); \
  227. cmd="cd $(PERF) && make -f $(MK) O=$$TMP_O DESTDIR=$$TMP_DEST $($(patsubst %_O,%,$@))"; \
  228. echo "- $@: $$cmd" && echo $$cmd > $@ && \
  229. ( eval $$cmd ) >> $@ 2>&1 && \
  230. echo " test: $(call test_O,$@)" >> $@ 2>&1; \
  231. $(call test_O,$@) && \
  232. rm -rf $@ $$TMP_O $$TMP_DEST || (cat $@ ; false)
  233. tarpkg:
  234. @cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \
  235. echo "- $@: $$cmd" && echo $$cmd > $@ && \
  236. ( eval $$cmd ) >> $@ 2>&1 && \
  237. rm -f $@
  238. make_kernelsrc:
  239. @echo "- make -C <kernelsrc> tools/perf"
  240. $(call clean); \
  241. (make -C ../.. tools/perf) > $@ 2>&1 && \
  242. test -x perf && rm -f $@ || (cat $@ ; false)
  243. make_kernelsrc_tools:
  244. @echo "- make -C <kernelsrc>/tools perf"
  245. $(call clean); \
  246. (make -C ../../tools perf) > $@ 2>&1 && \
  247. test -x perf && rm -f $@ || (cat $@ ; false)
  248. all: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools
  249. @echo OK
  250. out: $(run_O)
  251. @echo OK
  252. .PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools
  253. endif # ifndef MK