2020-01-13 15:31:42 +08:00
|
|
|
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
2020-11-11 00:43:08 +08:00
|
|
|
include ../../scripts/Makefile.include
|
|
|
|
|
2020-11-11 00:43:09 +08:00
|
|
|
OUTPUT ?= $(abspath .output)/
|
|
|
|
|
|
|
|
BPFTOOL_OUTPUT := $(OUTPUT)bpftool/
|
|
|
|
DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bpftool
|
2020-01-13 15:31:42 +08:00
|
|
|
BPFTOOL ?= $(DEFAULT_BPFTOOL)
|
|
|
|
LIBBPF_SRC := $(abspath ../../lib/bpf)
|
2020-11-11 00:43:09 +08:00
|
|
|
BPFOBJ_OUTPUT := $(OUTPUT)libbpf/
|
|
|
|
BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a
|
|
|
|
BPF_INCLUDE := $(BPFOBJ_OUTPUT)
|
2020-05-05 01:36:26 +08:00
|
|
|
INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) \
|
|
|
|
-I$(abspath ../../include/uapi)
|
2020-01-13 15:31:42 +08:00
|
|
|
CFLAGS := -g -Wall
|
|
|
|
|
|
|
|
# Try to detect best kernel BTF source
|
|
|
|
KERNEL_REL := $(shell uname -r)
|
2021-02-26 07:43:18 +08:00
|
|
|
VMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux) \
|
|
|
|
$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
|
|
|
|
../../../vmlinux /sys/kernel/btf/vmlinux \
|
|
|
|
/boot/vmlinux-$(KERNEL_REL)
|
2020-01-20 21:06:42 +08:00
|
|
|
VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \
|
|
|
|
$(wildcard $(VMLINUX_BTF_PATHS))))
|
2020-01-13 15:31:42 +08:00
|
|
|
|
|
|
|
ifeq ($(V),1)
|
|
|
|
Q =
|
|
|
|
else
|
|
|
|
Q = @
|
|
|
|
MAKEFLAGS += --no-print-directory
|
|
|
|
submake_extras := feature_display=0
|
|
|
|
endif
|
|
|
|
|
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
|
|
|
|
.PHONY: all clean runqslower
|
|
|
|
all: runqslower
|
|
|
|
|
|
|
|
runqslower: $(OUTPUT)/runqslower
|
|
|
|
|
|
|
|
clean:
|
2020-11-11 00:43:08 +08:00
|
|
|
$(call QUIET_CLEAN, runqslower)
|
2020-11-11 00:43:09 +08:00
|
|
|
$(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT)
|
|
|
|
$(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d
|
|
|
|
$(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
|
|
|
|
$(Q)$(RM) $(OUTPUT)runqslower
|
|
|
|
$(Q)$(RM) -r .output
|
2020-01-13 15:31:42 +08:00
|
|
|
|
2020-01-20 21:06:51 +08:00
|
|
|
$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
|
2020-11-11 00:43:08 +08:00
|
|
|
$(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
|
2020-01-13 15:31:42 +08:00
|
|
|
|
|
|
|
$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \
|
|
|
|
$(OUTPUT)/runqslower.bpf.o
|
|
|
|
|
|
|
|
$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h
|
|
|
|
|
|
|
|
$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
|
2020-11-11 00:43:08 +08:00
|
|
|
$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
|
2020-01-13 15:31:42 +08:00
|
|
|
|
2020-01-20 21:06:51 +08:00
|
|
|
$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
|
2020-11-11 00:43:08 +08:00
|
|
|
$(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES) \
|
2020-01-13 15:31:42 +08:00
|
|
|
-c $(filter %.c,$^) -o $@ && \
|
|
|
|
$(LLVM_STRIP) -g $@
|
|
|
|
|
|
|
|
$(OUTPUT)/%.o: %.c | $(OUTPUT)
|
2020-11-11 00:43:08 +08:00
|
|
|
$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
|
2020-01-13 15:31:42 +08:00
|
|
|
|
2020-11-11 00:43:09 +08:00
|
|
|
$(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
|
|
|
|
$(QUIET_MKDIR)mkdir -p $@
|
2020-01-13 15:31:42 +08:00
|
|
|
|
2020-01-20 21:06:42 +08:00
|
|
|
$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
|
2021-03-03 08:40:10 +08:00
|
|
|
ifeq ($(VMLINUX_H),)
|
2020-01-20 21:06:42 +08:00
|
|
|
$(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
|
|
|
|
echo "Couldn't find kernel BTF; set VMLINUX_BTF to" \
|
|
|
|
"specify its location." >&2; \
|
|
|
|
exit 1;\
|
|
|
|
fi
|
2020-11-11 00:43:08 +08:00
|
|
|
$(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
|
2021-03-03 08:40:10 +08:00
|
|
|
else
|
|
|
|
$(Q)cp "$(VMLINUX_H)" $@
|
|
|
|
endif
|
2020-01-13 15:31:42 +08:00
|
|
|
|
2020-11-11 00:43:09 +08:00
|
|
|
$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
|
|
|
|
$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) $@
|
2020-01-13 15:31:42 +08:00
|
|
|
|
2020-11-11 00:43:09 +08:00
|
|
|
$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
|
2020-11-11 00:43:10 +08:00
|
|
|
$(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) \
|
|
|
|
CC=$(HOSTCC) LD=$(HOSTLD)
|