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