-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
111 lines (89 loc) · 2.95 KB
/
Makefile
File metadata and controls
111 lines (89 loc) · 2.95 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
CLANG ?= clang
LLVM_STRIP ?= llvm-strip
BPFTOOL ?= bpftool
# Architecture
ARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/')
# Directories
SRC_DIR := src
OBJ_DIR := build
OUTPUT := $(OBJ_DIR)
# Application name
APP := io_uring_monitor
# Compiler flags
INCLUDES := -I$(OUTPUT) -I/usr/include
CFLAGS := -g -Wall -Wextra
BPF_CFLAGS := -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES)
# Libraries
LIBS := -lbpf -lelf -lz -ljson-c
# Source files
BPF_SRC := $(SRC_DIR)/$(APP).bpf.c
USER_SRC := $(SRC_DIR)/$(APP).c
HEADER := $(SRC_DIR)/$(APP).h
# Object files
BPF_OBJ := $(OUTPUT)/$(APP).bpf.o
SKEL_H := $(OUTPUT)/$(APP).skel.h
VMLINUX_H := $(OUTPUT)/vmlinux.h
USER_OBJ := $(OUTPUT)/$(APP).o
# Final binary
BINARY := $(OUTPUT)/$(APP)
.PHONY: all clean install uninstall check-deps
all: check-deps $(BINARY)
# Check dependencies
check-deps:
@echo "Checking dependencies..."
@command -v $(CLANG) >/dev/null 2>&1 || { echo "Error: clang not found. Install clang/llvm toolchain."; exit 1; }
@command -v $(BPFTOOL) >/dev/null 2>&1 || { echo "Error: bpftool not found. Install bpftool package."; exit 1; }
@command -v $(LLVM_STRIP) >/dev/null 2>&1 || { echo "Error: llvm-strip not found. Install llvm toolchain."; exit 1; }
@echo "Dependencies OK"
# Create output directory
$(OUTPUT):
mkdir -p $(OUTPUT)
# Generate vmlinux.h from BTF
$(VMLINUX_H): | $(OUTPUT)
@echo "Generating vmlinux.h from kernel BTF..."
$(BPFTOOL) btf dump file /sys/kernel/btf/vmlinux format c > $@
# Compile BPF program
$(BPF_OBJ): $(BPF_SRC) $(VMLINUX_H) $(HEADER) | $(OUTPUT)
@echo "Compiling BPF program: $<"
$(CLANG) $(BPF_CFLAGS) -c $(BPF_SRC) -o $@
$(LLVM_STRIP) -g $@
# Generate BPF skeleton
$(SKEL_H): $(BPF_OBJ)
@echo "Generating BPF skeleton: $@"
$(BPFTOOL) gen skeleton $< > $@
# Compile user-space program
$(USER_OBJ): $(USER_SRC) $(SKEL_H) $(HEADER) | $(OUTPUT)
@echo "Compiling user-space program: $<"
$(CLANG) $(CFLAGS) $(INCLUDES) -c $(USER_SRC) -o $@
# Link final binary
$(BINARY): $(USER_OBJ)
@echo "Linking binary: $@"
$(CLANG) $(CFLAGS) $< -o $@ $(LIBS)
@echo "Build complete: $@"
# Install to system
install: $(BINARY)
@echo "Installing $(APP)..."
install -D -m 0755 $(BINARY) /usr/local/bin/$(APP)
install -D -m 0644 deploy/systemd/$(APP).service /etc/systemd/system/$(APP).service
@echo "Installation complete. Enable with: systemctl enable $(APP)"
# Uninstall from system
uninstall:
@echo "Uninstalling $(APP)..."
systemctl stop $(APP) 2>/dev/null || true
systemctl disable $(APP) 2>/dev/null || true
rm -f /usr/local/bin/$(APP)
rm -f /etc/systemd/system/$(APP).service
systemctl daemon-reload
@echo "Uninstallation complete"
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
rm -rf $(OUTPUT)
# Run the monitor (requires root)
run: $(BINARY)
@echo "Running $(APP) (requires root)..."
sudo $(BINARY) -v
# Run with full monitoring
run-full: $(BINARY)
@echo "Running $(APP) with full monitoring (requires root)..."
sudo $(BINARY) -f -s -v -j