1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2- 1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 include ../../scripts/Makefile.include 2 include ../../scripts/Makefile.include 3 3 4 OUTPUT ?= $(abspath .output)/ 4 OUTPUT ?= $(abspath .output)/ 5 5 6 BPFTOOL_OUTPUT := $(OUTPUT)bpftool/ 6 BPFTOOL_OUTPUT := $(OUTPUT)bpftool/ 7 DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bootstrap/ 7 DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bootstrap/bpftool 8 BPFTOOL ?= $(DEFAULT_BPFTOOL) 8 BPFTOOL ?= $(DEFAULT_BPFTOOL) 9 LIBBPF_SRC := $(abspath ../../lib/bpf) 9 LIBBPF_SRC := $(abspath ../../lib/bpf) 10 BPFOBJ_OUTPUT := $(OUTPUT)libbpf/ 10 BPFOBJ_OUTPUT := $(OUTPUT)libbpf/ 11 BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a 11 BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a 12 BPF_DESTDIR := $(BPFOBJ_OUTPUT) 12 BPF_DESTDIR := $(BPFOBJ_OUTPUT) 13 BPF_INCLUDE := $(BPF_DESTDIR)/include 13 BPF_INCLUDE := $(BPF_DESTDIR)/include 14 INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(a 14 INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../include/uapi) 15 CFLAGS := -g -Wall $(CLANG_CROSS_FLAGS) 15 CFLAGS := -g -Wall $(CLANG_CROSS_FLAGS) 16 CFLAGS += $(EXTRA_CFLAGS) 16 CFLAGS += $(EXTRA_CFLAGS) 17 LDFLAGS += $(EXTRA_LDFLAGS) 17 LDFLAGS += $(EXTRA_LDFLAGS) 18 LDLIBS += -lelf -lz << 19 18 20 # Try to detect best kernel BTF source 19 # Try to detect best kernel BTF source 21 KERNEL_REL := $(shell uname -r) 20 KERNEL_REL := $(shell uname -r) 22 VMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux) 21 VMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux) \ 23 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT) 22 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ 24 ../../../vmlinux /sys/kernel/btf/vmlin 23 ../../../vmlinux /sys/kernel/btf/vmlinux \ 25 /boot/vmlinux-$(KERNEL_REL) 24 /boot/vmlinux-$(KERNEL_REL) 26 VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firs 25 VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ 27 $(wi 26 $(wildcard $(VMLINUX_BTF_PATHS)))) 28 27 29 ifeq ($(V),1) 28 ifeq ($(V),1) 30 Q = 29 Q = 31 else 30 else 32 Q = @ 31 Q = @ 33 MAKEFLAGS += --no-print-directory 32 MAKEFLAGS += --no-print-directory 34 submake_extras := feature_display=0 33 submake_extras := feature_display=0 35 endif 34 endif 36 35 37 .DELETE_ON_ERROR: 36 .DELETE_ON_ERROR: 38 37 39 .PHONY: all clean runqslower libbpf_hdrs 38 .PHONY: all clean runqslower libbpf_hdrs 40 all: runqslower 39 all: runqslower 41 40 42 runqslower: $(OUTPUT)/runqslower 41 runqslower: $(OUTPUT)/runqslower 43 42 44 clean: 43 clean: 45 $(call QUIET_CLEAN, runqslower) 44 $(call QUIET_CLEAN, runqslower) 46 $(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOO 45 $(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT) 47 $(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d 46 $(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d 48 $(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)v 47 $(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h 49 $(Q)$(RM) $(OUTPUT)runqslower 48 $(Q)$(RM) $(OUTPUT)runqslower 50 $(Q)$(RM) -r .output 49 $(Q)$(RM) -r .output 51 50 52 libbpf_hdrs: $(BPFOBJ) 51 libbpf_hdrs: $(BPFOBJ) 53 52 54 $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $ 53 $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ) 55 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS !! 54 $(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@ 56 55 57 $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT) 56 $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \ 58 $(OUTPUT)/runqslower.b 57 $(OUTPUT)/runqslower.bpf.o | libbpf_hdrs 59 58 60 $(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux. 59 $(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h | libbpf_hdrs 61 60 62 $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFT 61 $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL) 63 $(QUIET_GEN)$(BPFTOOL) gen skeleton $< 62 $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@ 64 63 65 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPU 64 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT) 66 $(QUIET_GEN)$(CLANG) -g -O2 --target=b 65 $(QUIET_GEN)$(CLANG) -g -O2 --target=bpf $(INCLUDES) \ 67 -c $(filter %.c,$^) -o $@ && 66 -c $(filter %.c,$^) -o $@ && \ 68 $(LLVM_STRIP) -g $@ 67 $(LLVM_STRIP) -g $@ 69 68 70 $(OUTPUT)/%.o: %.c | $(OUTPUT) 69 $(OUTPUT)/%.o: %.c | $(OUTPUT) 71 $(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) 70 $(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@ 72 71 73 $(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT): 72 $(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT): 74 $(QUIET_MKDIR)mkdir -p $@ 73 $(QUIET_MKDIR)mkdir -p $@ 75 74 76 $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(O 75 $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL) 77 ifeq ($(VMLINUX_H),) 76 ifeq ($(VMLINUX_H),) 78 $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] 77 $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \ 79 echo "Couldn't find kernel BTF 78 echo "Couldn't find kernel BTF; set VMLINUX_BTF to" \ 80 "specify its location. 79 "specify its location." >&2; \ 81 exit 1;\ 80 exit 1;\ 82 fi 81 fi 83 $(QUIET_GEN)$(BPFTOOL) btf dump file $ 82 $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@ 84 else 83 else 85 $(Q)cp "$(VMLINUX_H)" $@ 84 $(Q)cp "$(VMLINUX_H)" $@ 86 endif 85 endif 87 86 88 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(L 87 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT) 89 $(Q)$(MAKE) $(submake_extras) -C $(LIB 88 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) \ 90 DESTDIR=$(BPFOBJ_OUTPUT) p 89 DESTDIR=$(BPFOBJ_OUTPUT) prefix= $(abspath $@) install_headers 91 90 92 $(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT) 91 $(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT) 93 $(Q)$(MAKE) $(submake_extras) -C ../bp 92 $(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) bootstrap
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.