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