Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 1 | PERF := . |
| 2 | MK := Makefile |
| 3 | |
Jiri Olsa | 0659e66 | 2013-07-22 14:43:30 +0200 | [diff] [blame] | 4 | has = $(shell which $1 2>/dev/null) |
| 5 | |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 6 | # standard single make variable specified |
| 7 | make_clean_all := clean all |
| 8 | make_python_perf_so := python/perf.so |
| 9 | make_debug := DEBUG=1 |
| 10 | make_no_libperl := NO_LIBPERL=1 |
| 11 | make_no_libpython := NO_LIBPYTHON=1 |
| 12 | make_no_scripts := NO_LIBPYTHON=1 NO_LIBPERL=1 |
| 13 | make_no_newt := NO_NEWT=1 |
| 14 | make_no_slang := NO_SLANG=1 |
| 15 | make_no_gtk2 := NO_GTK2=1 |
| 16 | make_no_ui := NO_NEWT=1 NO_SLANG=1 NO_GTK2=1 |
| 17 | make_no_demangle := NO_DEMANGLE=1 |
| 18 | make_no_libelf := NO_LIBELF=1 |
| 19 | make_no_libunwind := NO_LIBUNWIND=1 |
| 20 | make_no_backtrace := NO_BACKTRACE=1 |
| 21 | make_no_libnuma := NO_LIBNUMA=1 |
| 22 | make_no_libaudit := NO_LIBAUDIT=1 |
| 23 | make_no_libbionic := NO_LIBBIONIC=1 |
| 24 | make_tags := tags |
| 25 | make_cscope := cscope |
| 26 | make_help := help |
| 27 | make_doc := doc |
| 28 | make_perf_o := perf.o |
| 29 | make_util_map_o := util/map.o |
Jiri Olsa | c0ec110 | 2013-07-22 14:43:33 +0200 | [diff] [blame^] | 30 | make_install := install |
| 31 | make_install_bin := install-bin |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 32 | |
| 33 | # all the NO_* variable combined |
| 34 | make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 |
| 35 | make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 |
| 36 | make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 |
| 37 | |
| 38 | # $(run) contains all available tests |
| 39 | run := make_pure |
| 40 | run += make_clean_all |
| 41 | run += make_python_perf_so |
| 42 | run += make_debug |
| 43 | run += make_no_libperl |
| 44 | run += make_no_libpython |
| 45 | run += make_no_scripts |
| 46 | run += make_no_newt |
| 47 | run += make_no_slang |
| 48 | run += make_no_gtk2 |
| 49 | run += make_no_ui |
| 50 | run += make_no_demangle |
| 51 | run += make_no_libelf |
| 52 | run += make_no_libunwind |
| 53 | run += make_no_backtrace |
| 54 | run += make_no_libnuma |
| 55 | run += make_no_libaudit |
| 56 | run += make_no_libbionic |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 57 | run += make_help |
| 58 | run += make_doc |
| 59 | run += make_perf_o |
| 60 | run += make_util_map_o |
Jiri Olsa | c0ec110 | 2013-07-22 14:43:33 +0200 | [diff] [blame^] | 61 | run += make_install |
| 62 | run += make_install_bin |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 63 | run += make_minimal |
| 64 | |
Jiri Olsa | 0659e66 | 2013-07-22 14:43:30 +0200 | [diff] [blame] | 65 | ifneq ($(call has,ctags),) |
| 66 | run += make_tags |
| 67 | endif |
| 68 | ifneq ($(call has,cscope),) |
| 69 | run += make_cscope |
| 70 | endif |
| 71 | |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 72 | # $(run_O) contains same portion of $(run) tests with '_O' attached |
| 73 | # to distinguish O=... tests |
| 74 | run_O := $(addsuffix _O,$(run)) |
| 75 | |
| 76 | # disable some tests for O=... |
| 77 | run_O := $(filter-out make_python_perf_so_O,$(run_O)) |
| 78 | |
| 79 | # define test for each compile as 'test_NAME' variable |
| 80 | # with the test itself as a value |
| 81 | test_make_tags = test -f tags |
| 82 | test_make_cscope = test -f cscope.out |
| 83 | |
| 84 | test_make_tags_O := $(test_make_tags) |
| 85 | test_make_cscope_O := $(test_make_cscope) |
| 86 | |
| 87 | test_ok := true |
| 88 | test_make_help := $(test_ok) |
| 89 | test_make_doc := $(test_ok) |
| 90 | test_make_help_O := $(test_ok) |
| 91 | test_make_doc_O := $(test_ok) |
| 92 | |
| 93 | test_make_python_perf_so := test -f $(PERF)/python/perf.so |
| 94 | |
| 95 | test_make_perf_o := test -f $(PERF)/perf.o |
| 96 | test_make_util_map_o := test -f $(PERF)/util/map.o |
| 97 | |
Jiri Olsa | c0ec110 | 2013-07-22 14:43:33 +0200 | [diff] [blame^] | 98 | test_make_install := test -x $$TMP_DEST/bin/perf |
| 99 | test_make_install_O := $(test_make_install) |
| 100 | test_make_install_bin := $(test_make_install) |
| 101 | test_make_install_bin_O := $(test_make_install) |
| 102 | |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 103 | # Kbuild tests only |
| 104 | #test_make_python_perf_so_O := test -f $$TMP/tools/perf/python/perf.so |
| 105 | #test_make_perf_o_O := test -f $$TMP/tools/perf/perf.o |
| 106 | #test_make_util_map_o_O := test -f $$TMP/tools/perf/util/map.o |
| 107 | |
| 108 | test_make_perf_o_O := true |
| 109 | test_make_util_map_o_O := true |
| 110 | |
| 111 | test_default = test -x $(PERF)/perf |
| 112 | test = $(if $(test_$1),$(test_$1),$(test_default)) |
| 113 | |
Jiri Olsa | 8ba7cde | 2013-07-22 14:43:31 +0200 | [diff] [blame] | 114 | test_default_O = test -x $$TMP_O/perf |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 115 | test_O = $(if $(test_$1),$(test_$1),$(test_default_O)) |
| 116 | |
| 117 | all: |
| 118 | |
| 119 | ifdef DEBUG |
| 120 | d := $(info run $(run)) |
| 121 | d := $(info run_O $(run_O)) |
| 122 | endif |
| 123 | |
| 124 | MAKEFLAGS := --no-print-directory |
| 125 | |
| 126 | clean := @(cd $(PERF); make -s -f $(MK) clean >/dev/null) |
| 127 | |
| 128 | $(run): |
| 129 | $(call clean) |
Jiri Olsa | c931167 | 2013-07-22 14:43:32 +0200 | [diff] [blame] | 130 | @TMP_DEST=$$(mktemp -d); \ |
| 131 | cmd="cd $(PERF) && make -f $(MK) DESTDIR=$$TMP_DEST $($@)"; \ |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 132 | echo "- $@: $$cmd" && echo $$cmd > $@ && \ |
| 133 | ( eval $$cmd ) >> $@ 2>&1; \ |
| 134 | echo " test: $(call test,$@)"; \ |
| 135 | $(call test,$@) && \ |
Jiri Olsa | c931167 | 2013-07-22 14:43:32 +0200 | [diff] [blame] | 136 | rm -f $@ \ |
| 137 | rm -rf $$TMP_DEST |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 138 | |
| 139 | $(run_O): |
| 140 | $(call clean) |
Jiri Olsa | 8ba7cde | 2013-07-22 14:43:31 +0200 | [diff] [blame] | 141 | @TMP_O=$$(mktemp -d); \ |
Jiri Olsa | c931167 | 2013-07-22 14:43:32 +0200 | [diff] [blame] | 142 | TMP_DEST=$$(mktemp -d); \ |
| 143 | cmd="cd $(PERF) && make -f $(MK) O=$$TMP_O DESTDIR=$$TMP_DEST $($(patsubst %_O,%,$@))"; \ |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 144 | echo "- $@: $$cmd" && echo $$cmd > $@ && \ |
| 145 | ( eval $$cmd ) >> $@ 2>&1 && \ |
| 146 | echo " test: $(call test_O,$@)"; \ |
| 147 | $(call test_O,$@) && \ |
| 148 | rm -f $@ && \ |
Jiri Olsa | c931167 | 2013-07-22 14:43:32 +0200 | [diff] [blame] | 149 | rm -rf $$TMP_O \ |
| 150 | rm -rf $$TMP_DEST |
Jiri Olsa | 095ae69 | 2013-03-29 16:11:02 +0100 | [diff] [blame] | 151 | |
| 152 | all: $(run) $(run_O) |
| 153 | @echo OK |
| 154 | |
| 155 | out: $(run_O) |
| 156 | @echo OK |
| 157 | |
| 158 | .PHONY: all $(run) $(run_O) clean |