| 1 |
|
| 2 | include ../../scripts/Makefile.include
|
| 3 |
|
| 4 | LIBUNWIND_ARCHS:=aarch64 arm loongarch64 mips ppc32 ppc64 riscv s390x x86 x86_64
|
| 5 |
|
| 6 | FILES= \
|
| 7 | test-all.bin \
|
| 8 | test-backtrace.bin \
|
| 9 | test-bionic.bin \
|
| 10 | test-libdw.bin \
|
| 11 | test-eventfd.bin \
|
| 12 | test-fortify-source.bin \
|
| 13 | test-glibc.bin \
|
| 14 | test-gtk2.bin \
|
| 15 | test-gtk2-infobar.bin \
|
| 16 | test-hello.bin \
|
| 17 | test-libbfd.bin \
|
| 18 | test-libbfd-threadsafe.bin \
|
| 19 | test-disassembler-four-args.bin \
|
| 20 | test-disassembler-init-styled.bin \
|
| 21 | test-reallocarray.bin \
|
| 22 | test-libbfd-liberty.bin \
|
| 23 | test-libbfd-liberty-z.bin \
|
| 24 | test-cplus-demangle.bin \
|
| 25 | test-cxa-demangle.bin \
|
| 26 | test-libcap.bin \
|
| 27 | test-libelf.bin \
|
| 28 | test-libelf-getphdrnum.bin \
|
| 29 | test-libelf-gelf_getnote.bin \
|
| 30 | test-libelf-getshdrstrndx.bin \
|
| 31 | test-libelf-zstd.bin \
|
| 32 | test-libdebuginfod.bin \
|
| 33 | test-libnuma.bin \
|
| 34 | test-numa_num_possible_cpus.bin \
|
| 35 | test-libperl.bin \
|
| 36 | test-libpython.bin \
|
| 37 | test-libslang.bin \
|
| 38 | test-libtraceevent.bin \
|
| 39 | test-libcpupower.bin \
|
| 40 | test-libtracefs.bin \
|
| 41 | test-libunwind.bin \
|
| 42 | test-libunwind-debug-frame.bin \
|
| 43 | $(foreach arch,$(LIBUNWIND_ARCHS),test-libunwind-$(arch).bin test-libunwind-debug-frame-$(arch).bin) \
|
| 44 | test-pthread-attr-setaffinity-np.bin \
|
| 45 | test-pthread-barrier.bin \
|
| 46 | test-stackprotector-all.bin \
|
| 47 | test-timerfd.bin \
|
| 48 | test-babeltrace2-ctf-writer.bin \
|
| 49 | test-libcapstone.bin \
|
| 50 | test-libcheck.bin \
|
| 51 | test-compile-32.bin \
|
| 52 | test-compile-x32.bin \
|
| 53 | test-zlib.bin \
|
| 54 | test-lzma.bin \
|
| 55 | test-bpf.bin \
|
| 56 | test-libbpf.bin \
|
| 57 | test-sdt.bin \
|
| 58 | test-gettid.bin \
|
| 59 | test-jvmti.bin \
|
| 60 | test-jvmti-cmlr.bin \
|
| 61 | test-scandirat.bin \
|
| 62 | test-sched_getcpu.bin \
|
| 63 | test-setns.bin \
|
| 64 | test-libopencsd.bin \
|
| 65 | test-llvm.bin \
|
| 66 | test-llvm-perf.bin \
|
| 67 | test-libaio.bin \
|
| 68 | test-libzstd.bin \
|
| 69 | test-clang-bpf-co-re.bin \
|
| 70 | test-file-handle.bin \
|
| 71 | test-libpfm4.bin \
|
| 72 | test-rust.bin \
|
| 73 | test-libopenssl.bin \
|
| 74 | test-bpftool-skeletons.bin
|
| 75 |
|
| 76 | FILES := $(addprefix $(OUTPUT),$(FILES))
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 | ifneq (, $(shell which $(CROSS_COMPILE)pkg-config))
|
| 82 | PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
|
| 83 | else
|
| 84 | PKG_CONFIG ?= pkg-config
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 | ifdef CROSS_COMPILE
|
| 91 | ifeq ($(PKG_CONFIG_LIBDIR)$(PKG_CONFIG_PATH)$(PKG_CONFIG_SYSROOT_DIR),)
|
| 92 | CROSS_ARCH = $(notdir $(CROSS_COMPILE:%-=%))
|
| 93 | PKG_CONFIG_LIBDIR := /usr/local/$(CROSS_ARCH)/lib/pkgconfig/
|
| 94 | PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/lib/$(CROSS_ARCH)/pkgconfig/
|
| 95 | PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/lib/$(CROSS_ARCH)/pkgconfig/
|
| 96 | PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/local/share/pkgconfig/
|
| 97 | PKG_CONFIG_LIBDIR := $(PKG_CONFIG_LIBDIR):/usr/share/pkgconfig/
|
| 98 | export PKG_CONFIG_LIBDIR
|
| 99 | endif
|
| 100 | endif
|
| 101 | endif
|
| 102 |
|
| 103 | ifeq ($(findstring -static,${LDFLAGS}),-static)
|
| 104 | PKG_CONFIG += --static
|
| 105 | endif
|
| 106 |
|
| 107 | all: $(FILES)
|
| 108 |
|
| 109 | __BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS)
|
| 110 | BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1
|
| 111 | BUILD_BFD = $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl
|
| 112 | BUILD_ALL = $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang \
|
| 113 | $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -ldl -lz -llzma -lzstd \
|
| 114 | $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null)
|
| 115 |
|
| 116 | __BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS)
|
| 117 | BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 | $(OUTPUT)test-all.bin:
|
| 122 | $(BUILD_ALL)
|
| 123 |
|
| 124 | $(OUTPUT)test-hello.bin:
|
| 125 | $(BUILD)
|
| 126 |
|
| 127 | $(OUTPUT)test-pthread-attr-setaffinity-np.bin:
|
| 128 | $(BUILD) -D_GNU_SOURCE -lpthread
|
| 129 |
|
| 130 | $(OUTPUT)test-pthread-barrier.bin:
|
| 131 | $(BUILD) -lpthread
|
| 132 |
|
| 133 | $(OUTPUT)test-stackprotector-all.bin:
|
| 134 | $(BUILD) -fstack-protector-all
|
| 135 |
|
| 136 | $(OUTPUT)test-fortify-source.bin:
|
| 137 | $(BUILD) -O2 -D_FORTIFY_SOURCE=2
|
| 138 |
|
| 139 | $(OUTPUT)test-bionic.bin:
|
| 140 | $(BUILD)
|
| 141 |
|
| 142 | $(OUTPUT)test-libcap.bin:
|
| 143 | $(BUILD) -lcap
|
| 144 |
|
| 145 | $(OUTPUT)test-libelf.bin:
|
| 146 | $(BUILD) -lelf
|
| 147 |
|
| 148 | $(OUTPUT)test-eventfd.bin:
|
| 149 | $(BUILD)
|
| 150 |
|
| 151 | $(OUTPUT)test-glibc.bin:
|
| 152 | $(BUILD)
|
| 153 |
|
| 154 | $(OUTPUT)test-scandirat.bin:
|
| 155 | $(BUILD)
|
| 156 |
|
| 157 | $(OUTPUT)test-sched_getcpu.bin:
|
| 158 | $(BUILD)
|
| 159 |
|
| 160 | $(OUTPUT)test-setns.bin:
|
| 161 | $(BUILD)
|
| 162 |
|
| 163 | $(OUTPUT)test-libopencsd.bin:
|
| 164 | $(BUILD) # -lopencsd_c_api -lopencsd provided by
|
| 165 |
|
| 166 |
|
| 167 | DWLIBS := -ldw
|
| 168 | ifeq ($(findstring -static,${LDFLAGS}),-static)
|
| 169 | DWLIBS += -lelf -lz -llzma -lbz2 -lzstd
|
| 170 |
|
| 171 | LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw).0.0
|
| 172 | LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
|
| 173 | LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 | ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
|
| 178 | DWLIBS += -lebl
|
| 179 | endif
|
| 180 |
|
| 181 |
|
| 182 | DWARFLIBS += -ldl
|
| 183 | endif
|
| 184 |
|
| 185 | $(OUTPUT)test-libdw.bin:
|
| 186 | $(BUILD) $(DWLIBS)
|
| 187 |
|
| 188 | $(OUTPUT)test-libelf-getphdrnum.bin:
|
| 189 | $(BUILD) -lelf
|
| 190 |
|
| 191 | $(OUTPUT)test-libelf-gelf_getnote.bin:
|
| 192 | $(BUILD) -lelf
|
| 193 |
|
| 194 | $(OUTPUT)test-libelf-getshdrstrndx.bin:
|
| 195 | $(BUILD) -lelf
|
| 196 |
|
| 197 | $(OUTPUT)test-libelf-zstd.bin:
|
| 198 | $(BUILD) -lelf -lz -lzstd
|
| 199 |
|
| 200 | $(OUTPUT)test-libdebuginfod.bin:
|
| 201 | $(BUILD) -ldebuginfod
|
| 202 |
|
| 203 | $(OUTPUT)test-libnuma.bin:
|
| 204 | $(BUILD) -lnuma
|
| 205 |
|
| 206 | $(OUTPUT)test-numa_num_possible_cpus.bin:
|
| 207 | $(BUILD) -lnuma
|
| 208 |
|
| 209 | $(OUTPUT)test-libunwind.bin:
|
| 210 | $(BUILD) -include libunwind.h -lelf -llzma -lunwind
|
| 211 |
|
| 212 | $(OUTPUT)test-libunwind-debug-frame.bin:
|
| 213 | $(BUILD) -include libunwind.h -lelf -llzma -lunwind
|
| 214 |
|
| 215 | define LIBUNWIND_RULE
|
| 216 | $$(OUTPUT)test-libunwind-$(1).bin:
|
| 217 | $$(CC) $$(CFLAGS) -MD -Wall -Werror -include libunwind-$(1).h -o $$@ \
|
| 218 | test-libunwind.c $$(LDFLAGS) -lelf -llzma -lunwind-$(1) \
|
| 219 | > $$(@:.bin=.make.output) 2>&1
|
| 220 |
|
| 221 | $$(OUTPUT)test-libunwind-debug-frame-$(1).bin:
|
| 222 | $$(CC) $$(CFLAGS) -MD -Wall -Werror -include libunwind-$(1).h -o $$@ \
|
| 223 | test-libunwind-debug-frame.c $$(LDFLAGS) -lelf -llzma -lunwind-$(1) \
|
| 224 | > $$(@:.bin=.make.output) 2>&1
|
| 225 |
|
| 226 | endef
|
| 227 | $(foreach arch,$(LIBUNWIND_ARCHS), \
|
| 228 | $(eval $(call LIBUNWIND_RULE,$(arch))) \
|
| 229 | )
|
| 230 |
|
| 231 | $(OUTPUT)test-libslang.bin:
|
| 232 | $(BUILD) -lslang
|
| 233 |
|
| 234 | $(OUTPUT)test-libtraceevent.bin:
|
| 235 | $(BUILD) -ltraceevent
|
| 236 |
|
| 237 | $(OUTPUT)test-libcpupower.bin:
|
| 238 | $(BUILD) -lcpupower
|
| 239 |
|
| 240 | $(OUTPUT)test-libtracefs.bin:
|
| 241 | $(BUILD) $(shell $(PKG_CONFIG) --cflags libtracefs 2>/dev/null) -ltracefs
|
| 242 |
|
| 243 | $(OUTPUT)test-gtk2.bin:
|
| 244 | $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations
|
| 245 |
|
| 246 | $(OUTPUT)test-gtk2-infobar.bin:
|
| 247 | $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
|
| 248 |
|
| 249 | grep-libs = $(filter -l%,$(1))
|
| 250 | strip-libs = $(filter-out -l%,$(1))
|
| 251 |
|
| 252 | PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
|
| 253 | PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
|
| 254 | PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
|
| 255 | PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
|
| 256 | FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
|
| 257 |
|
| 258 | ifeq ($(CC_NO_CLANG), 0)
|
| 259 | PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
|
| 260 | PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
|
| 261 | PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
|
| 262 | FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro
|
| 263 | endif
|
| 264 |
|
| 265 | $(OUTPUT)test-libperl.bin:
|
| 266 | $(BUILD) $(FLAGS_PERL_EMBED)
|
| 267 |
|
| 268 | $(OUTPUT)test-libpython.bin:
|
| 269 | $(BUILD) $(FLAGS_PYTHON_EMBED)
|
| 270 |
|
| 271 | $(OUTPUT)test-libbfd.bin:
|
| 272 | $(BUILD_BFD)
|
| 273 |
|
| 274 | $(OUTPUT)test-libbfd-threadsafe.bin:
|
| 275 | $(BUILD_BFD) || $(BUILD_BFD) -liberty || $(BUILD_BFD) -liberty -lz
|
| 276 |
|
| 277 | $(OUTPUT)test-disassembler-four-args.bin:
|
| 278 | $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
|
| 279 | $(BUILD_BFD) -lopcodes -liberty -lz
|
| 280 |
|
| 281 | $(OUTPUT)test-disassembler-init-styled.bin:
|
| 282 | $(BUILD_BFD) -lopcodes || $(BUILD_BFD) -lopcodes -liberty || \
|
| 283 | $(BUILD_BFD) -lopcodes -liberty -lz
|
| 284 |
|
| 285 | $(OUTPUT)test-reallocarray.bin:
|
| 286 | $(BUILD)
|
| 287 |
|
| 288 | $(OUTPUT)test-libbfd-liberty.bin:
|
| 289 | $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty
|
| 290 |
|
| 291 | $(OUTPUT)test-libbfd-liberty-z.bin:
|
| 292 | $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz
|
| 293 |
|
| 294 | $(OUTPUT)test-cplus-demangle.bin:
|
| 295 | $(BUILD) -liberty
|
| 296 |
|
| 297 | $(OUTPUT)test-cxa-demangle.bin:
|
| 298 | $(BUILDXX)
|
| 299 |
|
| 300 | $(OUTPUT)test-backtrace.bin:
|
| 301 | $(BUILD)
|
| 302 |
|
| 303 | $(OUTPUT)test-timerfd.bin:
|
| 304 | $(BUILD)
|
| 305 |
|
| 306 | $(OUTPUT)test-babeltrace2-ctf-writer.bin:
|
| 307 | $(BUILD) # -lbabeltrace2-ctf-writer provided by $(FEATURE_CHECK_LDFLAGS-babeltrace2-ctf-writer)
|
| 308 |
|
| 309 | $(OUTPUT)test-libcapstone.bin:
|
| 310 | $(BUILD) # -lcapstone provided by $(FEATURE_CHECK_LDFLAGS-libcapstone)
|
| 311 |
|
| 312 | $(OUTPUT)test-libcheck.bin:
|
| 313 | $(BUILD) # -lcheck is provided by $(FEATURE_CHECK_LDFLAGS-libcheck)
|
| 314 |
|
| 315 | $(OUTPUT)test-compile-32.bin:
|
| 316 | $(CC) -m32 -Wall -Werror -o $@ test-compile.c
|
| 317 |
|
| 318 | $(OUTPUT)test-compile-x32.bin:
|
| 319 | $(CC) -mx32 -Wall -Werror -o $@ test-compile.c
|
| 320 |
|
| 321 | $(OUTPUT)test-zlib.bin:
|
| 322 | $(BUILD) -lz
|
| 323 |
|
| 324 | $(OUTPUT)test-lzma.bin:
|
| 325 | $(BUILD) -llzma
|
| 326 |
|
| 327 | $(OUTPUT)test-bpf.bin:
|
| 328 | $(BUILD)
|
| 329 |
|
| 330 | $(OUTPUT)test-libbpf.bin:
|
| 331 | $(BUILD) -lbpf
|
| 332 |
|
| 333 | $(OUTPUT)test-sdt.bin:
|
| 334 | $(BUILD)
|
| 335 |
|
| 336 | $(OUTPUT)test-gettid.bin:
|
| 337 | $(BUILD)
|
| 338 |
|
| 339 | $(OUTPUT)test-jvmti.bin:
|
| 340 | $(BUILD)
|
| 341 |
|
| 342 | $(OUTPUT)test-jvmti-cmlr.bin:
|
| 343 | $(BUILD)
|
| 344 |
|
| 345 | $(OUTPUT)test-llvm.bin:
|
| 346 | $(BUILDXX) -std=gnu++17 \
|
| 347 | -I$(shell $(LLVM_CONFIG) --includedir) \
|
| 348 | -L$(shell $(LLVM_CONFIG) --libdir) \
|
| 349 | $(shell $(LLVM_CONFIG) --libs Core BPF) \
|
| 350 | $(shell $(LLVM_CONFIG) --system-libs) \
|
| 351 | > $(@:.bin=.make.output) 2>&1
|
| 352 |
|
| 353 | $(OUTPUT)test-llvm-perf.bin:
|
| 354 | $(BUILDXX) -std=gnu++17 \
|
| 355 | -I$(shell $(LLVM_CONFIG) --includedir) \
|
| 356 | -L$(shell $(LLVM_CONFIG) --libdir) \
|
| 357 | $(shell $(LLVM_CONFIG) --libs Core BPF) \
|
| 358 | $(shell $(LLVM_CONFIG) --system-libs) \
|
| 359 | > $(@:.bin=.make.output) 2>&1
|
| 360 |
|
| 361 | -include $(OUTPUT)*.d
|
| 362 |
|
| 363 | $(OUTPUT)test-libaio.bin:
|
| 364 | $(BUILD) -lrt
|
| 365 |
|
| 366 | $(OUTPUT)test-libzstd.bin:
|
| 367 | $(BUILD) -lzstd
|
| 368 |
|
| 369 | $(OUTPUT)test-clang-bpf-co-re.bin: test-clang-bpf-co-re.c
|
| 370 | { $(CLANG) -S -g --target=bpf -o - $< | \
|
| 371 | grep BTF_KIND_VAR; } > $(@:.bin=.make.output) 2>&1 && touch $@
|
| 372 |
|
| 373 | $(OUTPUT)test-file-handle.bin:
|
| 374 | $(BUILD)
|
| 375 |
|
| 376 | $(OUTPUT)test-libpfm4.bin:
|
| 377 | $(BUILD) -lpfm
|
| 378 |
|
| 379 | $(OUTPUT)test-libopenssl.bin:
|
| 380 | $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags openssl 2>/dev/null)
|
| 381 |
|
| 382 | $(OUTPUT)test-bpftool-skeletons.bin:
|
| 383 | { $(SYSTEM_BPFTOOL) version | grep '^features:.*skeletons'; } \
|
| 384 | > $(@:.bin=.make.output) 2>&1 && touch $@
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 | $(OUTPUT)test-rust.bin:
|
| 392 | $(RUSTC) --version > /dev/null 2>&1
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 | clean:
|
| 397 | rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output)
|