Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools build: Fix feature Makefile issues with 'O='

When building perf binaries outside the source tree with 'make O=<dir>',
the auto-detected features get re-tested for every build, which is
unnecessary and inconsistent with the behavior seen when building
directly in the source tree.

Another issue is that 'make O=<dir> clean' doesn't remove the feature
files from the object tree.

Fix these problems by looking for the binaries in the $(OUTPUT)
directory.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/113bd01530e9761778c60a75a96c65fc59860f68.1450193761.git.jpoimboe@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Josh Poimboeuf and committed by
Arnaldo Carvalho de Melo
1925459b 7a29c087

+48 -47
+1 -1
tools/build/Makefile.feature
··· 7 7 8 8 feature_check = $(eval $(feature_check_code)) 9 9 define feature_check_code 10 - 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) 10 + feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C $(feature_dir) $(OUTPUT_FEATURES)test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0) 11 11 endef 12 12 13 13 feature_set = $(eval $(feature_set_code))
+47 -46
tools/build/feature/Makefile
··· 1 - 2 1 FILES= \ 3 2 test-all.bin \ 4 3 test-backtrace.bin \ ··· 37 38 test-bpf.bin \ 38 39 test-get_cpuid.bin 39 40 41 + FILES := $(addprefix $(OUTPUT),$(FILES)) 42 + 40 43 CC := $(CROSS_COMPILE)gcc -MD 41 44 PKG_CONFIG := $(CROSS_COMPILE)pkg-config 42 45 43 46 all: $(FILES) 44 47 45 - __BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ $(patsubst %.bin,%.c,$@) $(LDFLAGS) 46 - BUILD = $(__BUILD) > $(OUTPUT)$(@:.bin=.make.output) 2>&1 48 + __BUILD = $(CC) $(CFLAGS) -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) 49 + BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 47 50 48 51 ############################### 49 52 50 - test-all.bin: 53 + $(OUTPUT)test-all.bin: 51 54 $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -laudit -I/usr/include/slang -lslang $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma 52 55 53 - test-hello.bin: 56 + $(OUTPUT)test-hello.bin: 54 57 $(BUILD) 55 58 56 - test-pthread-attr-setaffinity-np.bin: 59 + $(OUTPUT)test-pthread-attr-setaffinity-np.bin: 57 60 $(BUILD) -D_GNU_SOURCE -lpthread 58 61 59 - test-stackprotector-all.bin: 62 + $(OUTPUT)test-stackprotector-all.bin: 60 63 $(BUILD) -fstack-protector-all 61 64 62 - test-fortify-source.bin: 65 + $(OUTPUT)test-fortify-source.bin: 63 66 $(BUILD) -O2 -D_FORTIFY_SOURCE=2 64 67 65 - test-bionic.bin: 68 + $(OUTPUT)test-bionic.bin: 66 69 $(BUILD) 67 70 68 - test-libelf.bin: 71 + $(OUTPUT)test-libelf.bin: 69 72 $(BUILD) -lelf 70 73 71 - test-glibc.bin: 74 + $(OUTPUT)test-glibc.bin: 72 75 $(BUILD) 73 76 74 77 DWARFLIBS := -ldw ··· 78 77 DWARFLIBS += -lelf -lebl -lz -llzma -lbz2 79 78 endif 80 79 81 - test-dwarf.bin: 80 + $(OUTPUT)test-dwarf.bin: 82 81 $(BUILD) $(DWARFLIBS) 83 82 84 - test-libelf-mmap.bin: 83 + $(OUTPUT)test-libelf-mmap.bin: 85 84 $(BUILD) -lelf 86 85 87 - test-libelf-getphdrnum.bin: 86 + $(OUTPUT)test-libelf-getphdrnum.bin: 88 87 $(BUILD) -lelf 89 88 90 - test-libnuma.bin: 89 + $(OUTPUT)test-libnuma.bin: 91 90 $(BUILD) -lnuma 92 91 93 - test-numa_num_possible_cpus.bin: 92 + $(OUTPUT)test-numa_num_possible_cpus.bin: 94 93 $(BUILD) -lnuma 95 94 96 - test-libunwind.bin: 95 + $(OUTPUT)test-libunwind.bin: 97 96 $(BUILD) -lelf 98 97 99 - test-libunwind-debug-frame.bin: 98 + $(OUTPUT)test-libunwind-debug-frame.bin: 100 99 $(BUILD) -lelf 101 100 102 - test-libaudit.bin: 101 + $(OUTPUT)test-libaudit.bin: 103 102 $(BUILD) -laudit 104 103 105 - test-libslang.bin: 104 + $(OUTPUT)test-libslang.bin: 106 105 $(BUILD) -I/usr/include/slang -lslang 107 106 108 - test-gtk2.bin: 107 + $(OUTPUT)test-gtk2.bin: 109 108 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 110 109 111 - test-gtk2-infobar.bin: 110 + $(OUTPUT)test-gtk2-infobar.bin: 112 111 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 113 112 114 113 grep-libs = $(filter -l%,$(1)) ··· 120 119 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null` 121 120 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 122 121 123 - test-libperl.bin: 122 + $(OUTPUT)test-libperl.bin: 124 123 $(BUILD) $(FLAGS_PERL_EMBED) 125 124 126 - test-libpython.bin: 125 + $(OUTPUT)test-libpython.bin: 127 126 $(BUILD) 128 127 129 - test-libpython-version.bin: 128 + $(OUTPUT)test-libpython-version.bin: 130 129 $(BUILD) 131 130 132 - test-libbfd.bin: 131 + $(OUTPUT)test-libbfd.bin: 133 132 $(BUILD) -DPACKAGE='"perf"' -lbfd -lz -liberty -ldl 134 133 135 - test-liberty.bin: 136 - $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty 134 + $(OUTPUT)test-liberty.bin: 135 + $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty 137 136 138 - test-liberty-z.bin: 139 - $(CC) $(CFLAGS) -Wall -Werror -o $(OUTPUT)$@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz 137 + $(OUTPUT)test-liberty-z.bin: 138 + $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz 140 139 141 - test-cplus-demangle.bin: 140 + $(OUTPUT)test-cplus-demangle.bin: 142 141 $(BUILD) -liberty 143 142 144 - test-backtrace.bin: 143 + $(OUTPUT)test-backtrace.bin: 145 144 $(BUILD) 146 145 147 - test-timerfd.bin: 146 + $(OUTPUT)test-timerfd.bin: 148 147 $(BUILD) 149 148 150 - test-libdw-dwarf-unwind.bin: 149 + $(OUTPUT)test-libdw-dwarf-unwind.bin: 151 150 $(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind) 152 151 153 - test-libbabeltrace.bin: 152 + $(OUTPUT)test-libbabeltrace.bin: 154 153 $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace) 155 154 156 - test-sync-compare-and-swap.bin: 155 + $(OUTPUT)test-sync-compare-and-swap.bin: 157 156 $(BUILD) 158 157 159 - test-compile-32.bin: 160 - $(CC) -m32 -o $(OUTPUT)$@ test-compile.c 158 + $(OUTPUT)test-compile-32.bin: 159 + $(CC) -m32 -o $@ test-compile.c 161 160 162 - test-compile-x32.bin: 163 - $(CC) -mx32 -o $(OUTPUT)$@ test-compile.c 161 + $(OUTPUT)test-compile-x32.bin: 162 + $(CC) -mx32 -o $@ test-compile.c 164 163 165 - test-zlib.bin: 164 + $(OUTPUT)test-zlib.bin: 166 165 $(BUILD) -lz 167 166 168 - test-lzma.bin: 167 + $(OUTPUT)test-lzma.bin: 169 168 $(BUILD) -llzma 170 169 171 - test-get_cpuid.bin: 170 + $(OUTPUT)test-get_cpuid.bin: 172 171 $(BUILD) 173 172 174 - test-bpf.bin: 173 + $(OUTPUT)test-bpf.bin: 175 174 $(BUILD) 176 175 177 - -include *.d 176 + -include $(OUTPUT)*.d 178 177 179 178 ############################### 180 179 181 180 clean: 182 - rm -f $(FILES) *.d $(FILES:.bin=.make.output) 181 + rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)