1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
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
)
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
))
27 msg
= @printf
' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
28 MAKEFLAGS
+= --no-print-directory
29 submake_extras
:= feature_display
=0
34 .PHONY
: all clean runqslower
37 runqslower
: $(OUTPUT
)/runqslower
41 $(Q
)rm -rf
$(OUTPUT
) runqslower
43 $(OUTPUT
)/runqslower
: $(OUTPUT
)/runqslower.o
$(BPFOBJ
)
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
)
58 $(Q
)$(CLANG
) -g
-O2
-target bpf
$(INCLUDES
) \
59 -c
$(filter %.c
,$^
) -o
$@
&& \
62 $(OUTPUT
)/%.o
: %.c |
$(OUTPUT
)
64 $(Q
)$(CC
) $(CFLAGS
) $(INCLUDES
) -c
$(filter %.c
,$^
) -o
$@
68 $(Q
)mkdir
-p
$(OUTPUT
)
70 $(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; \
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
$@
)
84 $(Q
)$(MAKE
) $(submake_extras
) -C ..
/bpftool \
85 prefix= OUTPUT
=$(abs_out
)/ DESTDIR
=$(abs_out
) install