xref: /openbmc/linux/tools/bpf/runqslower/Makefile (revision 34d6f206a88c2651d216bd3487ac956a40b2ba8e)
19c01546dSAndrii Nakryiko# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
23290996eSJean-Philippe Bruckerinclude ../../scripts/Makefile.include
33290996eSJean-Philippe Brucker
485e59344SJean-Philippe BruckerOUTPUT ?= $(abspath .output)/
585e59344SJean-Philippe Brucker
685e59344SJean-Philippe BruckerBPFTOOL_OUTPUT := $(OUTPUT)bpftool/
73a2a58c4SPu LehuiDEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bootstrap/bpftool
89c01546dSAndrii NakryikoBPFTOOL ?= $(DEFAULT_BPFTOOL)
99c01546dSAndrii NakryikoLIBBPF_SRC := $(abspath ../../lib/bpf)
1085e59344SJean-Philippe BruckerBPFOBJ_OUTPUT := $(OUTPUT)libbpf/
1185e59344SJean-Philippe BruckerBPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a
12be79505cSQuentin MonnetBPF_DESTDIR := $(BPFOBJ_OUTPUT)
13be79505cSQuentin MonnetBPF_INCLUDE := $(BPF_DESTDIR)/include
14be79505cSQuentin MonnetINCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../include/uapi)
15bb7b75e8SJean-Philippe BruckerCFLAGS := -g -Wall $(CLANG_CROSS_FLAGS)
16585bf464SIlya LeoshkevichCFLAGS += $(EXTRA_CFLAGS)
17585bf464SIlya LeoshkevichLDFLAGS += $(EXTRA_LDFLAGS)
18*b0b99c12STony AmbardarLDLIBS += -lelf -lz
199c01546dSAndrii Nakryiko
209c01546dSAndrii Nakryiko# Try to detect best kernel BTF source
219c01546dSAndrii NakryikoKERNEL_REL := $(shell uname -r)
224b0d2d41SSong LiuVMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux)		\
234b0d2d41SSong Liu	$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
244b0d2d41SSong Liu	../../../vmlinux /sys/kernel/btf/vmlinux	\
254b0d2d41SSong Liu	/boot/vmlinux-$(KERNEL_REL)
26a835d38dSToke Høiland-JørgensenVMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword			       \
27a835d38dSToke Høiland-Jørgensen					  $(wildcard $(VMLINUX_BTF_PATHS))))
289c01546dSAndrii Nakryiko
299c01546dSAndrii Nakryikoifeq ($(V),1)
309c01546dSAndrii NakryikoQ =
319c01546dSAndrii Nakryikoelse
329c01546dSAndrii NakryikoQ = @
339c01546dSAndrii NakryikoMAKEFLAGS += --no-print-directory
349c01546dSAndrii Nakryikosubmake_extras := feature_display=0
359c01546dSAndrii Nakryikoendif
369c01546dSAndrii Nakryiko
379c01546dSAndrii Nakryiko.DELETE_ON_ERROR:
389c01546dSAndrii Nakryiko
39be79505cSQuentin Monnet.PHONY: all clean runqslower libbpf_hdrs
409c01546dSAndrii Nakryikoall: runqslower
419c01546dSAndrii Nakryiko
429c01546dSAndrii Nakryikorunqslower: $(OUTPUT)/runqslower
439c01546dSAndrii Nakryiko
449c01546dSAndrii Nakryikoclean:
453290996eSJean-Philippe Brucker	$(call QUIET_CLEAN, runqslower)
4685e59344SJean-Philippe Brucker	$(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT)
4785e59344SJean-Philippe Brucker	$(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d
4885e59344SJean-Philippe Brucker	$(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
4985e59344SJean-Philippe Brucker	$(Q)$(RM) $(OUTPUT)runqslower
5085e59344SJean-Philippe Brucker	$(Q)$(RM) -r .output
519c01546dSAndrii Nakryiko
52be79505cSQuentin Monnetlibbpf_hdrs: $(BPFOBJ)
53be79505cSQuentin Monnet
54b6580cd8SToke Høiland-Jørgensen$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
55*b0b99c12STony Ambardar	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
569c01546dSAndrii Nakryiko
579c01546dSAndrii Nakryiko$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h	      \
58be79505cSQuentin Monnet			$(OUTPUT)/runqslower.bpf.o | libbpf_hdrs
599c01546dSAndrii Nakryiko
60be79505cSQuentin Monnet$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h | libbpf_hdrs
619c01546dSAndrii Nakryiko
629c01546dSAndrii Nakryiko$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
633290996eSJean-Philippe Brucker	$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
649c01546dSAndrii Nakryiko
65b6580cd8SToke Høiland-Jørgensen$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
66bbaf1ff0SFangrui Song	$(QUIET_GEN)$(CLANG) -g -O2 --target=bpf $(INCLUDES)		      \
679c01546dSAndrii Nakryiko		 -c $(filter %.c,$^) -o $@ &&				      \
689c01546dSAndrii Nakryiko	$(LLVM_STRIP) -g $@
699c01546dSAndrii Nakryiko
709c01546dSAndrii Nakryiko$(OUTPUT)/%.o: %.c | $(OUTPUT)
713290996eSJean-Philippe Brucker	$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
729c01546dSAndrii Nakryiko
7385e59344SJean-Philippe Brucker$(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
7485e59344SJean-Philippe Brucker	$(QUIET_MKDIR)mkdir -p $@
759c01546dSAndrii Nakryiko
76a835d38dSToke Høiland-Jørgensen$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
77303dcc25SAndrii Nakryikoifeq ($(VMLINUX_H),)
78a835d38dSToke Høiland-Jørgensen	$(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
79a835d38dSToke Høiland-Jørgensen		echo "Couldn't find kernel BTF; set VMLINUX_BTF to"	       \
80a835d38dSToke Høiland-Jørgensen			"specify its location." >&2;			       \
81a835d38dSToke Høiland-Jørgensen		exit 1;\
82a835d38dSToke Høiland-Jørgensen	fi
833290996eSJean-Philippe Brucker	$(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
84303dcc25SAndrii Nakryikoelse
85303dcc25SAndrii Nakryiko	$(Q)cp "$(VMLINUX_H)" $@
86303dcc25SAndrii Nakryikoendif
879c01546dSAndrii Nakryiko
8885e59344SJean-Philippe Brucker$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
89be79505cSQuentin Monnet	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) \
90be79505cSQuentin Monnet		    DESTDIR=$(BPFOBJ_OUTPUT) prefix= $(abspath $@) install_headers
919c01546dSAndrii Nakryiko
923a2a58c4SPu Lehui$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
933a2a58c4SPu Lehui	$(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) bootstrap
94