-
Notifications
You must be signed in to change notification settings - Fork 302
/
Copy pathMakefile
157 lines (122 loc) · 4.57 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
.PHONY: all all-common clean ebpf generate test test-deps protobuf docker-image agent legal \
integration-test-binaries codespell lint linter-version debug debug-agent ebpf-profiler \
format-ebpf rust-components rust-targets rust-tests vanity-import-check vanity-import-fix
SHELL := /usr/bin/env bash
# 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 are: amd64, arm64.
TARGET_ARCH ?= $(NATIVE_ARCH)
ifeq ($(NATIVE_ARCH),$(TARGET_ARCH))
ARCH_PREFIX :=
else ifeq ($(TARGET_ARCH),arm64)
ARCH_PREFIX := aarch64-linux-gnu-
else ifeq ($(TARGET_ARCH),amd64)
ARCH_PREFIX := x86_64-linux-gnu-
else
$(error Unsupported architecture: $(TARGET_ARCH))
endif
export TARGET_ARCH
export CGO_ENABLED = 1
export GOARCH = $(TARGET_ARCH)
export CC = $(ARCH_PREFIX)gcc
export OBJCOPY = $(ARCH_PREFIX)objcopy
BRANCH = $(shell git rev-parse --abbrev-ref HEAD | tr -d '-' | tr '[:upper:]' '[:lower:]')
COMMIT_SHORT_SHA = $(shell git rev-parse --short=8 HEAD)
VERSION ?= v0.0.0
BUILD_TIMESTAMP ?= $(shell date +%s)
REVISION ?= $(BRANCH)-$(COMMIT_SHORT_SHA)
LDFLAGS := -X go.opentelemetry.io/ebpf-profiler/vc.version=$(VERSION) \
-X go.opentelemetry.io/ebpf-profiler/vc.revision=$(REVISION) \
-X go.opentelemetry.io/ebpf-profiler/vc.buildTimestamp=$(BUILD_TIMESTAMP) \
-extldflags=-static
GO_TAGS := osusergo,netgo
EBPF_FLAGS :=
GO_FLAGS := -buildvcs=false -ldflags="$(LDFLAGS)"
MAKEFLAGS += -j$(shell nproc)
all: ebpf-profiler
debug: GO_TAGS := $(GO_TAGS),debugtracer
debug: EBPF_FLAGS += debug
debug: all
# Removes the go build cache and binaries in the current project
clean:
@go clean -cache -i
@$(MAKE) -s -C support/ebpf clean
@rm -f support/*.test
@chmod -Rf u+w go/ || true
@rm -rf go .cache
@cargo clean
generate:
GOARCH=$(NATIVE_ARCH) go generate ./...
(cd support && ./generate.sh)
ebpf: generate
$(MAKE) $(EBPF_FLAGS) -C support/ebpf
ebpf-profiler: generate ebpf rust-components
go build $(GO_FLAGS) -tags $(GO_TAGS)
rust-targets:
ifeq ($(TARGET_ARCH),arm64)
rustup target add aarch64-unknown-linux-musl
else ifeq ($(TARGET_ARCH),amd64)
rustup target add x86_64-unknown-linux-musl
endif
rust-components: rust-targets
ifeq ($(TARGET_ARCH),arm64)
cargo build --lib --release --target aarch64-unknown-linux-musl
else ifeq ($(TARGET_ARCH),amd64)
cargo build --lib --release --target x86_64-unknown-linux-musl
endif
rust-tests: rust-targets
cargo test
GOLANGCI_LINT_VERSION = "v1.64.5"
lint: generate vanity-import-check
$(MAKE) lint -C support/ebpf
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) version
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run
format-ebpf:
$(MAKE) format -C support/ebpf
linter-version:
@echo $(GOLANGCI_LINT_VERSION)
vanity-import-check:
@go install github.com/jcchavezs/porto/cmd/porto@latest
@porto --include-internal -l . || ( echo "(run: make vanity-import-fix)"; exit 1 )
vanity-import-fix: $(PORTO)
@go install github.com/jcchavezs/porto/cmd/porto@latest
@porto --include-internal -w .
test: generate ebpf test-deps
go test $(GO_FLAGS) -tags $(GO_TAGS) ./...
TESTDATA_DIRS:= \
nativeunwind/elfunwindinfo/testdata \
libpf/pfelf/testdata \
reporter/testdata
test-deps:
$(foreach testdata_dir, $(TESTDATA_DIRS), \
($(MAKE) -C "$(testdata_dir)") || exit ; \
)
TEST_INTEGRATION_BINARY_DIRS := tracer processmanager/ebpf support
integration-test-binaries: generate ebpf
$(foreach test_name, $(TEST_INTEGRATION_BINARY_DIRS), \
(go test -ldflags='-extldflags=-static' -trimpath -c \
-tags $(GO_TAGS),static_build,integration \
-o ./support/$(subst /,_,$(test_name)).test \
./$(test_name)) || exit ; \
)
docker-image:
docker build -t otel/opentelemetry-ebpf-profiler-dev -f Dockerfile .
agent:
docker run -v "$$PWD":/agent -it --rm --user $(shell id -u):$(shell id -g) otel/opentelemetry-ebpf-profiler-dev:latest \
"make TARGET_ARCH=$(TARGET_ARCH) VERSION=$(VERSION) REVISION=$(REVISION) BUILD_TIMESTAMP=$(BUILD_TIMESTAMP)"
debug-agent:
docker run -v "$$PWD":/agent -it --rm --user $(shell id -u):$(shell id -g) otel/opentelemetry-ebpf-profiler-dev:latest \
"make TARGET_ARCH=$(TARGET_ARCH) VERSION=$(VERSION) REVISION=$(REVISION) BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) debug"
legal:
@go install github.com/google/go-licenses@latest
@go-licenses save --force . --save_path=LICENSES
@./legal/add-non-go.sh legal/non-go-dependencies.json LICENSES
codespell:
@codespell