forked from cilium/cilium-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
113 lines (97 loc) · 3.37 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
# Copyright Authors of Cilium
# SPDX-License-Identifier: Apache-2.0
GO := go
GO_BUILD = CGO_ENABLED=0 $(GO) build
GO_TAGS ?=
TARGET=cilium
INSTALL = $(QUIET)install
BINDIR ?= /usr/local/bin
CILIUM_VERSION=$(shell curl -s https://raw.githubusercontent.com/cilium/cilium/main/stable.txt)
CLI_VERSION=$(shell git describe --tags --always)
STRIP_DEBUG=-w -s
ifdef DEBUG
STRIP_DEBUG=
endif
GO_BUILD_LDFLAGS ?= $(STRIP_DEBUG) \
-X 'github.com/cilium/cilium/cilium-cli/defaults.CLIVersion=$(CLI_VERSION)' \
-X 'github.com/cilium/cilium/cilium-cli/defaults.Version=$(CILIUM_VERSION)'
TEST_TIMEOUT ?= 5s
RELEASE_UID ?= $(shell id -u)
RELEASE_GID ?= $(shell id -g)
# renovate: datasource=docker depName=golang
GO_IMAGE_VERSION = 1.23.3-alpine3.19
GO_IMAGE_SHA = sha256:36cc30986d1f9bc46670526fe6553b078097e562e196344dea6a075e434f8341
# renovate: datasource=docker depName=golangci/golangci-lint
GOLANGCILINT_WANT_VERSION = v1.62.0
GOLANGCILINT_IMAGE_SHA = sha256:a546859900cfd8599b993017e148e5ecf3f87a53de560549338b3422f8413209
GOLANGCILINT_VERSION = $(shell golangci-lint version --format short 2>/dev/null)
$(TARGET):
$(GO_BUILD) $(if $(GO_TAGS),-tags $(GO_TAGS)) \
-ldflags "$(GO_BUILD_LDFLAGS)" \
-o $(TARGET) \
./cmd/cilium
release:
docker run \
--rm \
--workdir /cilium \
--volume `pwd`:/cilium docker.io/library/golang:$(GO_IMAGE_VERSION)@$(GO_IMAGE_SHA) \
sh -c "apk add --no-cache curl setpriv make git zip && \
/usr/bin/setpriv --reuid=$(RELEASE_UID) --regid=$(RELEASE_GID) --clear-groups make GOCACHE=/tmp/gocache local-release"
local-release: clean
set -o errexit; \
for OS in darwin linux windows; do \
EXT=; \
ARCHS=; \
case $$OS in \
darwin) \
ARCHS='amd64 arm64'; \
;; \
linux) \
ARCHS='amd64 arm64'; \
;; \
windows) \
ARCHS='amd64 arm64'; \
EXT=".exe"; \
;; \
esac; \
for ARCH in $$ARCHS; do \
echo Building release binary for $$OS/$$ARCH...; \
test -d release/$$OS/$$ARCH|| mkdir -p release/$$OS/$$ARCH; \
env GOOS=$$OS GOARCH=$$ARCH $(GO_BUILD) $(if $(GO_TAGS),-tags $(GO_TAGS)) \
-ldflags "$(GO_BUILD_LDFLAGS)" \
-o release/$$OS/$$ARCH/$(TARGET)$$EXT ./cmd/cilium; \
if [ $$OS = "windows" ]; \
then \
zip -j release/$(TARGET)-$$OS-$$ARCH.zip release/$$OS/$$ARCH/$(TARGET)$$EXT; \
(cd release && sha256sum $(TARGET)-$$OS-$$ARCH.zip > $(TARGET)-$$OS-$$ARCH.zip.sha256sum); \
else \
tar -czf release/$(TARGET)-$$OS-$$ARCH.tar.gz -C release/$$OS/$$ARCH $(TARGET)$$EXT; \
(cd release && sha256sum $(TARGET)-$$OS-$$ARCH.tar.gz > $(TARGET)-$$OS-$$ARCH.tar.gz.sha256sum); \
fi; \
done; \
rm -rf release/$$OS; \
done; \
install: $(TARGET)
$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 $(TARGET) $(DESTDIR)$(BINDIR)
clean:
rm -f $(TARGET)
rm -rf ./release
test:
$(GO) test -timeout=$(TEST_TIMEOUT) -race -cover $$($(GO) list ./...)
bench:
$(GO) test -timeout=30s -bench=. $$($(GO) list ./...)
clean-tags:
@-rm -f cscope.out cscope.in.out cscope.po.out cscope.files tags
tags: $$($(GO) list ./...)
@ctags $<
cscope -R -b -q
ifneq (,$(findstring $(GOLANGCILINT_WANT_VERSION:v%=%),$(GOLANGCILINT_VERSION)))
check:
golangci-lint run
else
check:
docker run --rm -v `pwd`:/app -w /app docker.io/golangci/golangci-lint:$(GOLANGCILINT_WANT_VERSION) golangci-lint run
endif
.PHONY: $(TARGET) release local-release install clean test bench check clean-tags tags
-include Makefile.override