1# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2OUTPUT := .output 3CLANG ?= clang 4LLC ?= llc 5LLVM_STRIP ?= llvm-strip 6DEFAULT_BPFTOOL := $(OUTPUT)/sbin/bpftool 7BPFTOOL ?= $(DEFAULT_BPFTOOL) 8LIBBPF_SRC := $(abspath ../../lib/bpf) 9BPFOBJ := $(OUTPUT)/libbpf.a 10BPF_INCLUDE := $(OUTPUT) 11INCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../lib) 12CFLAGS := -g -Wall 13 14# Try to detect best kernel BTF source 15KERNEL_REL := $(shell uname -r) 16VMLINUX_BTF_PATHS := /sys/kernel/btf/vmlinux /boot/vmlinux-$(KERNEL_REL) 17VMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ 18 $(wildcard $(VMLINUX_BTF_PATHS)))) 19 20abs_out := $(abspath $(OUTPUT)) 21ifeq ($(V),1) 22Q = 23msg = 24else 25Q = @ 26msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))"; 27MAKEFLAGS += --no-print-directory 28submake_extras := feature_display=0 29endif 30 31.DELETE_ON_ERROR: 32 33.PHONY: all clean runqslower 34all: runqslower 35 36runqslower: $(OUTPUT)/runqslower 37 38clean: 39 $(call msg,CLEAN) 40 $(Q)rm -rf $(OUTPUT) runqslower 41 42$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ) 43 $(call msg,BINARY,$@) 44 $(Q)$(CC) $(CFLAGS) $^ -lelf -lz -o $@ 45 46$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \ 47 $(OUTPUT)/runqslower.bpf.o 48 49$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h 50 51$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL) 52 $(call msg,GEN-SKEL,$@) 53 $(Q)$(BPFTOOL) gen skeleton $< > $@ 54 55$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT) 56 $(call msg,BPF,$@) 57 $(Q)$(CLANG) -g -O2 -target bpf $(INCLUDES) \ 58 -c $(filter %.c,$^) -o $@ && \ 59 $(LLVM_STRIP) -g $@ 60 61$(OUTPUT)/%.o: %.c | $(OUTPUT) 62 $(call msg,CC,$@) 63 $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@ 64 65$(OUTPUT): 66 $(call msg,MKDIR,$@) 67 $(Q)mkdir -p $(OUTPUT) 68 69$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL) 70 $(call msg,GEN,$@) 71 $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \ 72 echo "Couldn't find kernel BTF; set VMLINUX_BTF to" \ 73 "specify its location." >&2; \ 74 exit 1;\ 75 fi 76 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@ 77 78$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT) 79 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) \ 80 OUTPUT=$(abspath $(dir $@))/ $(abspath $@) 81 82$(DEFAULT_BPFTOOL): 83 $(Q)$(MAKE) $(submake_extras) -C ../bpftool \ 84 prefix= OUTPUT=$(abs_out)/ DESTDIR=$(abs_out) install 85