18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 28c2ecf20Sopenharmony_ciOUTPUT := .output 38c2ecf20Sopenharmony_ciCLANG ?= clang 48c2ecf20Sopenharmony_ciLLC ?= llc 58c2ecf20Sopenharmony_ciLLVM_STRIP ?= llvm-strip 68c2ecf20Sopenharmony_ciDEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool 78c2ecf20Sopenharmony_ciBPFTOOL ?= $(DEFAULT_BPFTOOL) 88c2ecf20Sopenharmony_ciLIBBPF_SRC := $(abspath ../../lib/bpf) 98c2ecf20Sopenharmony_ciBPFOBJ := $(OUTPUT)/libbpf.a 108c2ecf20Sopenharmony_ciBPF_INCLUDE := $(OUTPUT) 118c2ecf20Sopenharmony_ciINCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) \ 128c2ecf20Sopenharmony_ci -I$(abspath ../../include/uapi) 138c2ecf20Sopenharmony_ciCFLAGS := -g -Wall 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci# Try to detect best kernel BTF source 168c2ecf20Sopenharmony_ciKERNEL_REL := $(shell uname -r) 178c2ecf20Sopenharmony_ciVMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL) 188c2ecf20Sopenharmony_ciVMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ 198c2ecf20Sopenharmony_ci $(wildcard $(VMLINUX_BTF_PATHS)))) 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciabs_out := $(abspath $(OUTPUT)) 228c2ecf20Sopenharmony_ciifeq ($(V),1) 238c2ecf20Sopenharmony_ciQ = 248c2ecf20Sopenharmony_cimsg = 258c2ecf20Sopenharmony_cielse 268c2ecf20Sopenharmony_ciQ = @ 278c2ecf20Sopenharmony_cimsg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))"; 288c2ecf20Sopenharmony_ciMAKEFLAGS += --no-print-directory 298c2ecf20Sopenharmony_cisubmake_extras := feature_display=0 308c2ecf20Sopenharmony_ciendif 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci.DELETE_ON_ERROR: 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci.PHONY: all clean runqslower 358c2ecf20Sopenharmony_ciall: runqslower 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cirunqslower: $(OUTPUT)/runqslower 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ciclean: 408c2ecf20Sopenharmony_ci $(call msg,CLEAN) 418c2ecf20Sopenharmony_ci $(Q)rm -rf $(OUTPUT) runqslower 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ) 448c2ecf20Sopenharmony_ci $(call msg,BINARY,$@) 458c2ecf20Sopenharmony_ci $(Q)$(CC) $(CFLAGS) $^ -lelf -lz -o $@ 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \ 488c2ecf20Sopenharmony_ci $(OUTPUT)/runqslower.bpf.o 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL) 538c2ecf20Sopenharmony_ci $(call msg,GEN-SKEL,$@) 548c2ecf20Sopenharmony_ci $(Q)$(BPFTOOL) gen skeleton $< > $@ 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT) 578c2ecf20Sopenharmony_ci $(call msg,BPF,$@) 588c2ecf20Sopenharmony_ci $(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES) \ 598c2ecf20Sopenharmony_ci -c $(filter %.c,$^) -o $@ && \ 608c2ecf20Sopenharmony_ci $(LLVM_STRIP) -g $@ 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci$(OUTPUT)/%.o: %.c | $(OUTPUT) 638c2ecf20Sopenharmony_ci $(call msg,CC,$@) 648c2ecf20Sopenharmony_ci $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@ 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci$(OUTPUT): 678c2ecf20Sopenharmony_ci $(call msg,MKDIR,$@) 688c2ecf20Sopenharmony_ci $(Q)mkdir -p $(OUTPUT) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL) 718c2ecf20Sopenharmony_ci $(call msg,GEN,$@) 728c2ecf20Sopenharmony_ci $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \ 738c2ecf20Sopenharmony_ci echo "Couldn't find kernel BTF; set VMLINUX_BTF to" \ 748c2ecf20Sopenharmony_ci "specify its location." >&2; \ 758c2ecf20Sopenharmony_ci exit 1;\ 768c2ecf20Sopenharmony_ci fi 778c2ecf20Sopenharmony_ci $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@ 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT) 808c2ecf20Sopenharmony_ci $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) \ 818c2ecf20Sopenharmony_ci OUTPUT=$(abspath $(dir $@))/ $(abspath $@) 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci$(DEFAULT_BPFTOOL): 848c2ecf20Sopenharmony_ci $(Q)$(MAKE) $(submake_extras) -C ../bpftool \ 858c2ecf20Sopenharmony_ci prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install 86