xref: /openbmc/linux/tools/bpf/runqslower/Makefile (revision 585bf4640ebe9ea4730b5b603347b4ba39731546)
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)
16*585bf464SIlya LeoshkevichCFLAGS += $(EXTRA_CFLAGS)
17*585bf464SIlya LeoshkevichLDFLAGS += $(EXTRA_LDFLAGS)
189c01546dSAndrii Nakryiko
199c01546dSAndrii Nakryiko# Try to detect best kernel BTF source
209c01546dSAndrii NakryikoKERNEL_REL := $(shell uname -r)
214b0d2d41SSong LiuVMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux)		\
224b0d2d41SSong Liu	$(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
234b0d2d41SSong Liu	../../../vmlinux /sys/kernel/btf/vmlinux	\
244b0d2d41SSong Liu	/boot/vmlinux-$(KERNEL_REL)
25a835d38dSToke Høiland-JørgensenVMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword			       \
26a835d38dSToke Høiland-Jørgensen					  $(wildcard $(VMLINUX_BTF_PATHS))))
279c01546dSAndrii Nakryiko
289c01546dSAndrii Nakryikoifeq ($(V),1)
299c01546dSAndrii NakryikoQ =
309c01546dSAndrii Nakryikoelse
319c01546dSAndrii NakryikoQ = @
329c01546dSAndrii NakryikoMAKEFLAGS += --no-print-directory
339c01546dSAndrii Nakryikosubmake_extras := feature_display=0
349c01546dSAndrii Nakryikoendif
359c01546dSAndrii Nakryiko
369c01546dSAndrii Nakryiko.DELETE_ON_ERROR:
379c01546dSAndrii Nakryiko
38be79505cSQuentin Monnet.PHONY: all clean runqslower libbpf_hdrs
399c01546dSAndrii Nakryikoall: runqslower
409c01546dSAndrii Nakryiko
419c01546dSAndrii Nakryikorunqslower: $(OUTPUT)/runqslower
429c01546dSAndrii Nakryiko
439c01546dSAndrii Nakryikoclean:
443290996eSJean-Philippe Brucker	$(call QUIET_CLEAN, runqslower)
4585e59344SJean-Philippe Brucker	$(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT)
4685e59344SJean-Philippe Brucker	$(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d
4785e59344SJean-Philippe Brucker	$(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h
4885e59344SJean-Philippe Brucker	$(Q)$(RM) $(OUTPUT)runqslower
4985e59344SJean-Philippe Brucker	$(Q)$(RM) -r .output
509c01546dSAndrii Nakryiko
51be79505cSQuentin Monnetlibbpf_hdrs: $(BPFOBJ)
52be79505cSQuentin Monnet
53b6580cd8SToke Høiland-Jørgensen$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
543290996eSJean-Philippe Brucker	$(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
559c01546dSAndrii Nakryiko
569c01546dSAndrii Nakryiko$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h	      \
57be79505cSQuentin Monnet			$(OUTPUT)/runqslower.bpf.o | libbpf_hdrs
589c01546dSAndrii Nakryiko
59be79505cSQuentin Monnet$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h | libbpf_hdrs
609c01546dSAndrii Nakryiko
619c01546dSAndrii Nakryiko$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
623290996eSJean-Philippe Brucker	$(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
639c01546dSAndrii Nakryiko
64b6580cd8SToke Høiland-Jørgensen$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
653290996eSJean-Philippe Brucker	$(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES)		      \
669c01546dSAndrii Nakryiko		 -c $(filter %.c,$^) -o $@ &&				      \
679c01546dSAndrii Nakryiko	$(LLVM_STRIP) -g $@
689c01546dSAndrii Nakryiko
699c01546dSAndrii Nakryiko$(OUTPUT)/%.o: %.c | $(OUTPUT)
703290996eSJean-Philippe Brucker	$(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
719c01546dSAndrii Nakryiko
7285e59344SJean-Philippe Brucker$(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
7385e59344SJean-Philippe Brucker	$(QUIET_MKDIR)mkdir -p $@
749c01546dSAndrii Nakryiko
75a835d38dSToke Høiland-Jørgensen$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
76303dcc25SAndrii Nakryikoifeq ($(VMLINUX_H),)
77a835d38dSToke Høiland-Jørgensen	$(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
78a835d38dSToke Høiland-Jørgensen		echo "Couldn't find kernel BTF; set VMLINUX_BTF to"	       \
79a835d38dSToke Høiland-Jørgensen			"specify its location." >&2;			       \
80a835d38dSToke Høiland-Jørgensen		exit 1;\
81a835d38dSToke Høiland-Jørgensen	fi
823290996eSJean-Philippe Brucker	$(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
83303dcc25SAndrii Nakryikoelse
84303dcc25SAndrii Nakryiko	$(Q)cp "$(VMLINUX_H)" $@
85303dcc25SAndrii Nakryikoendif
869c01546dSAndrii Nakryiko
8785e59344SJean-Philippe Brucker$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
88be79505cSQuentin Monnet	$(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) \
89be79505cSQuentin Monnet		    DESTDIR=$(BPFOBJ_OUTPUT) prefix= $(abspath $@) install_headers
909c01546dSAndrii Nakryiko
913a2a58c4SPu Lehui$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT)
923a2a58c4SPu Lehui	$(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) bootstrap
93