forked from cilium/cilium
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.defs
More file actions
293 lines (237 loc) · 9.74 KB
/
Makefile.defs
File metadata and controls
293 lines (237 loc) · 9.74 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Copyright Authors of Cilium
# SPDX-License-Identifier: Apache-2.0
SHELL := /usr/bin/env bash
.SHELLFLAGS := -eu -o pipefail -c
# define a function replacing spaces with commas in a list
empty :=
space := $(empty) $(empty)
comma := ,
join-with-comma = $(subst $(space),$(comma),$(strip $1))
define newline
endef
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
RELATIVE_DIR := $(shell echo $(realpath .) | sed "s;$(ROOT_DIR)[/]*;;")
include $(ROOT_DIR)/Makefile.quiet
PREFIX?=/usr
BINDIR?=$(PREFIX)/bin
CNIBINDIR?=/opt/cni/bin
CNICONFDIR?=/etc/cni/net.d
LIBDIR?=$(PREFIX)/lib
LOCALSTATEDIR?=/var
RUNDIR?=/var/run
CONFDIR?=/etc
CILIUM_BUILD_DIR?=.
export GO ?= go
NATIVE_ARCH = $(shell GOARCH= $(GO) env GOARCH)
export GOARCH ?= $(NATIVE_ARCH)
INSTALL = install
CONTAINER_ENGINE?=docker
DOCKER_FLAGS?=
DOCKER_BUILD_FLAGS?=
# use gsed if available, otherwise use sed.
# gsed is needed for MacOS to make in-place replacement work correctly.
SED ?= $(if $(shell command -v gsed),gsed,sed)
# Set DOCKER_DEV_ACCOUNT with "cilium" by default
ifeq ($(DOCKER_DEV_ACCOUNT),)
DOCKER_DEV_ACCOUNT=cilium
endif
ifneq ($(CI_BUILD),)
DOCKER_IMAGE_SUFFIX=-ci
DOCKER_IMAGE_TAG=$(shell git rev-parse HEAD)
endif
# Set DOCKER_IMAGE_TAG with "latest" by default
ifeq ($(DOCKER_IMAGE_TAG),)
DOCKER_IMAGE_TAG=latest
endif
# renovate: datasource=docker depName=gcr.io/etcd-development/etcd
ETCD_IMAGE_VERSION = v3.6.8
ETCD_IMAGE_SHA = sha256:397189418d1a00e500c0605ad18d1baf3b541a1004d768448c367e48071622e5
ETCD_IMAGE=gcr.io/etcd-development/etcd:$(ETCD_IMAGE_VERSION)@$(ETCD_IMAGE_SHA)
export CILIUM_CLI ?= cilium
export KUBECTL ?= kubectl
# renovate: datasource=docker depName=quay.io/goswagger/swagger
SWAGGER_VERSION = 0.33.1
SWAGGER_IMAGE_SHA = sha256:03e351c87e7bf5de41b120aec97f0a2255f90a1cd802162ad1947f9e2de9e778
SWAGGER := $(CONTAINER_ENGINE) run -u $(shell id -u):$(shell id -g) --rm -v $(ROOT_DIR):$(ROOT_DIR) -w $(ROOT_DIR) --entrypoint swagger quay.io/goswagger/swagger:$(SWAGGER_VERSION)@$(SWAGGER_IMAGE_SHA)
# go build/test/clean flags
# these are declared here so they are treated explicitly
# as non-immediate variables
GO_BUILD_FLAGS ?=
GO_TEST_FLAGS ?=
GO_TEST_OUT ?= /dev/null
GO_CLEAN_FLAGS ?=
GO_BUILD_LDFLAGS ?=
# go build/test -tags values
GO_TAGS_FLAGS += osusergo
# This is declared here as it is needed to change the covermode depending on if
# RACE is specified.
GOTEST_COVER_OPTS =
CODEOWNERS_PATH_EVAL := $(shell echo $(wildcard $(ROOT_DIR)/*OWNERS*) | tr ' ' ',')
CODEOWNERS_PATH ?= "$(CODEOWNERS_PATH_EVAL)"
# By default, just print go test output immediately to the terminal. If tparse
# is installed, use it to format the output. Use -progress instead of -follow,
# as the latter is too verbose for most of the test suite.
GOTEST_FORMATTER ?= cat
ifneq ($(shell command -v tparse),)
GOTEST_FORMATTER_FLAGS :=
ifneq ($(V),0)
GOTEST_FORMATTER_FLAGS += -follow
endif
ifneq ($(LOG_CODEOWNERS),)
ifneq ($(shell command -v go-junit-report),)
JUNIT_PATH ?= junit_results.xml
GOTEST_FORMATTER = tee \
>(go-junit-report -parser gojson \
-code-owners=$(CODEOWNERS_PATH) \
-code-owners-prefix github.com/cilium/cilium/ \
-out "$(JUNIT_PATH)") \
>($(GO) run $(ROOT_DIR)/tools/testowners \
--code-owners=$(CODEOWNERS_PATH)) \
>(tparse $(GOTEST_FORMATTER_FLAGS)) \
>$(GO_TEST_OUT) \
| cat
else
GOTEST_FORMATTER = tee \
>($(GO) run $(ROOT_DIR)/tools/testowners \
--code-owners=$(CODEOWNERS_PATH)) \
>(tparse $(GOTEST_FORMATTER_FLAGS)) \
>$(GO_TEST_OUT) \
| cat
endif
else
GOTEST_FORMATTER = tparse $(GOTEST_FORMATTER_FLAGS)
endif
endif
ifneq ($(GOTEST_FORMATTER),cat)
GO_TEST_FLAGS += -json
endif
# renovate: datasource=docker depName=golangci/golangci-lint
GOLANGCILINT_WANT_VERSION = v2.11.3
GOLANGCILINT_IMAGE_SHA = sha256:e838e8ab68aaefe83e2408691510867ade9329c0e0b895a3fb35eb93d1c2a4ba
GOLANGCILINT_VERSION = $(shell golangci-lint version --short 2>/dev/null)
VERSION = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION)
VERSION_MAJOR = $(shell cat $(dir $(lastword $(MAKEFILE_LIST)))/VERSION | cut -d. -f1)
# Use git only if in a Git repo
ifneq ($(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/.git/HEAD),)
GIT_VERSION = $(shell git show -s --format='format:%h %aI')
else
GIT_VERSION = $(shell cat 2>/dev/null $(ROOT_DIR)/GIT_VERSION)
endif
FULL_BUILD_VERSION = $(VERSION) $(GIT_VERSION)
GO_BUILD_LDFLAGS += -X "github.com/cilium/cilium/pkg/version.ciliumVersion=$(FULL_BUILD_VERSION)"
ifeq ($(NOSTRIP),)
# Note: these options will not remove annotations needed for stack
# traces, so panic backtraces will still be readable.
#
# -w: Omit the DWARF symbol table.
# -s: Omit the symbol table and debug information.
GO_BUILD_LDFLAGS += -s -w
endif
ifneq ($(wildcard $(ROOT_DIR)/images/cilium/Dockerfile),)
CILIUM_DOCKERFILE := $(ROOT_DIR)/images/cilium/Dockerfile
# Reading img ref from images/cilium/Dockerfile ARG value
get_cilium_ref = $(shell sed -nE 's/^ARG $(1)=([^ ]*)/\1/p' $(CILIUM_DOCKERFILE) | head -n1)
# Replacing quay.io registry if BASE_IMAGE_REGISTRY env is set
replace_registry = $(strip $(if $(strip $(BASE_IMAGE_REGISTRY)), \
$(subst quay.io,$(strip $(BASE_IMAGE_REGISTRY)),$(1)), \
$(1) \
))
CILIUM_BUILDER_REF := $(strip $(call get_cilium_ref,CILIUM_BUILDER_IMAGE))
CILIUM_RUNTIME_REF := $(strip $(call get_cilium_ref,CILIUM_RUNTIME_IMAGE))
CILIUM_ENVOY_REF := $(strip $(call get_cilium_ref,CILIUM_ENVOY_IMAGE))
CILIUM_BUILDER_IMAGE ?= $(call replace_registry,$(CILIUM_BUILDER_REF))
CILIUM_RUNTIME_IMAGE ?= $(call replace_registry,$(CILIUM_RUNTIME_REF))
CILIUM_ENVOY_IMAGE ?= $(call replace_registry,$(CILIUM_ENVOY_REF))
CILIUM_ENVOY_SHA := $(shell echo $(CILIUM_ENVOY_REF) | sed -E 's/[^/]*\/[^:]*:(.*-)?([^:@]*).*/\2/p;d')
GO_BUILD_LDFLAGS += -X "github.com/cilium/cilium/pkg/envoy.requiredEnvoyVersionSHA=$(CILIUM_ENVOY_SHA)"
ifneq ($(strip $(BASE_IMAGE_REGISTRY)),)
DOCKER_BUILD_FLAGS += --build-arg CILIUM_BUILDER_IMAGE=$(CILIUM_BUILDER_IMAGE)
DOCKER_BUILD_FLAGS += --build-arg CILIUM_RUNTIME_IMAGE=$(CILIUM_RUNTIME_IMAGE)
DOCKER_BUILD_FLAGS += --build-arg CILIUM_ENVOY_IMAGE=$(CILIUM_ENVOY_IMAGE)
endif
endif
# Use git only if in a Git repo, otherwise find the files from the file system
BPF_SRCFILES_IGNORE = bpf/.gitignore bpf/tests/% bpf/complexity-tests/% bpf/custom/% bpf/Makefile bpf/Makefile.bpf
ifneq ($(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/.git/HEAD),)
BPF_SRCFILES := $(shell git ls-files $(ROOT_DIR)/bpf/ | LC_ALL=C sort | tr "\n" ' ')
else
# this line has to be in-sync with bpf/.gitignore, please note usage of make patterns like `%.i`
BPF_SRCFILES_IGNORE += bpf/%.i bpf/%.s bpf/.rebuild_all
BPF_SRCFILES := $(shell find $(ROOT_DIR)/bpf/ -type f | LC_ALL=C sort | tr "\n" ' ')
endif
# ROOT_DIR can be either `../` or absolute path, each of these need to be stripped
BPF_SRCFILES := $(filter-out $(BPF_SRCFILES_IGNORE),$(subst ../,,$(subst $(ROOT_DIR)/,,$(BPF_SRCFILES))))
GO_BUILD_FLAGS += -mod=vendor
GO_TEST_FLAGS += -mod=vendor -vet=all
GO_CLEAN_FLAGS += -mod=vendor
CGO_ENABLED ?= 0
# See https://pkg.go.dev/internal/goexperiment
GOEXPERIMENT ?=
# Support CGO cross-compiling for amd64 and arm64 targets
GO_BUILD_ENV = CGO_ENABLED=$(CGO_ENABLED)
CROSS_ARCH =
ifneq ($(GOARCH),$(NATIVE_ARCH))
CROSS_ARCH = $(GOARCH)
endif
ifeq ($(CROSS_ARCH),arm64)
GO_BUILD_ENV += CC=aarch64-linux-gnu-gcc
else ifeq ($(CROSS_ARCH),amd64)
GO_BUILD_ENV += CC=x86_64-linux-gnu-gcc
endif
ifneq ($(GOARCH),)
GO_BUILD_ENV += GOARCH=$(GOARCH)
endif
ifneq ($(GOOS),)
GO_BUILD_ENV += GOOS=$(GOOS)
endif
ifneq ($(GOEXPERIMENT),)
GO_BUILD_ENV += GOEXPERIMENT=$(GOEXPERIMENT)
endif
ifneq ($(RACE),)
GO_BUILD_FLAGS += -race
GO_TEST_FLAGS += -race
GOTEST_COVER_OPTS += -covermode=atomic
# `-race` requires CGO
CGO_ENABLED = 1
ifeq ($(LOCKDEBUG),)
LOCKDEBUG=1
endif
else
GOTEST_COVER_OPTS += -covermode=count
endif
ifneq ($(LOCKDEBUG),)
GO_TAGS_FLAGS += lockdebug
endif
ifneq ($(findstring boringcrypto,$(GOEXPERIMENT)),)
CGO_ENABLED = 1
GO_BUILD_LDFLAGS += -linkmode external -extldflags "-static --enable-static-nss"
endif
GO_BUILD_FLAGS += -ldflags '$(GO_BUILD_LDFLAGS) $(EXTRA_GO_BUILD_LDFLAGS)' -tags=$(call join-with-comma,$(GO_TAGS_FLAGS)) $(EXTRA_GO_BUILD_FLAGS)
GO_TEST_FLAGS += -tags=$(call join-with-comma,$(GO_TAGS_FLAGS))
ifeq ($(NOOPT),1)
GO_BUILD_FLAGS += -gcflags="all=-N -l"
endif
GO_BUILD = $(GO_BUILD_ENV) $(GO) build $(GO_BUILD_FLAGS)
GO_TEST = CGO_ENABLED=0 $(GO) test $(GO_TEST_FLAGS)
GO_CLEAN = $(GO) clean $(GO_CLEAN_FLAGS)
GO_VET = $(GO) vet
GO_LIST = $(GO) list
HELM_TOOLBOX_VERSION ?= "v1.1.0"
HELM_TOOLBOX_SHA ?= "961693f182b9b456ed90e5274ac5df81e4af4343104e252666959cdf9570ce9e"
HELM_TOOLBOX_IMAGE ?= "quay.io/cilium/helm-toolbox:$(HELM_TOOLBOX_VERSION)@sha256:$(HELM_TOOLBOX_SHA)"
YQ_VERSION ?= "4.40.5"
YQ_SHA ?= "32be61dc94d0acc44f513ba69d0fc05f1f92c2e760491f2a27e11fc13cde6327"
YQ_IMAGE ?= "docker.io/mikefarah/yq:$(YQ_VERSION)@sha256:$(YQ_SHA)"
define print_help_line
@printf " \033[36m%-29s\033[0m %s.\n" $(1) $(2)
endef
define print_help_from_makefile
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9][a-zA-Z0-9 _-]*:.*?##/ { split($$1, targets, " "); for (i in targets) { printf " \033[36m%-28s\033[0m %s\n", targets[i], $$2 } } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
endef
# Use to ensure the CWD, or any child of it, belongs to Cilium's go module.
CILIUM_GO_MODULE = github.com/cilium/cilium
CURRENT_GO_MODULE = $(shell go list -m)
define ASSERT_CILIUM_MODULE
$(if $(filter $(CILIUM_GO_MODULE), $(CURRENT_GO_MODULE)) ,, $(error "Could not locate Cilium's go.mod file, are you in Cilium's repository?"))
endef
RENOVATE_GITHUB_COM_TOKEN ?= $(shell gh auth token)