Tests that load their BPF program through a bpftool skeleton have to bring their own rule for the header. Add a pattern rule to bpf.mk that generates $(OUTPUT)/.skel.h from $(OUTPUT)/.bpf.o with $(BPFTOOL), the bpftool in PATH by default, and removes the partial header if bpftool fails. Also build the programs in the subdirectories listed in BPF_PROG_DIRS, and have make clean remove all program objects and their skeletons. xskxceiver, which moves to net/lib/xsk in the next patch, is the first user of both. Signed-off-by: Maciej Fijalkowski --- tools/testing/selftests/net/bpf.mk | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/bpf.mk b/tools/testing/selftests/net/bpf.mk index a4f6755dd894..e0e10cf44af3 100644 --- a/tools/testing/selftests/net/bpf.mk +++ b/tools/testing/selftests/net/bpf.mk @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Rules to generate bpf objs CLANG ?= clang +BPFTOOL ?= bpftool SCRATCH_DIR := $(OUTPUT)/tools BUILD_DIR := $(SCRATCH_DIR)/build BPFDIR := $(top_srcdir)/tools/lib/bpf @@ -35,13 +36,21 @@ endif CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) -BPF_PROG_OBJS := $(patsubst %.c,$(OUTPUT)/%.o,$(wildcard *.bpf.c)) +# Programs come from *.bpf.c here and in the subdirectories in BPF_PROG_DIRS. +BPF_PROG_SRCS := $(wildcard *.bpf.c $(addsuffix /*.bpf.c,$(BPF_PROG_DIRS))) +BPF_PROG_OBJS := $(patsubst %.c,$(OUTPUT)/%.o,$(notdir $(BPF_PROG_SRCS))) +vpath %.bpf.c $(BPF_PROG_DIRS) $(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS) $(call msg,BPF_PROG,,$@) $(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \ -c $< -o $@ +$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o + $(call msg,GEN-SKEL,,$@) + $(Q)$(BPFTOOL) gen skeleton $< name $(notdir $*) > $@ || \ + { rm -f $@; exit 1; } + $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ $(APIDIR)/linux/bpf.h \ | $(BUILD_DIR)/libbpf @@ -50,4 +59,4 @@ $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ EXTRA_CFLAGS='-g -O0' \ DESTDIR=$(SCRATCH_DIR) prefix= all install_headers -EXTRA_CLEAN += $(SCRATCH_DIR) +EXTRA_CLEAN += $(SCRATCH_DIR) $(BPF_PROG_OBJS) $(BPF_PROG_OBJS:.bpf.o=.skel.h) -- 2.43.0