Merge tag 'kbuild-fixes-v5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/masahi...
[linux/fpc-iii.git] / tools / bpf / runqslower / Makefile
blobfb1337d6986801f3f591bf8aa28d52de1357987f
1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 OUTPUT := .output
3 CLANG ?= clang
4 LLC ?= llc
5 LLVM_STRIP ?= llvm-strip
6 DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
7 BPFTOOL ?= $(DEFAULT_BPFTOOL)
8 LIBBPF_SRC := $(abspath ../../lib/bpf)
9 BPFOBJ := $(OUTPUT)/libbpf.a
10 BPF_INCLUDE := $(OUTPUT)
11 INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) \
12 -I$(abspath ../../include/uapi)
13 CFLAGS := -g -Wall
15 # Try to detect best kernel BTF source
16 KERNEL_REL := $(shell uname -r)
17 VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL)
18 VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \
19 $(wildcard $(VMLINUX_BTF_PATHS))))
21 abs_out := $(abspath $(OUTPUT))
22 ifeq ($(V),1)
23 Q =
24 msg =
25 else
26 Q = @
27 msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
28 MAKEFLAGS += --no-print-directory
29 submake_extras := feature_display=0
30 endif
32 .DELETE_ON_ERROR:
34 .PHONY: all clean runqslower
35 all: runqslower
37 runqslower: $(OUTPUT)/runqslower
39 clean:
40 $(call msg,CLEAN)
41 $(Q)rm -rf $(OUTPUT) runqslower
43 $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
44 $(call msg,BINARY,$@)
45 $(Q)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
47 $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \
48 $(OUTPUT)/runqslower.bpf.o
50 $(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h
52 $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
53 $(call msg,GEN-SKEL,$@)
54 $(Q)$(BPFTOOL) gen skeleton $< > $@
56 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
57 $(call msg,BPF,$@)
58 $(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES) \
59 -c $(filter %.c,$^) -o $@ && \
60 $(LLVM_STRIP) -g $@
62 $(OUTPUT)/%.o: %.c | $(OUTPUT)
63 $(call msg,CC,$@)
64 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
66 $(OUTPUT):
67 $(call msg,MKDIR,$@)
68 $(Q)mkdir -p $(OUTPUT)
70 $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
71 $(call msg,GEN,$@)
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 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
79 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
80 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) \
81 OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
83 $(DEFAULT_BPFTOOL):
84 $(Q)$(MAKE) $(submake_extras) -C ../bpftool \
85 prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install