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