-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
40 lines (31 loc) · 1016 Bytes
/
makefile
File metadata and controls
40 lines (31 loc) · 1016 Bytes
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
# File names
BPF_SRC := watchdog.bpf.c
BPF_OBJ := watchdog.bpf.o
SKEL_HEADER := watchdog.skel.h
CONVENTION := watchdog
USER_SRC := main.cpp
USER_BIN := watchdog
VMLINUX := vmlinux.h
# Compiler settings
CLANG := clang
GPP := g++
CFLAGS := -O2 -g -Wall
BPF_CFLAGS := -target bpf -O2 -g -mllvm -bpf-stack-size=512 -I/usr/include/bpf -I/usr/include/linux -D__TARGET_ARCH_x86
# Libs
LDFLAGS := -lbpf -lpthread -lstdc++fs
.PHONY: all clean
build: $(USER_BIN)
# Step 0: Generate vmlinux.h
$(VMLINUX):
bpftool btf dump file /sys/kernel/btf/vmlinux format c > $@
# Step 1: Compile BPF program
$(BPF_OBJ): $(BPF_SRC) $(VMLINUX)
$(CLANG) $(BPF_CFLAGS) -c $< -o $@
# Step 2: Generate skeleton
$(SKEL_HEADER): $(BPF_OBJ)
bpftool gen skeleton $< name $(CONVENTION) > $@
# Step 3: Build userspace binary
$(USER_BIN): $(USER_SRC) $(SKEL_HEADER)
$(GPP) $(CFLAGS) $(USER_SRC) -o $@ $(LDFLAGS)
clean:
rm -f $(BPF_OBJ) $(SKEL_HEADER) $(USER_BIN) $(VMLINUX)