• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2OUTPUT := .output
3CLANG ?= clang
4LLC ?= llc
5LLVM_STRIP ?= llvm-strip
6DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool
7BPFTOOL ?= $(DEFAULT_BPFTOOL)
8LIBBPF_SRC := $(abspath ../../lib/bpf)
9BPFOBJ := $(OUTPUT)/libbpf.a
10BPF_INCLUDE := $(OUTPUT)
11INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib)        \
12       -I$(abspath ../../include/uapi)
13CFLAGS := -g -Wall
14
15# Try to detect best kernel BTF source
16KERNEL_REL := $(shell uname -r)
17VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL)
18VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword			       \
19					  $(wildcard $(VMLINUX_BTF_PATHS))))
20
21abs_out := $(abspath $(OUTPUT))
22ifeq ($(V),1)
23Q =
24msg =
25else
26Q = @
27msg = @printf '  %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
28MAKEFLAGS += --no-print-directory
29submake_extras := feature_display=0
30endif
31
32.DELETE_ON_ERROR:
33
34.PHONY: all clean runqslower
35all: runqslower
36
37runqslower: $(OUTPUT)/runqslower
38
39clean:
40	$(call msg,CLEAN)
41	$(Q)rm -rf $(OUTPUT) runqslower
42
43$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
44	$(call msg,BINARY,$@)
45	$(Q)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
46
47$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h	      \
48			$(OUTPUT)/runqslower.bpf.o
49
50$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h
51
52$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
53	$(call msg,GEN-SKEL,$@)
54	$(Q)$(BPFTOOL) gen skeleton $< > $@
55
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 $@
61
62$(OUTPUT)/%.o: %.c | $(OUTPUT)
63	$(call msg,CC,$@)
64	$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
65
66$(OUTPUT):
67	$(call msg,MKDIR,$@)
68	$(Q)mkdir -p $(OUTPUT)
69
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;\
76	fi
77	$(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
78
79$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)
80	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC)			       \
81		    OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
82
83$(DEFAULT_BPFTOOL):
84	$(Q)$(MAKE) $(submake_extras) -C ../bpftool			      \
85		    prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install
86