Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 1 | # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) |
Jean-Philippe Brucker | 3290996 | 2020-11-10 17:43:08 +0100 | [diff] [blame] | 2 | include ../../scripts/Makefile.include |
| 3 | |
Jean-Philippe Brucker | 85e5934 | 2020-11-10 17:43:09 +0100 | [diff] [blame] | 4 | OUTPUT ?= $(abspath .output)/ |
| 5 | |
Jean-Philippe Brucker | 85e5934 | 2020-11-10 17:43:09 +0100 | [diff] [blame] | 6 | BPFTOOL_OUTPUT := $(OUTPUT)bpftool/ |
| 7 | DEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bpftool |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 8 | BPFTOOL ?= $(DEFAULT_BPFTOOL) |
| 9 | LIBBPF_SRC := $(abspath ../../lib/bpf) |
Jean-Philippe Brucker | 85e5934 | 2020-11-10 17:43:09 +0100 | [diff] [blame] | 10 | BPFOBJ_OUTPUT := $(OUTPUT)libbpf/ |
| 11 | BPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a |
Quentin Monnet | be79505 | 2021-10-07 20:44:31 +0100 | [diff] [blame] | 12 | BPF_DESTDIR := $(BPFOBJ_OUTPUT) |
| 13 | BPF_INCLUDE := $(BPF_DESTDIR)/include |
| 14 | INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../include/uapi) |
Jean-Philippe Brucker | bb7b75e | 2021-12-16 16:38:42 +0000 | [diff] [blame] | 15 | CFLAGS := -g -Wall $(CLANG_CROSS_FLAGS) |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 16 | |
| 17 | # Try to detect best kernel BTF source |
| 18 | KERNEL_REL := $(shell uname -r) |
Song Liu | 4b0d2d4 | 2021-02-25 15:43:18 -0800 | [diff] [blame] | 19 | VMLINUX_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ørgensen | a835d38 | 2020-01-20 14:06:42 +0100 | [diff] [blame] | 23 | VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ |
| 24 | $(wildcard $(VMLINUX_BTF_PATHS)))) |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 25 | |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 26 | ifeq ($(V),1) |
| 27 | Q = |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 28 | else |
| 29 | Q = @ |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 30 | MAKEFLAGS += --no-print-directory |
| 31 | submake_extras := feature_display=0 |
| 32 | endif |
| 33 | |
| 34 | .DELETE_ON_ERROR: |
| 35 | |
Quentin Monnet | be79505 | 2021-10-07 20:44:31 +0100 | [diff] [blame] | 36 | .PHONY: all clean runqslower libbpf_hdrs |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 37 | all: runqslower |
| 38 | |
| 39 | runqslower: $(OUTPUT)/runqslower |
| 40 | |
| 41 | clean: |
Jean-Philippe Brucker | 3290996 | 2020-11-10 17:43:08 +0100 | [diff] [blame] | 42 | $(call QUIET_CLEAN, runqslower) |
Jean-Philippe Brucker | 85e5934 | 2020-11-10 17:43:09 +0100 | [diff] [blame] | 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 |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 48 | |
Quentin Monnet | be79505 | 2021-10-07 20:44:31 +0100 | [diff] [blame] | 49 | libbpf_hdrs: $(BPFOBJ) |
| 50 | |
Toke Høiland-Jørgensen | b6580cd | 2020-01-20 14:06:51 +0100 | [diff] [blame] | 51 | $(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ) |
Jean-Philippe Brucker | 3290996 | 2020-11-10 17:43:08 +0100 | [diff] [blame] | 52 | $(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@ |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 53 | |
| 54 | $(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \ |
Quentin Monnet | be79505 | 2021-10-07 20:44:31 +0100 | [diff] [blame] | 55 | $(OUTPUT)/runqslower.bpf.o | libbpf_hdrs |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 56 | |
Quentin Monnet | be79505 | 2021-10-07 20:44:31 +0100 | [diff] [blame] | 57 | $(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h | libbpf_hdrs |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 58 | |
| 59 | $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL) |
Jean-Philippe Brucker | 3290996 | 2020-11-10 17:43:08 +0100 | [diff] [blame] | 60 | $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@ |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 61 | |
Toke Høiland-Jørgensen | b6580cd | 2020-01-20 14:06:51 +0100 | [diff] [blame] | 62 | $(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT) |
Jean-Philippe Brucker | 3290996 | 2020-11-10 17:43:08 +0100 | [diff] [blame] | 63 | $(QUIET_GEN)$(CLANG) -g -O2 -target bpf $(INCLUDES) \ |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 64 | -c $(filter %.c,$^) -o $@ && \ |
| 65 | $(LLVM_STRIP) -g $@ |
| 66 | |
| 67 | $(OUTPUT)/%.o: %.c | $(OUTPUT) |
Jean-Philippe Brucker | 3290996 | 2020-11-10 17:43:08 +0100 | [diff] [blame] | 68 | $(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@ |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 69 | |
Jean-Philippe Brucker | 85e5934 | 2020-11-10 17:43:09 +0100 | [diff] [blame] | 70 | $(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT): |
| 71 | $(QUIET_MKDIR)mkdir -p $@ |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 72 | |
Toke Høiland-Jørgensen | a835d38 | 2020-01-20 14:06:42 +0100 | [diff] [blame] | 73 | $(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL) |
Andrii Nakryiko | 303dcc2 | 2021-03-02 16:40:10 -0800 | [diff] [blame] | 74 | ifeq ($(VMLINUX_H),) |
Toke Høiland-Jørgensen | a835d38 | 2020-01-20 14:06:42 +0100 | [diff] [blame] | 75 | $(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 Brucker | 3290996 | 2020-11-10 17:43:08 +0100 | [diff] [blame] | 80 | $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@ |
Andrii Nakryiko | 303dcc2 | 2021-03-02 16:40:10 -0800 | [diff] [blame] | 81 | else |
| 82 | $(Q)cp "$(VMLINUX_H)" $@ |
| 83 | endif |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 84 | |
Jean-Philippe Brucker | 85e5934 | 2020-11-10 17:43:09 +0100 | [diff] [blame] | 85 | $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT) |
Quentin Monnet | be79505 | 2021-10-07 20:44:31 +0100 | [diff] [blame] | 86 | $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) \ |
| 87 | DESTDIR=$(BPFOBJ_OUTPUT) prefix= $(abspath $@) install_headers |
Andrii Nakryiko | 9c01546 | 2020-01-12 23:31:42 -0800 | [diff] [blame] | 88 | |
Quentin Monnet | be79505 | 2021-10-07 20:44:31 +0100 | [diff] [blame] | 89 | $(DEFAULT_BPFTOOL): $(BPFOBJ) | $(BPFTOOL_OUTPUT) |
Jean-Philippe Brucker | 2d9393f | 2020-11-10 17:43:10 +0100 | [diff] [blame] | 90 | $(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) \ |
Jean-Philippe Brucker | bb7b75e | 2021-12-16 16:38:42 +0000 | [diff] [blame] | 91 | ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) |