forked from open-telemetry/opentelemetry-ebpf-profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
90 lines (67 loc) · 1.79 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
SHELL ?= bash
BPF_CLANG ?= clang-16
BPF_LINK ?= llvm-link-16
LLC ?= llc-16
DEBUG_FLAGS = -DOPTI_DEBUG -g
# Detect native architecture and translate to GOARCH.
NATIVE_ARCH := $(shell uname -m)
ifeq ($(NATIVE_ARCH),x86_64)
NATIVE_ARCH := amd64
else ifneq (,$(filter $(NATIVE_ARCH),aarch64 arm64))
NATIVE_ARCH := arm64
else
$(error Unsupported architecture: $(NATIVE_ARCH))
endif
# Valid values: amd64, arm64.
TARGET_ARCH ?= $(NATIVE_ARCH)
# Valid values: release, debug
BUILD_TYPE ?= release
TRACER_NAME ?= tracer.ebpf.$(BUILD_TYPE).$(TARGET_ARCH)
ifeq ($(TARGET_ARCH),arm64)
TARGET_FLAGS = -target aarch64-linux-gnu
else
TARGET_FLAGS = -target x86_64-linux-gnu
endif
ifeq ($(BUILD_TYPE),debug)
TARGET_FLAGS+=$(DEBUG_FLAGS)
endif
FLAGS=$(TARGET_FLAGS) \
-fno-jump-tables \
-nostdlib \
-nostdinc \
-ffreestanding \
-O2 -emit-llvm -c $< \
-Wall -Wextra -Werror \
-Wno-address-of-packed-member \
-Wno-unused-label \
-Wno-unused-parameter \
-Wno-sign-compare \
-fno-stack-protector
SRCS := $(wildcard *.ebpf.c)
OBJS := $(SRCS:.c=.$(BUILD_TYPE).$(TARGET_ARCH).o)
.DEFAULT_GOAL := all
all: $(TRACER_NAME)
debug:
$(MAKE) BUILD_TYPE=debug
amd64:
$(MAKE) TARGET_ARCH=amd64
arm64:
$(MAKE) TARGET_ARCH=arm64
debug-amd64:
$(MAKE) BUILD_TYPE=debug TARGET_ARCH=amd64
debug-arm64:
$(MAKE) BUILD_TYPE=debug TARGET_ARCH=arm64
errors.h: ../../tools/errors-codegen/errors.json
go run ../../tools/errors-codegen/main.go bpf $@
%.ebpf.c: errors.h ;
%.ebpf.$(BUILD_TYPE).$(TARGET_ARCH).o: %.ebpf.c
$(BPF_CLANG) $(FLAGS) -o $@
$(TRACER_NAME): $(OBJS)
$(BPF_LINK) $^ -o - | $(LLC) -march=bpf -mcpu=v2 -filetype=obj -o $@
@./print_instruction_count.sh $@
baseline: $(TRACER_NAME)
cp $< $(TRACER_NAME).$@
bloatcheck: $(TRACER_NAME)
python3 bloat-o-meter $(TRACER_NAME).baseline $(TRACER_NAME)
clean:
rm -f *.o