mirror of
https://github.com/eunomia-bpf/bpf-developer-tutorial.git
synced 2026-03-20 20:05:56 +08:00
* feat: add tcx and bpf token tutorials * docs: auto-generate documentation * docs: rewrite tcx and bpf_token tutorials with richer content and consistent style Rewrote all 4 README files (EN/ZH for both tutorials) to match the existing tutorial style with detailed background, full code listings, step-by-step explanations, comparison tables, and proper references. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style: replace em dashes with colons, commas, and parentheses Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: auto-generate documentation * ci: add tcx and bpf_token builds to CI; simplify execl in token_userns_demo - Add make targets for src/50-tcx and src/features/bpf_token to the test-libbpf CI workflow. - Replace four separate execl() calls with a single execv() using a dynamically built argv array, reducing complexity and eliminating CodeFactor command-injection false positives. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * ci: fix mkdocs path in trigger-sync workflow Use .venv/bin/mkdocs instead of bare mkdocs, since make install puts it inside a virtualenv. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: LinuxDev9002 <linuxdev8883@example.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
93 lines
2.8 KiB
Makefile
93 lines
2.8 KiB
Makefile
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
|
OUTPUT := .output
|
|
CLANG ?= clang
|
|
LIBBPF_SRC := $(abspath ../third_party/libbpf/src)
|
|
BPFTOOL_SRC := $(abspath ../third_party/bpftool/src)
|
|
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
|
|
BPFTOOL_OUTPUT ?= $(abspath $(OUTPUT)/bpftool)
|
|
BPFTOOL ?= $(BPFTOOL_OUTPUT)/bootstrap/bpftool
|
|
ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' \
|
|
| sed 's/arm.*/arm/' \
|
|
| sed 's/aarch64/arm64/' \
|
|
| sed 's/ppc64le/powerpc/' \
|
|
| sed 's/mips.*/mips/' \
|
|
| sed 's/riscv64/riscv/' \
|
|
| sed 's/loongarch64/loongarch/')
|
|
VMLINUX := ../third_party/vmlinux/$(ARCH)/vmlinux.h
|
|
INCLUDES := -I$(OUTPUT) -I../third_party/libbpf/include/uapi -I$(dir $(VMLINUX)) -I.
|
|
CFLAGS := -g -Wall
|
|
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
|
|
|
|
APPS = tcx_demo
|
|
|
|
CLANG_BPF_SYS_INCLUDES ?= $(shell $(CLANG) -v -E - </dev/null 2>&1 \
|
|
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
|
|
|
|
ifeq ($(V),1)
|
|
Q =
|
|
msg =
|
|
else
|
|
Q = @
|
|
msg = @printf ' %-8s %s%s\n' \
|
|
"$(1)" \
|
|
"$(patsubst $(abspath $(OUTPUT))/%,%,$(2))" \
|
|
"$(if $(3), $(3))";
|
|
MAKEFLAGS += --no-print-directory
|
|
endif
|
|
|
|
define allow-override
|
|
$(if $(or $(findstring environment,$(origin $(1))),\
|
|
$(findstring command line,$(origin $(1)))),,\
|
|
$(eval $(1) = $(2)))
|
|
endef
|
|
|
|
$(call allow-override,CC,$(CROSS_COMPILE)cc)
|
|
$(call allow-override,LD,$(CROSS_COMPILE)ld)
|
|
|
|
.PHONY: all
|
|
all: $(APPS)
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(call msg,CLEAN)
|
|
$(Q)rm -rf $(OUTPUT) $(APPS)
|
|
|
|
$(OUTPUT) $(OUTPUT)/libbpf $(BPFTOOL_OUTPUT):
|
|
$(call msg,MKDIR,$@)
|
|
$(Q)mkdir -p $@
|
|
|
|
$(LIBBPF_OBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
|
|
$(call msg,LIB,$@)
|
|
$(Q)$(MAKE) -C $(LIBBPF_SRC) BUILD_STATIC_ONLY=1 \
|
|
OBJDIR=$(dir $@)/libbpf DESTDIR=$(dir $@) \
|
|
INCLUDEDIR= LIBDIR= UAPIDIR= \
|
|
install
|
|
|
|
$(BPFTOOL): | $(BPFTOOL_OUTPUT)
|
|
$(call msg,BPFTOOL,$@)
|
|
$(Q)$(MAKE) ARCH= CROSS_COMPILE= OUTPUT=$(BPFTOOL_OUTPUT)/ -C $(BPFTOOL_SRC) bootstrap
|
|
|
|
$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) $(BPFTOOL)
|
|
$(call msg,BPF,$@)
|
|
$(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) \
|
|
$(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) \
|
|
-c $(filter %.c,$^) -o $(patsubst %.bpf.o,%.tmp.bpf.o,$@)
|
|
$(Q)$(BPFTOOL) gen object $@ $(patsubst %.bpf.o,%.tmp.bpf.o,$@)
|
|
|
|
$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL)
|
|
$(call msg,GEN-SKEL,$@)
|
|
$(Q)$(BPFTOOL) gen skeleton $< > $@
|
|
|
|
$(patsubst %,$(OUTPUT)/%.o,$(APPS)): %.o: %.skel.h
|
|
|
|
$(OUTPUT)/%.o: %.c $(wildcard %.h) | $(OUTPUT)
|
|
$(call msg,CC,$@)
|
|
$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@
|
|
|
|
$(APPS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) | $(OUTPUT)
|
|
$(call msg,BINARY,$@)
|
|
$(Q)$(CC) $(CFLAGS) $^ $(ALL_LDFLAGS) -lelf -lz -o $@
|
|
|
|
.DELETE_ON_ERROR:
|
|
.SECONDARY:
|