diff --git a/source/mk/bpf.mk b/source/mk/bpf.mk index 3e42f978a47bf755f91c9acf061e4324a40520dd..883cc7f4bf95c0517d5d313609b880c1d98e72e1 100644 --- a/source/mk/bpf.mk +++ b/source/mk/bpf.mk @@ -2,7 +2,6 @@ CLANG ?= clang LLVM_STRIP ?= llvm-strip BPFTOOL ?= $(SRC)/lib/internal/ebpf/tools/bpftool APPS_DIR := $(abspath .) -CFLAGS := -g -O2 -Wall prefix ?= /usr/local ARCH := $(shell uname -m | sed 's/x86_64/x86/') LIBBPF_OBJ := $(OBJ_LIB_PATH)/libbpf.a @@ -13,7 +12,9 @@ else OUTPUT := $(OBJ_TOOLS_ROOT) endif -INCLUDES := -I$(OBJPATH) -I$(SRC)/lib/internal/ebpf -I$(OUTPUT) -I$(OBJ_LIB_PATH) -I$(SRC)/lib/internal/ebpf/libbpf/include/uapi +CFLAGS += $(EXTRA_CLFAGS) -g -O2 -Wall +LDFLAGS += $(EXTRA_LDFLAGS) +INCLUDES += $(EXTRA_INCLUDES) -I$(OBJPATH) -I$(SRC)/lib/internal/ebpf -I$(OUTPUT) -I$(OBJ_LIB_PATH) -I$(SRC)/lib/internal/ebpf/libbpf/include/uapi ifeq ($(V),1) Q = @@ -27,31 +28,40 @@ else MAKEFLAGS += --no-print-directory endif -cobjs := $(foreach n, $(cobject), $(OBJPATH)/$(n)) -bpfobjs := $(foreach n, $(bpfobject), $(OBJPATH)/$(n)) -bpfskel := $(patsubst %.bpf.o, %.skel.h, $(bpfobjs)) +newdirs := $(addprefix $(OBJPATH)/, $(newdirs)) -$(target): $(cobjs) $(bpfskel) $(LIBBPF_OBJ) +cobjs := $(patsubst %.c, %.o, $(csrcs)) +target_cobjs := $(foreach n, $(cobjs), $(OBJPATH)/$(n)) + +bpfobjs := $(patsubst %.c, %.o, $(bpfsrcs)) +target_bpfobjs := $(foreach n, $(bpfobjs), $(OBJPATH)/$(n)) + +bpfskel := $(patsubst %.bpf.o, %.skel.h, $(target_bpfobjs)) + +$(target): $(target_cobjs) $(bpfskel) $(LIBBPF_OBJ) $(call msg,BINARY,$@) - $(Q)$(CC) $(CFLAGS) $(INCLUDES) $^ -lelf -lz -o $(OUTPUT)/$@ + $(Q)$(CC) $(CFLAGS) $(INCLUDES) $^ -lelf -lz -o $(OUTPUT)/$@ $(LDFLAGS) echo $(target):$(DEPEND) >> $(OUTPUT)/$(SYSAK_RULES) -$(cobjs): $(cobject) +$(target_cobjs): $(cobjs) -$(cobject): %.o : %.c $(bpfskel) +$(cobjs): %.o : %.c $(bpfskel) $(call msg,CC,$@) $(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $(OBJPATH)/$@ -$(bpfskel): %.skel.h : %.bpf.o $(bpfobjs) +$(bpfskel): %.skel.h : %.bpf.o $(target_bpfobjs) $(call msg,GEN-SKEL,$@) $(Q)$(BPFTOOL) gen skeleton $< > $@ -$(bpfobjs): $(bpfobject) +$(target_bpfobjs): $(bpfobjs) -$(bpfobject) : %.o : %.c +$(bpfobjs) : %.o : %.c dirs $(call msg,BPF,$@) $(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) -c $< -o $(OBJPATH)/$@ $(Q)$(LLVM_STRIP) -g $(OBJPATH)/$@ # strip useless DWARF info +dirs: + mkdir -p $(newdirs) + # delete failed targets .DELETE_ON_ERROR: diff --git a/source/tools/test/bpf_test/Makefile b/source/tools/test/bpf_test/Makefile index aab68e82a1a7b1568d20178c203d13962d53742a..ab15a62b0279f3b32dd1c701870259e75eae3fc8 100644 --- a/source/tools/test/bpf_test/Makefile +++ b/source/tools/test/bpf_test/Makefile @@ -1,6 +1,8 @@ -bpfobject := bpftest1.bpf.o bpftest2.bpf.o -cobject := bpftest.o +newdirs := $(shell find ./ -type d) + +bpfsrcs := $(wildcard bpf/*.bpf.c) +csrcs := $(wildcard *.c) target := bpftest include $(SRC)/mk/bpf.mk \ No newline at end of file diff --git a/source/tools/test/bpf_test/bpftest1.bpf.c b/source/tools/test/bpf_test/bpf/bpftest1.bpf.c similarity index 93% rename from source/tools/test/bpf_test/bpftest1.bpf.c rename to source/tools/test/bpf_test/bpf/bpftest1.bpf.c index a8dbebbddc60090afad690f29969341fdb4db97a..4186d9095459934044e39400f3b8980a2fd8bf2c 100644 --- a/source/tools/test/bpf_test/bpftest1.bpf.c +++ b/source/tools/test/bpf_test/bpf/bpftest1.bpf.c @@ -2,7 +2,7 @@ #include #include #include -#include "bpftest.h" +#include "../bpftest.h" diff --git a/source/tools/test/bpf_test/bpftest2.bpf.c b/source/tools/test/bpf_test/bpf/bpftest2.bpf.c similarity index 93% rename from source/tools/test/bpf_test/bpftest2.bpf.c rename to source/tools/test/bpf_test/bpf/bpftest2.bpf.c index a8dbebbddc60090afad690f29969341fdb4db97a..4186d9095459934044e39400f3b8980a2fd8bf2c 100644 --- a/source/tools/test/bpf_test/bpftest2.bpf.c +++ b/source/tools/test/bpf_test/bpf/bpftest2.bpf.c @@ -2,7 +2,7 @@ #include #include #include -#include "bpftest.h" +#include "../bpftest.h" diff --git a/source/tools/test/bpf_test/bpftest.c b/source/tools/test/bpf_test/bpftest.c index 0d521a99d471c7a1ac72110d3c987413a372d46d..6d3420e7f9bf49ed04bd9f273fc27194e51551aa 100644 --- a/source/tools/test/bpf_test/bpftest.c +++ b/source/tools/test/bpf_test/bpftest.c @@ -1,8 +1,8 @@ #include #include #include "bpftest.h" -#include "bpftest1.skel.h" -#include "bpftest2.skel.h" +#include "bpf/bpftest1.skel.h" +#include "bpf/bpftest2.skel.h" static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args)