-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (52 loc) · 1.81 KB
/
Makefile
File metadata and controls
65 lines (52 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
.PHONY: all clean build ebpf ebpf-debug go-build vmlinux build-libbpf test debug
EBPF_CFLAGS ?=
# Default target
all: vmlinux ebpf go-build
build-libbpf:
make -C ./libbpf/src LIBSUBDIR=lib DESTDIR=../../dest/libbpf install install_uapi_headers
# Generate vmlinux.h from kernel BTF
vmlinux:
@if [ ! -f bpf/vmlinux.h ]; then \
echo "Generating vmlinux.h..."; \
bpftool btf dump file /sys/kernel/btf/vmlinux format c > bpf/vmlinux.h; \
fi
# eBPF compilation
ebpf: vmlinux
clang -g -O2 -D__TARGET_ARCH_x86 $(EBPF_CFLAGS) -I./bpf -I./dest/libbpf/usr/include -idirafter /usr/include/x86_64-linux-gnu -c bpf/php.bpf.c -target bpf -o bpf/php.bpf.o
# eBPF compilation with debug (enables bpf_trace_printk)
ebpf-debug:
$(MAKE) ebpf EBPF_CFLAGS=-DDEBUG
# Debug build (eBPF with -DDEBUG + go binary)
debug: ebpf-debug go-build
# Go build
go-build:
CGO_CFLAGS="-I$(CURDIR)/dest/libbpf/usr/include" \
CGO_LDFLAGS="-L$(CURDIR)/dest/libbpf/usr/lib -lbpf -lelf -lzstd" \
go build -ldflags='-extldflags "-static"'
# Build everything
build: ebpf go-build
# Run tests
test:
CGO_CFLAGS="-I$(CURDIR)/dest/libbpf/usr/include" \
CGO_LDFLAGS="-L$(CURDIR)/dest/libbpf/usr/lib -lbpf -lelf -lzstd" \
go test -v ./...
# Clean build artifacts
clean:
rm -f bpf/*.o
rm -f bpf/vmlinux.h
rm -f php-dcr
# Run the program (requires root)
run: build
sudo ./php-dcr
# Help target
help:
@echo "Available targets:"
@echo " build-libbpf - Build and install libbpf to dest/libbpf"
@echo " vmlinux - Generate vmlinux.h from kernel BTF"
@echo " ebpf - Compile eBPF program"
@echo " go-build - Build Go binary"
@echo " build - Build everything"
@echo " all - Build everything (default)"
@echo " clean - Remove build artifacts"
@echo " test - Run Go tests"
@echo " run - Build and run the program (requires root)"