GNU Linux-libre 6.8.9-gnu
[releases.git] / tools / bpf / runqslower / Makefile
1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 include ../../scripts/Makefile.include
3
4 OUTPUT ?= $(abspath .output)/
5
6 BPFTOOL_OUTPUT := $(OUTPUT)bpftool/
7 DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bootstrap/bpftool
8 BPFTOOL ?= $(DEFAULT_BPFTOOL)
9 LIBBPF_SRC := $(abspath ../../lib/bpf)
10 BPFOBJ_OUTPUT := $(OUTPUT)libbpf/
11 BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a
12 BPF_DESTDIR := $(BPFOBJ_OUTPUT)
13 BPF_INCLUDE := $(BPF_DESTDIR)/include
14 INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../include/uapi)
15 CFLAGS := -g -Wall $(CLANG_CROSS_FLAGS)
16 CFLAGS += $(EXTRA_CFLAGS)
17 LDFLAGS += $(EXTRA_LDFLAGS)
18
19 # Try to detect best kernel BTF source
20 KERNEL_REL := $(shell uname -r)
21 VMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux)            \
22         $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
23         ../../../vmlinux /sys/kernel/btf/vmlinux        \
24         /boot/vmlinux-$(KERNEL_REL)
25 VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword                            \
26                                           $(wildcard $(VMLINUX_BTF_PATHS))))
27
28 ifeq ($(V),1)
29 Q =
30 else
31 Q = @
32 MAKEFLAGS += --no-print-directory
33 submake_extras := feature_display=0
34 endif
35
36 .DELETE_ON_ERROR:
37
38 .PHONY: all clean runqslower libbpf_hdrs
39 all: runqslower
40
41 runqslower: $(OUTPUT)/runqslower
42
43 clean:
44         $(call QUIET_CLEAN, runqslower)
45         $(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT)
46         $(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d
47         $(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
48         $(Q)$(RM) $(OUTPUT)runqslower
49         $(Q)$(RM) -r .output
50
51 libbpf_hdrs: $(BPFOBJ)
52
53 $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
54         $(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
55
56 $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h              \
57                         $(OUTPUT)/runqslower.bpf.o | libbpf_hdrs
58
59 $(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h | libbpf_hdrs
60
61 $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
62         $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
63
64 $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
65         $(QUIET_GEN)$(CLANG) -g -O2 --target=bpf $(INCLUDES)                  \
66                  -c $(filter %.c,$^) -o $@ &&                                 \
67         $(LLVM_STRIP) -g $@
68
69 $(OUTPUT)/%.o: %.c | $(OUTPUT)
70         $(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
71
72 $(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
73         $(QUIET_MKDIR)mkdir -p $@
74
75 $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
76 ifeq ($(VMLINUX_H),)
77         $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
78                 echo "Couldn't find kernel BTF; set VMLINUX_BTF to"            \
79                         "specify its location." >&2;                           \
80                 exit 1;\
81         fi
82         $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
83 else
84         $(Q)cp "$(VMLINUX_H)" $@
85 endif
86
87 $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
88         $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) \
89                     DESTDIR=$(BPFOBJ_OUTPUT) prefix= $(abspath $@) install_headers
90
91 $(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
92         $(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) bootstrap