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-disassembler-four-args.bin \ 19 test-reallocarray.bin \ 20 test-libbfd-liberty.bin \ 21 test-libbfd-liberty-z.bin \ 22 test-cplus-demangle.bin \ 23 test-libcap.bin \ 24 test-libelf.bin \ 25 test-libelf-getphdrnum.bin \ 26 test-libelf-gelf_getnote.bin \ 27 test-libelf-getshdrstrndx.bin \ 28 test-libelf-mmap.bin \ 29 test-libnuma.bin \ 30 test-numa_num_possible_cpus.bin \ 31 test-libperl.bin \ 32 test-libpython.bin \ 33 test-libpython-version.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-global-var.bin \ 72 test-file-handle.bin \ 73 test-libpfm4.bin 74 75FILES := $(addprefix $(OUTPUT),$(FILES)) 76 77CC ?= $(CROSS_COMPILE)gcc 78CXX ?= $(CROSS_COMPILE)g++ 79PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config 80LLVM_CONFIG ?= llvm-config 81CLANG ?= clang 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 -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 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-mmap.bin: 151 $(BUILD) -lelf 152 153$(OUTPUT)test-libelf-getphdrnum.bin: 154 $(BUILD) -lelf 155 156$(OUTPUT)test-libelf-gelf_getnote.bin: 157 $(BUILD) -lelf 158 159$(OUTPUT)test-libelf-getshdrstrndx.bin: 160 $(BUILD) -lelf 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-libcrypto.bin: 201 $(BUILD) -lcrypto 202 203$(OUTPUT)test-gtk2.bin: 204 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno-deprecated-declarations 205 206$(OUTPUT)test-gtk2-infobar.bin: 207 $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) 208 209grep-libs = $(filter -l%,$(1)) 210strip-libs = $(filter-out -l%,$(1)) 211 212PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 213PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 214PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 215PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null` 216FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 217 218$(OUTPUT)test-libperl.bin: 219 $(BUILD) $(FLAGS_PERL_EMBED) 220 221$(OUTPUT)test-libpython.bin: 222 $(BUILD) $(FLAGS_PYTHON_EMBED) 223 224$(OUTPUT)test-libpython-version.bin: 225 $(BUILD) 226 227$(OUTPUT)test-libbfd.bin: 228 $(BUILD) -DPACKAGE='"perf"' -lbfd -ldl 229 230$(OUTPUT)test-disassembler-four-args.bin: 231 $(BUILD) -DPACKAGE='"perf"' -lbfd -lopcodes 232 233$(OUTPUT)test-reallocarray.bin: 234 $(BUILD) 235 236$(OUTPUT)test-libbfd-liberty.bin: 237 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty 238 239$(OUTPUT)test-libbfd-liberty-z.bin: 240 $(CC) $(CFLAGS) -Wall -Werror -o $@ test-libbfd.c -DPACKAGE='"perf"' $(LDFLAGS) -lbfd -ldl -liberty -lz 241 242$(OUTPUT)test-cplus-demangle.bin: 243 $(BUILD) -liberty 244 245$(OUTPUT)test-backtrace.bin: 246 $(BUILD) 247 248$(OUTPUT)test-timerfd.bin: 249 $(BUILD) 250 251$(OUTPUT)test-libdw-dwarf-unwind.bin: 252 $(BUILD) # -ldw provided by $(FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind) 253 254$(OUTPUT)test-libbabeltrace.bin: 255 $(BUILD) # -lbabeltrace provided by $(FEATURE_CHECK_LDFLAGS-libbabeltrace) 256 257$(OUTPUT)test-sync-compare-and-swap.bin: 258 $(BUILD) 259 260$(OUTPUT)test-compile-32.bin: 261 $(CC) -m32 -o $@ test-compile.c 262 263$(OUTPUT)test-compile-x32.bin: 264 $(CC) -mx32 -o $@ test-compile.c 265 266$(OUTPUT)test-zlib.bin: 267 $(BUILD) -lz 268 269$(OUTPUT)test-lzma.bin: 270 $(BUILD) -llzma 271 272$(OUTPUT)test-get_cpuid.bin: 273 $(BUILD) 274 275$(OUTPUT)test-bpf.bin: 276 $(BUILD) 277 278$(OUTPUT)test-libbpf.bin: 279 $(BUILD) -lbpf 280 281$(OUTPUT)test-sdt.bin: 282 $(BUILD) 283 284$(OUTPUT)test-cxx.bin: 285 $(BUILDXX) -std=gnu++11 286 287$(OUTPUT)test-gettid.bin: 288 $(BUILD) 289 290$(OUTPUT)test-jvmti.bin: 291 $(BUILD) 292 293$(OUTPUT)test-jvmti-cmlr.bin: 294 $(BUILD) 295 296$(OUTPUT)test-llvm.bin: 297 $(BUILDXX) -std=gnu++11 \ 298 -I$(shell $(LLVM_CONFIG) --includedir) \ 299 -L$(shell $(LLVM_CONFIG) --libdir) \ 300 $(shell $(LLVM_CONFIG) --libs Core BPF) \ 301 $(shell $(LLVM_CONFIG) --system-libs) \ 302 > $(@:.bin=.make.output) 2>&1 303 304$(OUTPUT)test-llvm-version.bin: 305 $(BUILDXX) -std=gnu++11 \ 306 -I$(shell $(LLVM_CONFIG) --includedir) \ 307 > $(@:.bin=.make.output) 2>&1 308 309$(OUTPUT)test-clang.bin: 310 $(BUILDXX) -std=gnu++11 \ 311 -I$(shell $(LLVM_CONFIG) --includedir) \ 312 -L$(shell $(LLVM_CONFIG) --libdir) \ 313 -Wl,--start-group -lclangBasic -lclangDriver \ 314 -lclangFrontend -lclangEdit -lclangLex \ 315 -lclangAST -Wl,--end-group \ 316 $(shell $(LLVM_CONFIG) --libs Core option) \ 317 $(shell $(LLVM_CONFIG) --system-libs) \ 318 > $(@:.bin=.make.output) 2>&1 319 320-include $(OUTPUT)*.d 321 322$(OUTPUT)test-libaio.bin: 323 $(BUILD) -lrt 324 325$(OUTPUT)test-libzstd.bin: 326 $(BUILD) -lzstd 327 328$(OUTPUT)test-clang-bpf-global-var.bin: 329 $(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) | \ 330 grep BTF_KIND_VAR 331 332$(OUTPUT)test-file-handle.bin: 333 $(BUILD) 334 335$(OUTPUT)test-libpfm4.bin: 336 $(BUILD) -lpfm 337 338############################### 339 340clean: 341 rm -f $(FILES) $(OUTPUT)*.d $(FILES:.bin=.make.output) 342