2020-01-13 15:31:42 +08:00
|
|
|
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
|
|
|
OUTPUT := .output
|
2020-01-25 06:41:42 +08:00
|
|
|
CLANG ?= clang
|
|
|
|
LLC ?= llc
|
|
|
|
LLVM_STRIP ?= llvm-strip
|
2020-01-13 15:31:42 +08:00
|
|
|
DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
|
|
|
|
BPFTOOL ?= $(DEFAULT_BPFTOOL)
|
|
|
|
LIBBPF_SRC := $(abspath ../../lib/bpf)
|
2020-01-20 21:06:51 +08:00
|
|
|
BPFOBJ := $(OUTPUT)/libbpf.a
|
|
|
|
BPF_INCLUDE := $(OUTPUT)
|
2020-04-22 09:24:07 +08:00
|
|
|
INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib)
|
2020-01-13 15:31:42 +08:00
|
|
|
CFLAGS := -g -Wall
|
|
|
|
|
|
|
|
# Try to detect best kernel BTF source
|
|
|
|
KERNEL_REL := $(shell uname -r)
|
2020-01-20 21:06:42 +08:00
|
|
|
VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL)
|
|
|
|
VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \
|
|
|
|
$(wildcard $(VMLINUX_BTF_PATHS))))
|
2020-01-13 15:31:42 +08:00
|
|
|
|
|
|
|
abs_out := $(abspath $(OUTPUT))
|
|
|
|
ifeq ($(V),1)
|
|
|
|
Q =
|
|
|
|
msg =
|
|
|
|
else
|
|
|
|
Q = @
|
|
|
|
msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
|
|
|
|
MAKEFLAGS += --no-print-directory
|
|
|
|
submake_extras := feature_display=0
|
|
|
|
endif
|
|
|
|
|
|
|
|
.DELETE_ON_ERROR:
|
|
|
|
|
|
|
|
.PHONY: all clean runqslower
|
|
|
|
all: runqslower
|
|
|
|
|
|
|
|
runqslower: $(OUTPUT)/runqslower
|
|
|
|
|
|
|
|
clean:
|
|
|
|
$(call msg,CLEAN)
|
|
|
|
$(Q)rm -rf $(OUTPUT) runqslower
|
|
|
|
|
2020-01-20 21:06:51 +08:00
|
|
|
$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
|
2020-01-13 15:31:42 +08:00
|
|
|
$(call msg,BINARY,$@)
|
2020-01-31 07:13:10 +08:00
|
|
|
$(Q)$(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)
|
|
|
|
$(call msg,GEN-SKEL,$@)
|
|
|
|
$(Q)$(BPFTOOL) gen skeleton $< > $@
|
|
|
|
|
2020-01-20 21:06:51 +08:00
|
|
|
$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
|
2020-01-13 15:31:42 +08:00
|
|
|
$(call msg,BPF,$@)
|
2020-01-20 21:06:44 +08:00
|
|
|
$(Q)$(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)
|
|
|
|
$(call msg,CC,$@)
|
2020-01-20 21:06:44 +08:00
|
|
|
$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
|
2020-01-13 15:31:42 +08:00
|
|
|
|
|
|
|
$(OUTPUT):
|
|
|
|
$(call msg,MKDIR,$@)
|
|
|
|
$(Q)mkdir -p $(OUTPUT)
|
|
|
|
|
2020-01-20 21:06:42 +08:00
|
|
|
$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
|
2020-01-13 15:31:42 +08:00
|
|
|
$(call msg,GEN,$@)
|
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
|
|
|
|
$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
|
2020-01-13 15:31:42 +08:00
|
|
|
|
2020-02-05 05:50:37 +08:00
|
|
|
$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
|
2020-01-13 15:31:42 +08:00
|
|
|
$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) \
|
2020-01-20 21:06:51 +08:00
|
|
|
OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
|
2020-01-13 15:31:42 +08:00
|
|
|
|
|
|
|
$(DEFAULT_BPFTOOL):
|
|
|
|
$(Q)$(MAKE) $(submake_extras) -C ../bpftool \
|
|
|
|
prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install
|