1194955Strasz# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2194955Straszinclude ../../scripts/Makefile.include 3194955Strasz 4194955StraszOUTPUT ?= $(abspath .output)/ 5194955Strasz 6194955StraszBPFTOOL_OUTPUT := $(OUTPUT)bpftool/ 7194955StraszDEFAULT_BPFTOOL := $(BPFTOOL_OUTPUT)bootstrap/bpftool 8194955StraszBPFTOOL ?= $(DEFAULT_BPFTOOL) 9194955StraszLIBBPF_SRC := $(abspath ../../lib/bpf) 10194955StraszBPFOBJ_OUTPUT := $(OUTPUT)libbpf/ 11194955StraszBPFOBJ := $(BPFOBJ_OUTPUT)libbpf.a 12194955StraszBPF_DESTDIR := $(BPFOBJ_OUTPUT) 13194955StraszBPF_INCLUDE := $(BPF_DESTDIR)/include 14194955StraszINCLUDES := -I$(OUTPUT) -I$(BPF_INCLUDE) -I$(abspath ../../include/uapi) 15194955StraszCFLAGS := -g -Wall $(CLANG_CROSS_FLAGS) 16194955StraszCFLAGS += $(EXTRA_CFLAGS) 17194955StraszLDFLAGS += $(EXTRA_LDFLAGS) 18194955Strasz 19194955Strasz# Try to detect best kernel BTF source 20194955StraszKERNEL_REL := $(shell uname -r) 21194955StraszVMLINUX_BTF_PATHS := $(if $(O),$(O)/vmlinux) \ 22194955Strasz $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ 23194955Strasz ../../../vmlinux /sys/kernel/btf/vmlinux \ 24194955Strasz /boot/vmlinux-$(KERNEL_REL) 25194955StraszVMLINUX_BTF_PATH := $(or $(VMLINUX_BTF),$(firstword \ 26194955Strasz $(wildcard $(VMLINUX_BTF_PATHS)))) 27194955Strasz 28194955Straszifeq ($(V),1) 29194955StraszQ = 30194956Straszelse 31194955StraszQ = @ 32194955StraszMAKEFLAGS += --no-print-directory 33194955Straszsubmake_extras := feature_display=0 34194955Straszendif 35210772Sjoel 36194955Strasz.DELETE_ON_ERROR: 37194955Strasz 38194955Strasz.PHONY: all clean runqslower libbpf_hdrs 39194955Straszall: runqslower 40194955Strasz 41194955Straszrunqslower: $(OUTPUT)/runqslower 42194955Strasz 43194955Straszclean: 44194955Strasz $(call QUIET_CLEAN, runqslower) 45194955Strasz $(Q)$(RM) -r $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT) 46194955Strasz $(Q)$(RM) $(OUTPUT)*.o $(OUTPUT)*.d 47194955Strasz $(Q)$(RM) $(OUTPUT)*.skel.h $(OUTPUT)vmlinux.h 48194955Strasz $(Q)$(RM) $(OUTPUT)runqslower 49194955Strasz $(Q)$(RM) -r .output 50194955Strasz 51194955Straszlibbpf_hdrs: $(BPFOBJ) 52194955Strasz 53194955Strasz$(OUTPUT)/runqslower: $(OUTPUT)/runqslower.o $(BPFOBJ) 54194955Strasz $(QUIET_LINK)$(CC) $(CFLAGS) $^ -lelf -lz -o $@ 55194955Strasz 56194955Strasz$(OUTPUT)/runqslower.o: runqslower.h $(OUTPUT)/runqslower.skel.h \ 57194955Strasz $(OUTPUT)/runqslower.bpf.o | libbpf_hdrs 58194955Strasz 59194955Strasz$(OUTPUT)/runqslower.bpf.o: $(OUTPUT)/vmlinux.h runqslower.h | libbpf_hdrs 60194955Strasz 61194955Strasz$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(BPFTOOL) 62194955Strasz $(QUIET_GEN)$(BPFTOOL) gen skeleton $< > $@ 63194955Strasz 64194955Strasz$(OUTPUT)/%.bpf.o: %.bpf.c $(BPFOBJ) | $(OUTPUT) 65194955Strasz $(QUIET_GEN)$(CLANG) -g -O2 --target=bpf $(INCLUDES) \ 66194955Strasz -c $(filter %.c,$^) -o $@ && \ 67194955Strasz $(LLVM_STRIP) -g $@ 68194955Strasz 69194955Strasz$(OUTPUT)/%.o: %.c | $(OUTPUT) 70194955Strasz $(QUIET_CC)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@ 71194955Strasz 72194955Strasz$(OUTPUT) $(BPFOBJ_OUTPUT) $(BPFTOOL_OUTPUT): 73194955Strasz $(QUIET_MKDIR)mkdir -p $@ 74194955Strasz 75194955Strasz$(OUTPUT)/vmlinux.h: $(VMLINUX_BTF_PATH) | $(OUTPUT) $(BPFTOOL) 76194955Straszifeq ($(VMLINUX_H),) 77194955Strasz $(Q)if [ ! -e "$(VMLINUX_BTF_PATH)" ] ; then \ 78194955Strasz echo "Couldn't find kernel BTF; set VMLINUX_BTF to" \ 79194955Strasz "specify its location." >&2; \ 80194955Strasz exit 1;\ 81194955Strasz fi 82194955Strasz $(QUIET_GEN)$(BPFTOOL) btf dump file $(VMLINUX_BTF_PATH) format c > $@ 83194955Straszelse 84194955Strasz $(Q)cp "$(VMLINUX_H)" $@ 85194955Straszendif 86194955Strasz 87194955Strasz$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(BPFOBJ_OUTPUT) 88194955Strasz $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(BPFOBJ_OUTPUT) \ 89194955Strasz DESTDIR=$(BPFOBJ_OUTPUT) prefix= $(abspath $@) install_headers 90194955Strasz 91194955Strasz$(DEFAULT_BPFTOOL): | $(BPFTOOL_OUTPUT) 92194955Strasz $(Q)$(MAKE) $(submake_extras) -C ../bpftool OUTPUT=$(BPFTOOL_OUTPUT) bootstrap 93194955Strasz