-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (158 loc) · 5.96 KB
/
Makefile
File metadata and controls
180 lines (158 loc) · 5.96 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright (c) 2022-2025, daeuniverse Organization <dae@v2raya.org>
#
# The development version of clang is distributed as the 'clang' binary,
# while stable/released versions have a version number attached.
# Pin the default clang to a stable version.
CLANG ?= clang
STRIP ?= llvm-strip
CFLAGS := -O2 -Wall -Werror $(CFLAGS)
TARGET ?= bpfel,bpfeb
OUTPUT ?= dae
MAX_MATCH_SET_LEN ?= 1024
CFLAGS := -DMAX_MATCH_SET_LEN=$(MAX_MATCH_SET_LEN) $(CFLAGS)
DEFAULT_GOEXPERIMENT := heapminimum512kib,randomizedheapbase64
GOEXPERIMENT_MERGED := $(shell printf '%s\n' "$(DEFAULT_GOEXPERIMENT),$(GOEXPERIMENT)" | tr ',' '\n' | sed '/^$$/d' | awk '!seen[$$0]++' | paste -sd, -)
export GOEXPERIMENT := $(GOEXPERIMENT_MERGED)
NOSTRIP ?= n
STRIP_PATH := $(shell command -v $(STRIP) 2>/dev/null)
BUILD_TAGS_FILE := .build_tags
ifeq ($(strip $(NOSTRIP)),y)
STRIP_FLAG := -no-strip
else ifeq ($(wildcard $(STRIP_PATH)),)
STRIP_FLAG := -no-strip
else
STRIP_FLAG := -strip=$(STRIP_PATH)
endif
GOARCH ?= $(shell go env GOARCH)
# Do NOT remove the line below. This line is for CI.
#export GOMODCACHE=$(PWD)/go-mod
# Get version from .git.
date=$(shell git log -1 --format="%cd" --date=short | sed s/-//g)
count=$(shell git rev-list --count HEAD)
commit=$(shell git rev-parse --short HEAD)
ifeq ($(wildcard .git/.),)
VERSION ?= unstable-0.nogit
else
VERSION ?= unstable-$(date).r$(count).$(commit)
endif
BUILD_ARGS := -trimpath -ldflags "-s -w -X github.com/daeuniverse/dae/cmd.Version=$(VERSION) -X github.com/daeuniverse/dae/common/consts.MaxMatchSetLen_=$(MAX_MATCH_SET_LEN)" $(BUILD_ARGS)
.PHONY: clean-ebpf ebpf ebpf-sync ebpf-sync-check ebpf-test-tagged ebpf-test-debug ebpf-test-debug-tagged ebpf-audit dae submodule submodules
## Begin Dae Build
dae: export GOOS=linux
ifndef CGO_ENABLED
dae: export CGO_ENABLED=0
endif
dae: ebpf
@echo $(CFLAGS)
go build -tags=$(shell cat $(BUILD_TAGS_FILE)) -o $(OUTPUT) $(BUILD_ARGS) .
## End Dae Build
## Begin Git Submodules
.gitmodules.d.mk: .gitmodules
@set -e && \
submodules=$$(grep '\[submodule "' .gitmodules | cut -d'"' -f2 | tr '\n' ' ' | tr ' \n' '\n') && \
echo "submodule_paths=$${submodules}" > $@
-include .gitmodules.d.mk
$(submodule_paths): .gitmodules.d.mk
git submodule update --init --recursive -- $@ && \
touch $@
submodule submodules: $(submodule_paths)
@if [ -z "$(submodule_paths)" ]; then \
rm -f .gitmodules.d.mk; \
echo "Failed to generate submodules list. Please try again."; \
exit 1; \
fi
## End Git Submodules
## Begin Ebpf
clean-ebpf:
@rm -f control/bpf_bpf*.go && \
rm -f control/bpf_bpf*.o
@rm -f trace/bpf_bpf*.go && \
rm -f trace/bpf_bpf*.o
@rm -f control/kern/tests/bpftest_bpf*.go && \
rm -f control/kern/tests/bpftest_bpf*.o
fmt:
go fmt ./...
ebpf-sync:
@unset GOOS && \
unset GOARCH && \
unset GOARM && \
unset GOAMD64 && \
go generate ./common/consts/ebpf.go
ebpf-sync-check: ebpf-sync
git diff --exit-code -- common/consts/ebpf_generated.go control/kern/ebpf_sync_defs.h
# $BPF_CLANG is used in go:generate invocations.
ebpf: export BPF_CLANG := $(CLANG)
ebpf: export BPF_STRIP_FLAG := $(STRIP_FLAG)
ebpf: export BPF_CFLAGS := $(CFLAGS)
ebpf: export BPF_TARGET := $(TARGET)
ebpf: export BPF_TRACE_TARGET := $(GOARCH)
ebpf: ebpf-sync submodule clean-ebpf
@unset GOOS && \
unset GOARCH && \
unset GOARM && \
echo $(STRIP_FLAG) && \
go generate ./control/control.go && \
if go generate ./trace/trace.go; then \
echo trace > $(BUILD_TAGS_FILE); \
else \
echo > $(BUILD_TAGS_FILE); \
fi
ebpf-lint:
./scripts/checkpatch.pl --no-tree --strict --no-summary --show-types --color=always control/kern/tproxy.c --ignore COMMIT_COMMENT_SYMBOL,NOT_UNIFIED_DIFF,COMMIT_LOG_LONG_LINE,LONG_LINE_COMMENT,VOLATILE,ASSIGN_IN_IF,PREFER_DEFINED_ATTRIBUTE_MACRO,CAMELCASE,LEADING_SPACE,OPEN_ENDED_LINE,SPACING,BLOCK_COMMENT_STYLE
ebpf-test: export BPF_CLANG := $(CLANG)
ebpf-test: export BPF_STRIP_FLAG := $(STRIP_FLAG)
ebpf-test: export BPF_CFLAGS := $(CFLAGS)
ebpf-test: export BPF_TARGET := $(TARGET)
ebpf-test: export BPF_TRACE_TARGET := $(GOARCH)
ebpf-test: ebpf-sync submodule clean-ebpf
@unset GOOS && \
unset GOARCH && \
unset GOARM && \
echo $(STRIP_FLAG) && \
go generate ./control/kern/tests/bpf_test.go && \
go clean -testcache && \
go test -v ./control/kern/tests/...
ebpf-test-tagged: export BPF_CLANG := $(CLANG)
ebpf-test-tagged: export BPF_STRIP_FLAG := $(STRIP_FLAG)
ebpf-test-tagged: export BPF_CFLAGS := $(CFLAGS)
ebpf-test-tagged: export BPF_TARGET := $(TARGET)
ebpf-test-tagged: export BPF_TRACE_TARGET := $(GOARCH)
ebpf-test-tagged: ebpf-sync submodule clean-ebpf
@unset GOOS && \
unset GOARCH && \
unset GOARM && \
echo $(STRIP_FLAG) && \
go generate ./control/kern/tests/bpf_test.go && \
go clean -testcache && \
go test -v -tags dae_bpf_tests ./control/kern/tests/...
ebpf-test-debug: export BPF_CLANG := $(CLANG)
ebpf-test-debug: export BPF_STRIP_FLAG := $(STRIP_FLAG)
ebpf-test-debug: export BPF_CFLAGS := $(CFLAGS) -D__BPF_TEST_ENABLE_DEBUG
ebpf-test-debug: export BPF_TARGET := $(TARGET)
ebpf-test-debug: export BPF_TRACE_TARGET := $(GOARCH)
ebpf-test-debug: ebpf-sync submodule clean-ebpf
@unset GOOS && \
unset GOARCH && \
unset GOARM && \
echo $(STRIP_FLAG) && \
go generate ./control/kern/tests/bpf_test.go && \
go clean -testcache && \
go test -v ./control/kern/tests/...
ebpf-test-debug-tagged: export BPF_CLANG := $(CLANG)
ebpf-test-debug-tagged: export BPF_STRIP_FLAG := $(STRIP_FLAG)
ebpf-test-debug-tagged: export BPF_CFLAGS := $(CFLAGS) -D__BPF_TEST_ENABLE_DEBUG
ebpf-test-debug-tagged: export BPF_TARGET := $(TARGET)
ebpf-test-debug-tagged: export BPF_TRACE_TARGET := $(GOARCH)
ebpf-test-debug-tagged: ebpf-sync submodule clean-ebpf
@unset GOOS && \
unset GOARCH && \
unset GOARM && \
echo $(STRIP_FLAG) && \
go generate ./control/kern/tests/bpf_test.go && \
go clean -testcache && \
go test -v -tags dae_bpf_tests ./control/kern/tests/...
ebpf-audit:
./scripts/ebpf-audit.sh
## End Ebpf