-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (48 loc) · 1.47 KB
/
Makefile
File metadata and controls
64 lines (48 loc) · 1.47 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
# xdpcap Makefile
CLANG ?= clang
ARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/')
CFLAGS := -O2 -g -Wall -target bpf \
-D__TARGET_ARCH_$(ARCH) \
-I/usr/include/$(shell uname -m)-linux-gnu \
-Ibpf
GO := go
BINARY := xdpcap
BPF_SRC := bpf/xdpcap.c
BPF_OBJ := bpf/xdpcap.o
.PHONY: all clean generate build install
all: generate build
# Generate Go bindings from eBPF object file
generate: $(BPF_OBJ)
cd internal/capture && $(GO) generate
# Compile eBPF program (depends on vmlinux.h)
$(BPF_OBJ): $(BPF_SRC) bpf/vmlinux.h
$(CLANG) $(CFLAGS) -c $< -o $@
# Build Go binary
build:
CGO_ENABLED=0 $(GO) build -o $(BINARY) ./cmd/xdpcap
# Install binary and default config
install: build
install -m 755 $(BINARY) /usr/local/bin/
install -d /etc/xdpcap
install -m 644 configs/xdpcap.yaml.example /etc/xdpcap/xdpcap.yaml.example
clean:
rm -f $(BPF_OBJ) $(BINARY)
rm -f internal/capture/xdpcap_bpf*.go internal/capture/xdpcap_bpf*.o
# Development helpers
.PHONY: deps deps-system lint test vmlinux
# Install system build dependencies (Ubuntu/Debian) - requires sudo
deps-system:
apt-get update
apt-get install -y clang llvm libbpf-dev linux-tools-common linux-tools-$$(uname -r)
# Download Go module dependencies
deps:
$(GO) mod download
$(GO) mod tidy
# Generate vmlinux.h from kernel BTF (requires bpftool)
vmlinux: bpf/vmlinux.h
bpf/vmlinux.h:
bpftool btf dump file /sys/kernel/btf/vmlinux format c > $@
lint:
golangci-lint run ./...
test:
$(GO) test -v ./...