blob: da6de16a3dfbaa2a49e466cb6b8d2895cd4515ca [file] [log] [blame]
Andrii Nakryiko9c015462020-01-12 23:31:42 -08001# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
Jean-Philippe Brucker32909962020-11-10 17:43:08 +01002include ../../scripts/Makefile.include
3
Jean-Philippe Brucker85e59342020-11-10 17:43:09 +01004OUTPUT ?= $(abspath .output)/
5
Jean-Philippe Brucker85e59342020-11-10 17:43:09 +01006BPFTOOL_OUTPUT := $(OUTPUT)bpftool/
7DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bpftool
Andrii Nakryiko9c015462020-01-12 23:31:42 -08008BPFTOOL ?= $(DEFAULT_BPFTOOL)
9LIBBPF_SRC := $(abspath ../../lib/bpf)
Jean-Philippe Brucker85e59342020-11-10 17:43:09 +010010BPFOBJ_OUTPUT := $(OUTPUT)libbpf/
11BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a
Quentin Monnetbe795052021-10-07 20:44:31 +010012BPF_DESTDIR := $(BPFOBJ_OUTPUT)
13BPF_INCLUDE := $(BPF_DESTDIR)/include
14INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../include/uapi)
Jean-Philippe Bruckerbb7b75e2021-12-16 16:38:42 +000015CFLAGS := -g -Wall $(CLANG_CROSS_FLAGS)
Andrii Nakryiko9c015462020-01-12 23:31:42 -080016
17# Try to detect best kernel BTF source
18KERNEL_REL := $(shell uname -r)
Song Liu4b0d2d42021-02-25 15:43:18 -080019VMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux) \
20 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
21 ../../../vmlinux /sys/kernel/btf/vmlinux \
22 /boot/vmlinux-$(KERNEL_REL)
Toke Høiland-Jørgensena835d382020-01-20 14:06:42 +010023VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \
24 $(wildcard $(VMLINUX_BTF_PATHS))))
Andrii Nakryiko9c015462020-01-12 23:31:42 -080025
Andrii Nakryiko9c015462020-01-12 23:31:42 -080026ifeq ($(V),1)
27Q =
Andrii Nakryiko9c015462020-01-12 23:31:42 -080028else
29Q = @
Andrii Nakryiko9c015462020-01-12 23:31:42 -080030MAKEFLAGS += --no-print-directory
31submake_extras := feature_display=0
32endif
33
34.DELETE_ON_ERROR:
35
Quentin Monnetbe795052021-10-07 20:44:31 +010036.PHONY: all clean runqslower libbpf_hdrs
Andrii Nakryiko9c015462020-01-12 23:31:42 -080037all: runqslower
38
39runqslower: $(OUTPUT)/runqslower
40
41clean:
Jean-Philippe Brucker32909962020-11-10 17:43:08 +010042 $(call QUIET_CLEAN, runqslower)
Jean-Philippe Brucker85e59342020-11-10 17:43:09 +010043 $(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
Andrii Nakryiko9c015462020-01-12 23:31:42 -080048
Quentin Monnetbe795052021-10-07 20:44:31 +010049libbpf_hdrs: $(BPFOBJ)
50
Toke Høiland-Jørgensenb6580cd2020-01-20 14:06:51 +010051$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ)
Jean-Philippe Brucker32909962020-11-10 17:43:08 +010052 $(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@
Andrii Nakryiko9c015462020-01-12 23:31:42 -080053
54$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \
Quentin Monnetbe795052021-10-07 20:44:31 +010055 $(OUTPUT)/runqslower.bpf.o | libbpf_hdrs
Andrii Nakryiko9c015462020-01-12 23:31:42 -080056
Quentin Monnetbe795052021-10-07 20:44:31 +010057$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h | libbpf_hdrs
Andrii Nakryiko9c015462020-01-12 23:31:42 -080058
59$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL)
Jean-Philippe Brucker32909962020-11-10 17:43:08 +010060 $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@
Andrii Nakryiko9c015462020-01-12 23:31:42 -080061
Toke Høiland-Jørgensenb6580cd2020-01-20 14:06:51 +010062$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT)
Jean-Philippe Brucker32909962020-11-10 17:43:08 +010063 $(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES) \
Andrii Nakryiko9c015462020-01-12 23:31:42 -080064 -c $(filter %.c,$^) -o $@ && \
65 $(LLVM_STRIP) -g $@
66
67$(OUTPUT)/%.o: %.c | $(OUTPUT)
Jean-Philippe Brucker32909962020-11-10 17:43:08 +010068 $(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
Andrii Nakryiko9c015462020-01-12 23:31:42 -080069
Jean-Philippe Brucker85e59342020-11-10 17:43:09 +010070$(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT):
71 $(QUIET_MKDIR)mkdir -p $@
Andrii Nakryiko9c015462020-01-12 23:31:42 -080072
Toke Høiland-Jørgensena835d382020-01-20 14:06:42 +010073$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL)
Andrii Nakryiko303dcc22021-03-02 16:40:10 -080074ifeq ($(VMLINUX_H),)
Toke Høiland-Jørgensena835d382020-01-20 14:06:42 +010075 $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \
76 echo "Couldn't find kernel BTF; set VMLINUX_BTF to" \
77 "specify its location." >&2; \
78 exit 1;\
79 fi
Jean-Philippe Brucker32909962020-11-10 17:43:08 +010080 $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@
Andrii Nakryiko303dcc22021-03-02 16:40:10 -080081else
82 $(Q)cp "$(VMLINUX_H)" $@
83endif
Andrii Nakryiko9c015462020-01-12 23:31:42 -080084
Jean-Philippe Brucker85e59342020-11-10 17:43:09 +010085$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT)
Quentin Monnetbe795052021-10-07 20:44:31 +010086 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) \
87 DESTDIR=$(BPFOBJ_OUTPUT) prefix= $(abspath $@) install_headers
Andrii Nakryiko9c015462020-01-12 23:31:42 -080088
Quentin Monnetbe795052021-10-07 20:44:31 +010089$(DEFAULT_BPFTOOL): $(BPFOBJ) | $(BPFTOOL_OUTPUT)
Jean-Philippe Brucker2d9393f2020-11-10 17:43:10 +010090 $(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) \
Jean-Philippe Bruckerbb7b75e2021-12-16 16:38:42 +000091 ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD)