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