Skip to content

Commit

Permalink
Add bpftool as submodule
Browse files Browse the repository at this point in the history
Generate `bpftool` from submodule
Set submodule `bpftool` HEAD to v6.7.0
Build `bpftool` in output folder

Signed-off-by: Nurdan Almazbekov <nalmazbe@gmail.com>
  • Loading branch information
nurdann authored and anakryiko committed Apr 6, 2022
1 parent d6f8b82 commit a08b978
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libbpf"]
path = libbpf
url = https://github.com/libbpf/libbpf.git
[submodule "bpftool"]
path = bpftool
url = https://github.com/libbpf/bpftool
1 change: 1 addition & 0 deletions bpftool
Submodule bpftool added at cdd0b4
12 changes: 9 additions & 3 deletions examples/c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
OUTPUT := .output
CLANG ?= clang
LLVM_STRIP ?= llvm-strip
BPFTOOL ?= $(abspath ../../tools/bpftool)
LIBBPF_SRC := $(abspath ../../libbpf/src)
BPFTOOL_SRC := $(abspath ../../bpftool/src)
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
BPFTOOL ?= $(abspath $(OUTPUT)/bpftool/bpftool)
ARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/' | sed 's/mips.*/mips/')
VMLINUX := ../../vmlinux/$(ARCH)/vmlinux.h
# Use our own libbpf API headers and Linux UAPI headers distributed with
Expand Down Expand Up @@ -46,7 +47,7 @@ clean:
$(call msg,CLEAN)
$(Q)rm -rf $(OUTPUT) $(APPS)

$(OUTPUT) $(OUTPUT)/libbpf:
$(OUTPUT) $(OUTPUT)/libbpf $(dir $(BPFTOOL)):
$(call msg,MKDIR,$@)
$(Q)mkdir -p $@

Expand All @@ -58,14 +59,19 @@ $(LIBBPF_OBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPU
INCLUDEDIR= LIBDIR= UAPIDIR= \
install

# Build bpftool
$(BPFTOOL): | $(dir $(BPFTOOL))
$(call msg,BPFTOOL,$@)
$(Q)$(MAKE) OUTPUT=$(dir $(BPFTOOL)) -C $(BPFTOOL_SRC)

# Build BPF code
$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT)
$(call msg,BPF,$@)
$(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) -c $(filter %.c,$^) -o $@
$(Q)$(LLVM_STRIP) -g $@ # strip useless DWARF info

# Generate BPF skeletons
$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT)
$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
$(call msg,GEN-SKEL,$@)
$(Q)$(BPFTOOL) gen skeleton $< > $@

Expand Down
Binary file removed tools/bpftool
Binary file not shown.

0 comments on commit a08b978

Please sign in to comment.