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