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