-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
95 lines (77 loc) · 1.98 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
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
# SPDX-FileCopyrightText: 2024 Tobias Böhm <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
MAKEFLAGS := --no-builtin-rules
.ONESHELL:
BIN_DIR ?= bin
BPF_PACKAGE_DIR := ./internal/bpf
BINARY ?= $(BIN_DIR)/exceed2go
PIDONETEST_KERNEL ?= test-kernel
GOBIN := $(shell realpath ./gobin)
VIRTRUN := $(GOBIN)/virtrun
BPF2GO := $(GOBIN)/bpf2go
STRINGER := $(GOBIN)/stringer
LIBBPF ?= bpf/libbpf
BPF_SRC_FILE := bpf/exceed2go.c
BPF2GO_FILE := $(BPF_PACKAGE_DIR)/exceed2go_bpfel.go
CC = clang
CFLAGS := -O2 -g -v \
-Wall -Werror -Wshadow \
-nostdinc -mcpu=v3 \
-I$(shell realpath $(LIBBPF)) \
$(CFLAGS)
export CGO_ENABLED := 0
export GOBIN
build: $(BINARY)
bpf: $(BPF2GO_FILE)
$(VIRTRUN): go.mod
go install github.com/aibor/virtrun
$(BPF2GO): go.mod
go install github.com/cilium/ebpf/cmd/bpf2go
$(STRINGER): go.mod
go install golang.org/x/tools/cmd/stringer
$(BINARY): $(shell find . -name '*.go' ! -name '*_test.go') $(BPF2GO_FILE)
go build -o "$@"
$(BPF2GO_FILE): $(BPF2GO) $(STRINGER) $(BPF_SRC_FILE) $(LIBBPF)/*.h Makefile
cd $(@D)
GOPACKAGE=bpf $(BPF2GO) \
-cc $(CC) \
-target bpfel \
-cflags "$(CFLAGS)" \
-no-strip \
Exceed2Go $(shell realpath $(BPF_SRC_FILE))
llvm-objdump \
--source \
--no-show-raw-insn \
-g \
$(patsubst %.go,%.o,$(@F)) \
> $(patsubst %.go,%.dump,$(@F))
$(STRINGER) \
-type Exceed2GoCounterKey \
-trimprefix Exceed2GoCounterKeyCOUNTER_ \
-output exceed2go_counter_key_string.go \
exceed2go_bpfel.go
.PHONY: pidonetest
pidonetest: $(BPF2GO_FILE) $(VIRTRUN)
CGO_ENABLED=1 go test \
-exec "$(VIRTRUN) \
-kernel $$(realpath $(PIDONETEST_KERNEL))" \
-v \
-race \
-coverpkg $$(go list ./... | tr '\n' ,) \
-cover \
-covermode atomic \
-coverprofile /tmp/cover.out \
$(PIDONETEST_FLAGS) \
./...
.PHONY: clean
clean:
@rm -frv \
$(BINARY)
.PHONY: cleangen
cleangen:
@rm -frv \
$(BPF2GO_FILE) \
$(patsubst %.go,%.dump,$(BPF2GO_FILE)) \
$(patsubst %.go,%.o,$(BPF2GO_FILE)) \
$(BPF_PACKAGE_DIR)/*_string.go