xref: /linux/tools/bpf/runqslower/Makefile (revision d4b996f9ef1fe83d9ce9ad5c1ca0bd8231638ce5)
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 := $(if $(O),$(O)/vmlinux)		\
20	$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
21	../../../vmlinux /sys/kernel/btf/vmlinux	\
22	/boot/vmlinux-$(KERNEL_REL)
23VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword			       \
24					  $(wildcard $(VMLINUX_BTF_PATHS))))
25
26ifeq ($(V),1)
27Q =
28else
29Q = @
30MAKEFLAGS += --no-print-directory
31submake_extras := feature_display=0
32endif
33
34.DELETE_ON_ERROR:
35
36.PHONY: all clean runqslower
37all: runqslower
38
39runqslower: $(OUTPUT)/runqslower
40
41clean:
42	$(call QUIET_CLEAN, runqslower)
43	$(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT)
44	$(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d
45	$(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
46	$(Q)$(RM) $(OUTPUT)runqslower
47	$(Q)$(RM) -r .output
48
49$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
50	$(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
51
52$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h	      \
53			$(OUTPUT)/runqslower.bpf.o
54
55$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h
56
57$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
58	$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
59
60$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
61	$(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES)		      \
62		 -c $(filter %.c,$^) -o $@ &&				      \
63	$(LLVM_STRIP) -g $@
64
65$(OUTPUT)/%.o: %.c | $(OUTPUT)
66	$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
67
68$(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
69	$(QUIET_MKDIR)mkdir -p $@
70
71$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
72ifeq ($(VMLINUX_H),)
73	$(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
74		echo "Couldn't find kernel BTF; set VMLINUX_BTF to"	       \
75			"specify its location." >&2;			       \
76		exit 1;\
77	fi
78	$(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
79else
80	$(Q)cp "$(VMLINUX_H)" $@
81endif
82
83$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
84	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) $@
85
86$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
87	$(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT)   \
88		    CC=$(HOSTCC) LD=$(HOSTLD)
89