Merge tag 'block-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / bpf / runqslower / Makefile
blob4d5ca54fcd4c83e8d876508c5fe178f9e7cedac9
1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 include ../../scripts/Makefile.include
4 OUTPUT ?= $(abspath .output)/
6 CLANG ?= clang
7 LLC ?= llc
8 LLVM_STRIP ?= llvm-strip
9 BPFTOOL_OUTPUT := $(OUTPUT)bpftool/
10 DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bpftool
11 BPFTOOL ?= $(DEFAULT_BPFTOOL)
12 LIBBPF_SRC := $(abspath ../../lib/bpf)
13 BPFOBJ_OUTPUT := $(OUTPUT)libbpf/
14 BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a
15 BPF_INCLUDE := $(BPFOBJ_OUTPUT)
16 INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) \
17 -I$(abspath ../../include/uapi)
18 CFLAGS := -g -Wall
20 # Try to detect best kernel BTF source
21 KERNEL_REL := $(shell uname -r)
22 VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL)
23 VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \
24 $(wildcard $(VMLINUX_BTF_PATHS))))
26 ifeq ($(V),1)
27 Q =
28 else
29 Q = @
30 MAKEFLAGS += --no-print-directory
31 submake_extras := feature_display=0
32 endif
34 .DELETE_ON_ERROR:
36 .PHONY: all clean runqslower
37 all: runqslower
39 runqslower: $(OUTPUT)/runqslower
41 clean:
42 $(call QUIET_CLEAN, runqslower)
43 $(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT)
44 $(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d
45 $(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
46 $(Q)$(RM) $(OUTPUT)runqslower
47 $(Q)$(RM) -r .output
49 $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
50 $(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
52 $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \
53 $(OUTPUT)/runqslower.bpf.o
55 $(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h
57 $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
58 $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
60 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
61 $(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES) \
62 -c $(filter %.c,$^) -o $@ && \
63 $(LLVM_STRIP) -g $@
65 $(OUTPUT)/%.o: %.c | $(OUTPUT)
66 $(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
68 $(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
69 $(QUIET_MKDIR)mkdir -p $@
71 $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
72 $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
73 echo "Couldn't find kernel BTF; set VMLINUX_BTF to" \
74 "specify its location." >&2; \
75 exit 1;\
77 $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
79 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
80 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) $@
82 $(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
83 $(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) \
84 CC=$(HOSTCC) LD=$(HOSTLD)