1935e6bd3SWang Naninclude ../scripts/Makefile.include 2935e6bd3SWang Nan 3502819c5SJiri Olsaifndef MK 4502819c5SJiri Olsaifeq ($(MAKECMDGOALS),) 5502819c5SJiri Olsa# no target specified, trigger the whole suite 6502819c5SJiri Olsaall: 7502819c5SJiri Olsa @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile 8eb807730SWang Nan @echo "Testing Makefile.perf"; $(MAKE) -sf tests/make MK=Makefile.perf SET_PARALLEL=1 SET_O=1 9502819c5SJiri Olsaelse 10502819c5SJiri Olsa# run only specific test over 'Makefile' 11502819c5SJiri Olsa%: 12502819c5SJiri Olsa @echo "Testing Makefile"; $(MAKE) -sf tests/make MK=Makefile $@ 13502819c5SJiri Olsaendif 14502819c5SJiri Olsaelse 15095ae69bSJiri OlsaPERF := . 16*68824de1SWang NanPERF_O := $(PERF) 17eb807730SWang NanO_OPT := 18eb807730SWang Nan 19eb807730SWang Nanifneq ($(O),) 20eb807730SWang Nan FULL_O := $(shell readlink -f $(O) || echo $(O)) 21*68824de1SWang Nan PERF_O := $(FULL_O) 22eb807730SWang Nan ifeq ($(SET_O),1) 23eb807730SWang Nan O_OPT := 'O=$(FULL_O)' 24eb807730SWang Nan endif 25eb807730SWang Nanendif 26095ae69bSJiri Olsa 277be43dfbSWang NanPARALLEL_OPT= 287be43dfbSWang Nanifeq ($(SET_PARALLEL),1) 297be43dfbSWang Nan cores := $(shell (getconf _NPROCESSORS_ONLN || egrep -c '^processor|^CPU[0-9]' /proc/cpuinfo) 2>/dev/null) 307be43dfbSWang Nan ifeq ($(cores),0) 317be43dfbSWang Nan cores := 1 327be43dfbSWang Nan endif 337be43dfbSWang Nan PARALLEL_OPT="-j$(cores)" 347be43dfbSWang Nanendif 357be43dfbSWang Nan 36935e6bd3SWang Nan# As per kernel Makefile, avoid funny character set dependencies 37935e6bd3SWang Nanunexport LC_ALL 38935e6bd3SWang NanLC_COLLATE=C 39935e6bd3SWang NanLC_NUMERIC=C 40935e6bd3SWang Nanexport LC_COLLATE LC_NUMERIC 41935e6bd3SWang Nan 42935e6bd3SWang Nanifeq ($(srctree),) 43935e6bd3SWang Nansrctree := $(patsubst %/,%,$(dir $(shell pwd))) 44935e6bd3SWang Nansrctree := $(patsubst %/,%,$(dir $(srctree))) 45935e6bd3SWang Nan#$(info Determined 'srctree' to be $(srctree)) 46935e6bd3SWang Nanendif 47935e6bd3SWang Nan 48935e6bd3SWang Naninclude $(srctree)/tools/scripts/Makefile.arch 49f7c64474SJiri Olsa 50f7c64474SJiri Olsa# FIXME looks like x86 is the only arch running tests ;-) 51f7c64474SJiri Olsa# we need some IS_(32/64) flag to make this generic 5276aea773SH.J. Luifeq ($(ARCH)$(IS_64_BIT), x861) 53f7c64474SJiri Olsalib = lib64 54f7c64474SJiri Olsaelse 55f7c64474SJiri Olsalib = lib 56f7c64474SJiri Olsaendif 57f7c64474SJiri Olsa 580659e669SJiri Olsahas = $(shell which $1 2>/dev/null) 590659e669SJiri Olsa 60095ae69bSJiri Olsa# standard single make variable specified 61095ae69bSJiri Olsamake_clean_all := clean all 62095ae69bSJiri Olsamake_python_perf_so := python/perf.so 63095ae69bSJiri Olsamake_debug := DEBUG=1 64095ae69bSJiri Olsamake_no_libperl := NO_LIBPERL=1 65095ae69bSJiri Olsamake_no_libpython := NO_LIBPYTHON=1 66095ae69bSJiri Olsamake_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1 67095ae69bSJiri Olsamake_no_newt := NO_NEWT=1 68095ae69bSJiri Olsamake_no_slang := NO_SLANG=1 69095ae69bSJiri Olsamake_no_gtk2 := NO_GTK2=1 70095ae69bSJiri Olsamake_no_ui := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1 71095ae69bSJiri Olsamake_no_demangle := NO_DEMANGLE=1 72095ae69bSJiri Olsamake_no_libelf := NO_LIBELF=1 73095ae69bSJiri Olsamake_no_libunwind := NO_LIBUNWIND=1 749e8c06eaSJiri Olsamake_no_libdw_dwarf_unwind := NO_LIBDW_DWARF_UNWIND=1 75095ae69bSJiri Olsamake_no_backtrace := NO_BACKTRACE=1 76095ae69bSJiri Olsamake_no_libnuma := NO_LIBNUMA=1 77095ae69bSJiri Olsamake_no_libaudit := NO_LIBAUDIT=1 78095ae69bSJiri Olsamake_no_libbionic := NO_LIBBIONIC=1 79e31f0d01SAdrian Huntermake_no_auxtrace := NO_AUXTRACE=1 80ed63f34cSWang Nanmake_no_libbpf := NO_LIBBPF=1 81095ae69bSJiri Olsamake_tags := tags 82095ae69bSJiri Olsamake_cscope := cscope 83095ae69bSJiri Olsamake_help := help 84095ae69bSJiri Olsamake_doc := doc 85095ae69bSJiri Olsamake_perf_o := perf.o 86095ae69bSJiri Olsamake_util_map_o := util/map.o 872a94f6c4SJiri Olsamake_util_pmu_bison_o := util/pmu-bison.o 88c0ec1108SJiri Olsamake_install := install 89c0ec1108SJiri Olsamake_install_bin := install-bin 90dbad4189SJiri Olsamake_install_doc := install-doc 91dbad4189SJiri Olsamake_install_man := install-man 92dbad4189SJiri Olsamake_install_html := install-html 93dbad4189SJiri Olsamake_install_info := install-info 94dbad4189SJiri Olsamake_install_pdf := install-pdf 95eb30d2c5SJiri Olsamake_install_prefix := install prefix=/tmp/krava 96aa53c09eSJiri Olsamake_install_prefix_slash := install prefix=/tmp/krava/ 97611ec127SJiri Olsamake_static := LDFLAGS=-static 98095ae69bSJiri Olsa 99095ae69bSJiri Olsa# all the NO_* variable combined 100095ae69bSJiri Olsamake_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 101095ae69bSJiri Olsamake_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 102095ae69bSJiri Olsamake_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 103ed63f34cSWang Nanmake_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 104095ae69bSJiri Olsa 105095ae69bSJiri Olsa# $(run) contains all available tests 106095ae69bSJiri Olsarun := make_pure 107502819c5SJiri Olsa# Targets 'clean all' can be run together only through top level 108502819c5SJiri Olsa# Makefile because we detect clean target in Makefile.perf and 109502819c5SJiri Olsa# disable features detection 110502819c5SJiri Olsaifeq ($(MK),Makefile) 111095ae69bSJiri Olsarun += make_clean_all 112502819c5SJiri Olsaendif 113095ae69bSJiri Olsarun += make_python_perf_so 114095ae69bSJiri Olsarun += make_debug 115095ae69bSJiri Olsarun += make_no_libperl 116095ae69bSJiri Olsarun += make_no_libpython 117095ae69bSJiri Olsarun += make_no_scripts 118095ae69bSJiri Olsarun += make_no_newt 119095ae69bSJiri Olsarun += make_no_slang 120095ae69bSJiri Olsarun += make_no_gtk2 121095ae69bSJiri Olsarun += make_no_ui 122095ae69bSJiri Olsarun += make_no_demangle 123095ae69bSJiri Olsarun += make_no_libelf 124095ae69bSJiri Olsarun += make_no_libunwind 1259e8c06eaSJiri Olsarun += make_no_libdw_dwarf_unwind 126095ae69bSJiri Olsarun += make_no_backtrace 127095ae69bSJiri Olsarun += make_no_libnuma 128095ae69bSJiri Olsarun += make_no_libaudit 129095ae69bSJiri Olsarun += make_no_libbionic 130e31f0d01SAdrian Hunterrun += make_no_auxtrace 131ed63f34cSWang Nanrun += make_no_libbpf 132095ae69bSJiri Olsarun += make_help 133095ae69bSJiri Olsarun += make_doc 134095ae69bSJiri Olsarun += make_perf_o 135095ae69bSJiri Olsarun += make_util_map_o 1362a94f6c4SJiri Olsarun += make_util_pmu_bison_o 137c0ec1108SJiri Olsarun += make_install 138c0ec1108SJiri Olsarun += make_install_bin 139eb30d2c5SJiri Olsarun += make_install_prefix 140aa53c09eSJiri Olsarun += make_install_prefix_slash 141dbad4189SJiri Olsa# FIXME 'install-*' commented out till they're fixed 142dbad4189SJiri Olsa# run += make_install_doc 143dbad4189SJiri Olsa# run += make_install_man 144dbad4189SJiri Olsa# run += make_install_html 145dbad4189SJiri Olsa# run += make_install_info 146dbad4189SJiri Olsa# run += make_install_pdf 147095ae69bSJiri Olsarun += make_minimal 148611ec127SJiri Olsarun += make_static 149095ae69bSJiri Olsa 1500659e669SJiri Olsaifneq ($(call has,ctags),) 1510659e669SJiri Olsarun += make_tags 1520659e669SJiri Olsaendif 1530659e669SJiri Olsaifneq ($(call has,cscope),) 1540659e669SJiri Olsarun += make_cscope 1550659e669SJiri Olsaendif 1560659e669SJiri Olsa 157095ae69bSJiri Olsa# $(run_O) contains same portion of $(run) tests with '_O' attached 158095ae69bSJiri Olsa# to distinguish O=... tests 159095ae69bSJiri Olsarun_O := $(addsuffix _O,$(run)) 160095ae69bSJiri Olsa 161095ae69bSJiri Olsa# disable some tests for O=... 162095ae69bSJiri Olsarun_O := $(filter-out make_python_perf_so_O,$(run_O)) 163095ae69bSJiri Olsa 164095ae69bSJiri Olsa# define test for each compile as 'test_NAME' variable 165095ae69bSJiri Olsa# with the test itself as a value 166095ae69bSJiri Olsatest_make_tags = test -f tags 167095ae69bSJiri Olsatest_make_cscope = test -f cscope.out 168095ae69bSJiri Olsa 169095ae69bSJiri Olsatest_make_tags_O := $(test_make_tags) 170095ae69bSJiri Olsatest_make_cscope_O := $(test_make_cscope) 171095ae69bSJiri Olsa 172095ae69bSJiri Olsatest_ok := true 173095ae69bSJiri Olsatest_make_help := $(test_ok) 174095ae69bSJiri Olsatest_make_doc := $(test_ok) 175095ae69bSJiri Olsatest_make_help_O := $(test_ok) 176095ae69bSJiri Olsatest_make_doc_O := $(test_ok) 177095ae69bSJiri Olsa 178*68824de1SWang Nantest_make_python_perf_so := test -f $(PERF_O)/python/perf.so 179095ae69bSJiri Olsa 180*68824de1SWang Nantest_make_perf_o := test -f $(PERF_O)/perf.o 181*68824de1SWang Nantest_make_util_map_o := test -f $(PERF_O)/util/map.o 182*68824de1SWang Nantest_make_util_pmu_bison_o := test -f $(PERF_O)/util/pmu-bison.o 183095ae69bSJiri Olsa 184ee4ad93eSJiri Olsadefine test_dest_files 185ee4ad93eSJiri Olsa for file in $(1); do \ 186ee4ad93eSJiri Olsa if [ ! -x $$TMP_DEST/$$file ]; then \ 187ee4ad93eSJiri Olsa echo " failed to find: $$file"; \ 188ee4ad93eSJiri Olsa fi \ 189ee4ad93eSJiri Olsa done 190ee4ad93eSJiri Olsaendef 191ee4ad93eSJiri Olsa 192ee4ad93eSJiri Olsainstalled_files_bin := bin/perf 193ee4ad93eSJiri Olsainstalled_files_bin += etc/bash_completion.d/perf 194ee4ad93eSJiri Olsainstalled_files_bin += libexec/perf-core/perf-archive 195ee4ad93eSJiri Olsa 196f7c64474SJiri Olsainstalled_files_plugins := $(lib)/traceevent/plugins/plugin_cfg80211.so 197f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_scsi.so 198f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_xen.so 199f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_function.so 200f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_sched_switch.so 201f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_mac80211.so 202f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_kvm.so 203f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_kmem.so 204f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_hrtimer.so 205f7c64474SJiri Olsainstalled_files_plugins += $(lib)/traceevent/plugins/plugin_jbd2.so 206ee4ad93eSJiri Olsa 207ee4ad93eSJiri Olsainstalled_files_all := $(installed_files_bin) 208ee4ad93eSJiri Olsainstalled_files_all += $(installed_files_plugins) 209ee4ad93eSJiri Olsa 210ee4ad93eSJiri Olsatest_make_install := $(call test_dest_files,$(installed_files_all)) 211ee4ad93eSJiri Olsatest_make_install_O := $(call test_dest_files,$(installed_files_all)) 212ee4ad93eSJiri Olsatest_make_install_bin := $(call test_dest_files,$(installed_files_bin)) 213ee4ad93eSJiri Olsatest_make_install_bin_O := $(call test_dest_files,$(installed_files_bin)) 214c0ec1108SJiri Olsa 215aa53c09eSJiri Olsa# We prefix all installed files for make_install_prefix(_slash) 216eb30d2c5SJiri Olsa# with '/tmp/krava' to match installed/prefix-ed files. 217eb30d2c5SJiri Olsainstalled_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all)) 218eb30d2c5SJiri Olsatest_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix)) 219eb30d2c5SJiri Olsatest_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix)) 220eb30d2c5SJiri Olsa 221aa53c09eSJiri Olsatest_make_install_prefix_slash := $(test_make_install_prefix) 222aa53c09eSJiri Olsatest_make_install_prefix_slash_O := $(test_make_install_prefix_O) 223aa53c09eSJiri Olsa 224dbad4189SJiri Olsa# FIXME nothing gets installed 225dbad4189SJiri Olsatest_make_install_man := test -f $$TMP_DEST/share/man/man1/perf.1 226dbad4189SJiri Olsatest_make_install_man_O := $(test_make_install_man) 227dbad4189SJiri Olsa 228dbad4189SJiri Olsa# FIXME nothing gets installed 229dbad4189SJiri Olsatest_make_install_doc := $(test_ok) 230dbad4189SJiri Olsatest_make_install_doc_O := $(test_ok) 231dbad4189SJiri Olsa 232dbad4189SJiri Olsa# FIXME nothing gets installed 233dbad4189SJiri Olsatest_make_install_html := $(test_ok) 234dbad4189SJiri Olsatest_make_install_html_O := $(test_ok) 235dbad4189SJiri Olsa 236dbad4189SJiri Olsa# FIXME nothing gets installed 237dbad4189SJiri Olsatest_make_install_info := $(test_ok) 238dbad4189SJiri Olsatest_make_install_info_O := $(test_ok) 239dbad4189SJiri Olsa 240dbad4189SJiri Olsa# FIXME nothing gets installed 241dbad4189SJiri Olsatest_make_install_pdf := $(test_ok) 242dbad4189SJiri Olsatest_make_install_pdf_O := $(test_ok) 243dbad4189SJiri Olsa 24404b01a1dSJiri Olsatest_make_python_perf_so_O := test -f $$TMP_O/python/perf.so 24504b01a1dSJiri Olsatest_make_perf_o_O := test -f $$TMP_O/perf.o 24604b01a1dSJiri Olsatest_make_util_map_o_O := test -f $$TMP_O/util/map.o 2472a94f6c4SJiri Olsatest_make_util_pmu_bison_o_O := test -f $$TMP_O/util/pmu-bison.o 248095ae69bSJiri Olsa 249*68824de1SWang Nantest_default = test -x $(PERF_O)/perf 250095ae69bSJiri Olsatest = $(if $(test_$1),$(test_$1),$(test_default)) 251095ae69bSJiri Olsa 2528ba7cdeaSJiri Olsatest_default_O = test -x $$TMP_O/perf 253095ae69bSJiri Olsatest_O = $(if $(test_$1),$(test_$1),$(test_default_O)) 254095ae69bSJiri Olsa 255095ae69bSJiri Olsaall: 256095ae69bSJiri Olsa 25798916392SArnaldo Carvalho de Meloifdef SHUF 25898916392SArnaldo Carvalho de Melorun := $(shell shuf -e $(run)) 25998916392SArnaldo Carvalho de Melorun_O := $(shell shuf -e $(run_O)) 26098916392SArnaldo Carvalho de Meloendif 26198916392SArnaldo Carvalho de Melo 262095ae69bSJiri Olsaifdef DEBUG 263095ae69bSJiri Olsad := $(info run $(run)) 264095ae69bSJiri Olsad := $(info run_O $(run_O)) 265095ae69bSJiri Olsaendif 266095ae69bSJiri Olsa 267095ae69bSJiri OlsaMAKEFLAGS := --no-print-directory 268095ae69bSJiri Olsa 269eb807730SWang Nanclean := @(cd $(PERF); make -s -f $(MK) $(O_OPT) clean >/dev/null) 270095ae69bSJiri Olsa 271095ae69bSJiri Olsa$(run): 272095ae69bSJiri Olsa $(call clean) 273c9311674SJiri Olsa @TMP_DEST=$$(mktemp -d); \ 274eb807730SWang Nan cmd="cd $(PERF) && make -f $(MK) $(PARALLEL_OPT) $(O_OPT) DESTDIR=$$TMP_DEST $($@)"; \ 275095ae69bSJiri Olsa echo "- $@: $$cmd" && echo $$cmd > $@ && \ 276095ae69bSJiri Olsa ( eval $$cmd ) >> $@ 2>&1; \ 277ee4ad93eSJiri Olsa echo " test: $(call test,$@)" >> $@ 2>&1; \ 278095ae69bSJiri Olsa $(call test,$@) && \ 279a5c5009fSArnaldo Carvalho de Melo rm -rf $@ $$TMP_DEST || (cat $@ ; false) 280095ae69bSJiri Olsa 281095ae69bSJiri Olsa$(run_O): 282095ae69bSJiri Olsa $(call clean) 2838ba7cdeaSJiri Olsa @TMP_O=$$(mktemp -d); \ 284c9311674SJiri Olsa TMP_DEST=$$(mktemp -d); \ 2857be43dfbSWang Nan cmd="cd $(PERF) && make -f $(MK) $(PARALLEL_OPT) O=$$TMP_O DESTDIR=$$TMP_DEST $($(patsubst %_O,%,$@))"; \ 286095ae69bSJiri Olsa echo "- $@: $$cmd" && echo $$cmd > $@ && \ 287095ae69bSJiri Olsa ( eval $$cmd ) >> $@ 2>&1 && \ 288ee4ad93eSJiri Olsa echo " test: $(call test_O,$@)" >> $@ 2>&1; \ 289095ae69bSJiri Olsa $(call test_O,$@) && \ 290a5c5009fSArnaldo Carvalho de Melo rm -rf $@ $$TMP_O $$TMP_DEST || (cat $@ ; false) 291095ae69bSJiri Olsa 29248878053SArnaldo Carvalho de Melotarpkg: 29348878053SArnaldo Carvalho de Melo @cmd="$(PERF)/tests/perf-targz-src-pkg $(PERF)"; \ 29448878053SArnaldo Carvalho de Melo echo "- $@: $$cmd" && echo $$cmd > $@ && \ 295004bd89dSJosh Poimboeuf ( eval $$cmd ) >> $@ 2>&1 && \ 296004bd89dSJosh Poimboeuf rm -f $@ 29748878053SArnaldo Carvalho de Melo 298*68824de1SWang NanKERNEL_O := ../.. 299*68824de1SWang Nanifneq ($(O),) 300*68824de1SWang Nan KERNEL_O := $(O) 301*68824de1SWang Nanendif 302*68824de1SWang Nan 303c41c6647SJiri Olsamake_kernelsrc: 3047be43dfbSWang Nan @echo "- make -C <kernelsrc> $(PARALLEL_OPT) tools/perf" 305c41c6647SJiri Olsa $(call clean); \ 3067be43dfbSWang Nan (make -C ../.. $(PARALLEL_OPT) tools/perf) > $@ 2>&1 && \ 307*68824de1SWang Nan test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false) 308c41c6647SJiri Olsa 309c41c6647SJiri Olsamake_kernelsrc_tools: 3107be43dfbSWang Nan @echo "- make -C <kernelsrc>/tools $(PARALLEL_OPT) perf" 311c41c6647SJiri Olsa $(call clean); \ 3127be43dfbSWang Nan (make -C ../../tools $(PARALLEL_OPT) perf) > $@ 2>&1 && \ 313*68824de1SWang Nan test -x $(KERNEL_O)/tools/perf/perf && rm -f $@ || (cat $@ ; false) 314c41c6647SJiri Olsa 315c41c6647SJiri Olsaall: $(run) $(run_O) tarpkg make_kernelsrc make_kernelsrc_tools 316095ae69bSJiri Olsa @echo OK 317095ae69bSJiri Olsa 318095ae69bSJiri Olsaout: $(run_O) 319095ae69bSJiri Olsa @echo OK 320095ae69bSJiri Olsa 3213167eea2SWang Nan.PHONY: all $(run) $(run_O) tarpkg clean make_kernelsrc make_kernelsrc_tools 322502819c5SJiri Olsaendif # ifndef MK 323