-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
51 lines (40 loc) · 1.25 KB
/
Makefile
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
CLANG ?= clang
STRIP ?= llvm-strip
TARGET_X86_64 := __TARGET_ARCH_x86
TARGET_ARM64 := __TARGET_ARCH_arm64
LDFLAGS_X86_64 := "-extldflags '-static -L/usr/x86_64-linux-musl/lib64'"
LDFLAGS_ARM64 := "-extldflags '-static -L/usr/aarch64-linux-musl/lib64'"
UNAME_ARCH := $(shell uname -m)
ifeq ($(UNAME_ARCH), aarch64)
TARGET := $(TARGET_ARM64)
LDFLAGS := $(LDFLAGS_ARM64)
else ifeq ($(UNAME_ARCH), x86_64)
TARGET := $(TARGET_X86_64)
LDFLAGS := $(LDFLAGS_X86_64)
else
$(error Unsupported architecture: $(UNAME_ARCH))
endif
CFLAGS := -c -O2 -g -Wall -D $(TARGET) -target bpf -I $(shell pwd)/include $(CFLAGS)
GO_LDFLAGS := -ldflags=$(LDFLAGS)
all: wiretap compile_commands.json
builddepends:
sudo apt install golang clang-13 libbpf-dev bear
include:
mkdir -p include
include/vmlinux.h: include
bpftool btf dump file /sys/kernel/btf/vmlinux format c > include/vmlinux.h
generate: export BPF_CLANG := $(CLANG)
generate: export BPF_CFLAGS := $(CFLAGS)
generate: include/vmlinux.h
go generate ./...
wiretap: generate
go build $(GO_LDFLAGS) -o wiretap cmd/wiretap/main.go
compile_commands.json:
bear -- $(CLANG) $(CFLAGS) pkg/probe/*/bpf/*.bpf.c
clean:
rm wiretap \
*.o \
compile_commands.json \
include/vmlinux.h \
pkg/probe/*/*.o \
pkg/probe/*/*_bpfe*.go