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