1# SPDX-License-Identifier: GPL-2.0 2include ../../scripts/Makefile.include 3 4FILES= \ 5 test-all.bin \ 6 test-backtrace.bin \ 7 test-bionic.bin \ 8 test-dwarf.bin \ 9 test-dwarf_getlocations.bin \ 10 test-eventfd.bin \ 11 test-fortify-source.bin \ 12 test-get_current_dir_name.bin \ 13 test-glibc.bin \ 14 test-gtk2.bin \ 15 test-gtk2-infobar.bin \ 16 test-hello.bin \ 17 test-libaudit.bin \ 18 test-libbfd.bin \ 19 test-libbfd-buildid.bin \ 20 test-disassembler-four-args.bin \ 21 test-reallocarray.bin \ 22 test-libbfd-liberty.bin \ 23 test-libbfd-liberty-z.bin \ 24 test-cplus-demangle.bin \ 25 test-libcap.bin \ 26 test-libelf.bin \ 27 test-libelf-getphdrnum.bin \ 28 test-libelf-gelf_getnote.bin \ 29 test-libelf-getshdrstrndx.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-libslang-include-subdir.bin \ 37 test-libtraceevent.bin \ 38 test-libtracefs.bin \ 39 test-libcrypto.bin \ 40 test-libunwind.bin \ 41 test-libunwind-debug-frame.bin \ 42 test-libunwind-x86.bin \ 43 test-libunwind-x86_64.bin \ 44 test-libunwind-arm.bin \ 45 test-libunwind-aarch64.bin \ 46 test-libunwind-debug-frame-arm.bin \ 47 test-libunwind-debug-frame-aarch64.bin \ 48 test-pthread-attr-setaffinity-np.bin \ 49 test-pthread-barrier.bin \ 50 test-stackprotector-all.bin \ 51 test-timerfd.bin \ 52 test-libdw-dwarf-unwind.bin \ 53 test-libbabeltrace.bin \ 54 test-compile-32.bin \ 55 test-compile-x32.bin \ 56 test-zlib.bin \ 57 test-lzma.bin \ 58 test-bpf.bin \ 59 test-libbpf.bin \ 60 test-libbpf-btf__load_from_kernel_by_id.bin \ 61 test-get_cpuid.bin \ 62 test-sdt.bin \ 63 test-cxx.bin \ 64 test-gettid.bin \ 65 test-jvmti.bin \ 66 test-jvmti-cmlr.bin \ 67 test-sched_getcpu.bin \ 68 test-setns.bin \ 69 test-libopencsd.bin \ 70 test-clang.bin \ 71 test-llvm.bin \ 72 test-llvm-version.bin \ 73 test-libaio.bin \ 74 test-libzstd.bin \ 75 test-clang-bpf-co-re.bin \ 76 test-file-handle.bin \ 77 test-libpfm4.bin 78 79FILES := $(addprefix $(OUTPUT),$(FILES)) 80 81PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config 82 83all: $(FILES) 84 85__BUILD = $(CC) $(CFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.c,$(@F)) $(LDFLAGS) 86 BUILD = $(__BUILD) > $(@:.bin=.make.output) 2>&1 87 88__BUILDXX = $(CXX) $(CXXFLAGS) -MD -Wall -Werror -o $@ $(patsubst %.bin,%.cpp,$(@F)) $(LDFLAGS) 89 BUILDXX = $(__BUILDXX) > $(@:.bin=.make.output) 2>&1 90 91############################### 92 93$(OUTPUT)test-all.bin: 94 $(BUILD) -fstack-protector-all -O2 -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lelf -lslang $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl -lz -llzma -lzstd -lcap 95 96$(OUTPUT)test-hello.bin: 97 $(BUILD) 98 99$(OUTPUT)test-pthread-attr-setaffinity-np.bin: 100 $(BUILD) -D_GNU_SOURCE -lpthread 101 102$(OUTPUT)test-pthread-barrier.bin: 103 $(BUILD) -lpthread 104 105$(OUTPUT)test-stackprotector-all.bin: 106 $(BUILD) -fstack-protector-all 107 108$(OUTPUT)test-fortify-source.bin: 109 $(BUILD) -O2 -D_FORTIFY_SOURCE=2 110 111$(OUTPUT)test-bionic.bin: 112 $(BUILD) 113 114$(OUTPUT)test-libcap.bin: 115 $(BUILD) -lcap 116 117$(OUTPUT)test-libelf.bin: 118 $(BUILD) -lelf 119 120$(OUTPUT)test-eventfd.bin: 121 $(BUILD) 122 123$(OUTPUT)test-get_current_dir_name.bin: 124 $(BUILD) 125 126$(OUTPUT)test-glibc.bin: 127 $(BUILD) 128 129$(OUTPUT)test-sched_getcpu.bin: 130 $(BUILD) 131 132$(OUTPUT)test-setns.bin: 133 $(BUILD) 134 135$(OUTPUT)test-libopencsd.bin: 136 $(BUILD) # -lopencsd_c_api -lopencsd provided by 137 # $(FEATURE_CHECK_LDFLAGS-libopencsd) 138 139DWARFLIBS := -ldw 140ifeq ($(findstring -static,${LDFLAGS}),-static) 141DWARFLIBS += -lelf -lebl -lz -llzma -lbz2 142endif 143 144$(OUTPUT)test-dwarf.bin: 145 $(BUILD) $(DWARFLIBS) 146 147$(OUTPUT)test-dwarf_getlocations.bin: 148 $(BUILD) $(DWARFLIBS) 149 150$(OUTPUT)test-libelf-getphdrnum.bin: 151 $(BUILD) -lelf 152 153$(OUTPUT)test-libelf-gelf_getnote.bin: 154 $(BUILD) -lelf 155 156$(OUTPUT)test-libelf-getshdrstrndx.bin: 157 $(BUILD) -lelf 158 159$(OUTPUT)test-libdebuginfod.bin: 160 $(BUILD) -ldebuginfod 161 162$(OUTPUT)test-libnuma.bin: 163 $(BUILD) -lnuma 164 165$(OUTPUT)test-numa_num_possible_cpus.bin: 166 $(BUILD) -lnuma 167 168$(OUTPUT)test-libunwind.bin: 169 $(BUILD) -lelf 170 171$(OUTPUT)test-libunwind-debug-frame.bin: 172 $(BUILD) -lelf 173$(OUTPUT)test-libunwind-x86.bin: 174 $(BUILD) -lelf -lunwind-x86 175 176$(OUTPUT)test-libunwind-x86_64.bin: 177 $(BUILD) -lelf -lunwind-x86_64 178 179$(OUTPUT)test-libunwind-arm.bin: 180 $(BUILD) -lelf -lunwind-arm 181 182$(OUTPUT)test-libunwind-aarch64.bin: 183 $(BUILD) -lelf -lunwind-aarch64 184 185$(OUTPUT)test-libunwind-debug-frame-arm.bin: 186 $(BUILD) -lelf -lunwind-arm 187 188$(OUTPUT)test-libunwind-debug-frame-aarch64.bin: 189 $(BUILD) -lelf -lunwind-aarch64 190 191$(OUTPUT)test-libaudit.bin: 192 $(BUILD) -laudit 193 194$(OUTPUT)test-libslang.bin: 195 $(BUILD) -lslang 196 197$(OUTPUT)test-libslang-include-subdir.bin: 198 $(BUILD) -lslang 199 200$(OUTPUT)test-libtraceevent.bin: 201 $(BUILD) -ltraceevent 202 203$(OUTPUT)test-libtracefs.bin: 204 $(BUILD) -ltracefs 205 206$(OUTPUT)test-libcrypto.bin: 207 $(BUILD) -lcrypto 208 209$(OUTPUT)test-gtk2.bin: 210 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations 211 212$(OUTPUT)test-gtk2-infobar.bin: 213 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 214 215grep-libs = $(filter -l%,$(1)) 216strip-libs = $(filter-out -l%,$(1)) 217 218PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 219PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 220PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 221PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null) 222FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 223 224ifeq ($(CC_NO_CLANG), 0) 225 PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS)) 226 PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS)) 227 PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS)) 228 FLAGS_PERL_EMBED += -Wno-compound-token-split-by-macro 229endif 230 231$(OUTPUT)test-libperl.bin: 232 $(BUILD) $(FLAGS_PERL_EMBED) 233 234$(OUTPUT)test-libpython.bin: 235 $(BUILD) $(FLAGS_PYTHON_EMBED) 236 237$(OUTPUT)test-libbfd.bin: 238 $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl 239 240$(OUTPUT)test-libbfd-buildid.bin: 241 $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl 242 243$(OUTPUT)test-disassembler-four-args.bin: 244 $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes 245 246$(OUTPUT)test-reallocarray.bin: 247 $(BUILD) 248 249$(OUTPUT)test-libbfd-liberty.bin: 250 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty 251 252$(OUTPUT)test-libbfd-liberty-z.bin: 253 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz 254 255$(OUTPUT)test-cplus-demangle.bin: 256 $(BUILD) -liberty 257 258$(OUTPUT)test-backtrace.bin: 259 $(BUILD) 260 261$(OUTPUT)test-timerfd.bin: 262 $(BUILD) 263 264$(OUTPUT)test-libdw-dwarf-unwind.bin: 265 $(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind) 266 267$(OUTPUT)test-libbabeltrace.bin: 268 $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace) 269 270$(OUTPUT)test-compile-32.bin: 271 $(CC) -m32 -o $@ test-compile.c 272 273$(OUTPUT)test-compile-x32.bin: 274 $(CC) -mx32 -o $@ test-compile.c 275 276$(OUTPUT)test-zlib.bin: 277 $(BUILD) -lz 278 279$(OUTPUT)test-lzma.bin: 280 $(BUILD) -llzma 281 282$(OUTPUT)test-get_cpuid.bin: 283 $(BUILD) 284 285$(OUTPUT)test-bpf.bin: 286 $(BUILD) 287 288$(OUTPUT)test-libbpf.bin: 289 $(BUILD) -lbpf 290 291$(OUTPUT)test-libbpf-btf__load_from_kernel_by_id.bin: 292 $(BUILD) -lbpf 293 294$(OUTPUT)test-sdt.bin: 295 $(BUILD) 296 297$(OUTPUT)test-cxx.bin: 298 $(BUILDXX) -std=gnu++11 299 300$(OUTPUT)test-gettid.bin: 301 $(BUILD) 302 303$(OUTPUT)test-jvmti.bin: 304 $(BUILD) 305 306$(OUTPUT)test-jvmti-cmlr.bin: 307 $(BUILD) 308 309$(OUTPUT)test-llvm.bin: 310 $(BUILDXX) -std=gnu++14 \ 311 -I$(shell $(LLVM_CONFIG) --includedir) \ 312 -L$(shell $(LLVM_CONFIG) --libdir) \ 313 $(shell $(LLVM_CONFIG) --libs Core BPF) \ 314 $(shell $(LLVM_CONFIG) --system-libs) \ 315 > $(@:.bin=.make.output) 2>&1 316 317$(OUTPUT)test-llvm-version.bin: 318 $(BUILDXX) -std=gnu++14 \ 319 -I$(shell $(LLVM_CONFIG) --includedir) \ 320 > $(@:.bin=.make.output) 2>&1 321 322$(OUTPUT)test-clang.bin: 323 $(BUILDXX) -std=gnu++14 \ 324 -I$(shell $(LLVM_CONFIG) --includedir) \ 325 -L$(shell $(LLVM_CONFIG) --libdir) \ 326 -Wl,--start-group -lclangBasic -lclangDriver \ 327 -lclangFrontend -lclangEdit -lclangLex \ 328 -lclangAST -Wl,--end-group \ 329 $(shell $(LLVM_CONFIG) --libs Core option) \ 330 $(shell $(LLVM_CONFIG) --system-libs) \ 331 > $(@:.bin=.make.output) 2>&1 332 333-include $(OUTPUT)*.d 334 335$(OUTPUT)test-libaio.bin: 336 $(BUILD) -lrt 337 338$(OUTPUT)test-libzstd.bin: 339 $(BUILD) -lzstd 340 341$(OUTPUT)test-clang-bpf-co-re.bin: 342 $(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ 343 grep BTF_KIND_VAR 344 345$(OUTPUT)test-file-handle.bin: 346 $(BUILD) 347 348$(OUTPUT)test-libpfm4.bin: 349 $(BUILD) -lpfm 350 351############################### 352 353clean: 354 rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output) 355