forked from lima-vm/lima
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
293 lines (246 loc) · 8.85 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
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
# Files are installed under $(DESTDIR)/$(PREFIX)
PREFIX ?= /usr/local
DEST := $(shell echo "$(DESTDIR)/$(PREFIX)" | sed 's:///*:/:g; s://*$$::')
GO ?= go
TAR ?= tar
ZIP ?= zip
PLANTUML ?= plantuml # may also be "java -jar plantuml.jar" if installed elsewhere
# The KCONFIG programs are only needed for re-generating the ".config" file.
# You can install the python "kconfiglib", if you don't have kconfig/kbuild.
KCONFIG_CONF ?= $(shell command -v kconfig-conf || command -v kbuild-conf || echo oldconfig)
KCONFIG_MCONF ?= $(shell command -v kconfig-mconf || command -v kbuild-mconf || echo menuconfig)
GOOS ?= $(shell $(GO) env GOOS)
ifeq ($(GOOS),windows)
bat = .bat
exe = .exe
endif
GO_BUILDTAGS ?=
ifeq ($(GOOS),darwin)
MACOS_SDK_VERSION=$(shell xcrun --show-sdk-version | cut -d . -f 1)
ifeq ($(shell test $(MACOS_SDK_VERSION) -lt 13; echo $$?),0)
# The "vz" mode needs macOS 13 SDK or later
GO_BUILDTAGS += no_vz
endif
endif
ifeq ($(GOOS),windows)
WINVER_MAJOR=$(shell powershell.exe "[System.Environment]::OSVersion.Version.Major")
ifeq ($(WINVER_MAJOR),10)
WINVER_BUILD=$(shell powershell.exe "[System.Environment]::OSVersion.Version.Build")
WINVER_BUILD_HIGH_ENOUGH=$(shell powershell.exe $(WINVER_BUILD) -ge 19041)
ifeq ($(WINVER_BUILD_HIGH_ENOUGH),False)
GO_BUILDTAGS += no_wsl
endif
endif
endif
PACKAGE := github.com/lima-vm/lima
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always --tags)
VERSION_TRIMMED := $(VERSION:v%=%)
GO_BUILD := $(GO) build -ldflags="-s -w -X $(PACKAGE)/pkg/version.Version=$(VERSION)" -tags "$(GO_BUILDTAGS)"
.NOTPARALLEL:
.PHONY: all
all: binaries manpages
.PHONY: help
help:
@echo ' binaries - Build all binaries'
@echo ' manpages - Build manual pages'
exe: _output/bin/limactl$(exe)
.PHONY: minimal
minimal: clean \
_output/bin/limactl$(exe) \
codesign \
_output/share/lima/lima-guestagent.Linux-$(shell uname -m | sed -e s/arm64/aarch64/)
mkdir -p _output/share/lima/templates
cp -aL examples/default.yaml _output/share/lima/templates/
config: Kconfig
$(KCONFIG_CONF) $<
menuconfig: Kconfig
MENUCONFIG_STYLE=aquatic \
$(KCONFIG_MCONF) $<
# Copy the default config, if not overridden locally
# This is done to avoid a dependency on KCONFIG tools
.config: config.mk
cp $^ $@
-include .config
HELPERS = \
_output/bin/nerdctl.lima \
_output/bin/apptainer.lima \
_output/bin/docker.lima \
_output/bin/podman.lima \
_output/bin/kubectl.lima
ifeq ($(CONFIG_GUESTAGENT_OS_LINUX),y)
ifeq ($(CONFIG_GUESTAGENT_ARCH_X8664),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-x86_64
endif
ifeq ($(CONFIG_GUESTAGENT_ARCH_AARCH64),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-aarch64
endif
ifeq ($(CONFIG_GUESTAGENT_ARCH_ARMV7L),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-armv7l
endif
ifeq ($(CONFIG_GUESTAGENT_ARCH_RISCV64),y)
GUESTAGENT += \
_output/share/lima/lima-guestagent.Linux-riscv64
endif
endif
.PHONY: binaries
binaries: clean \
_output/bin/lima \
_output/bin/lima$(bat) \
_output/bin/limactl$(exe) \
codesign \
$(HELPERS) \
$(GUESTAGENT)
cp -aL examples _output/share/lima/templates
ifneq ($(GOOS),windows)
ln -sf templates _output/share/lima/examples
else
cp -aL examples _output/share/lima/examples
endif
mkdir -p _output/share/doc/lima
cp -aL *.md LICENSE _output/share/doc/lima
echo "Moved to https://github.com/lima-vm/.github/blob/main/SECURITY.md" >_output/share/doc/lima/SECURITY.md
ifneq ($(GOOS),windows)
ln -sf ../../lima/templates _output/share/doc/lima/templates
ln -sf templates _output/share/doc/lima/examples
else
cp -aL examples _output/share/doc/lima/examples
cp -aL examples _output/share/doc/lima/templates
endif
echo $(VERSION) > _output/share/doc/lima/VERSION
.PHONY: _output/bin/lima
_output/bin/lima:
mkdir -p _output/bin
cp -a ./cmd/lima $@
.PHONY: _output/bin/lima.bat
_output/bin/lima.bat:
mkdir -p _output/bin
cp -a ./cmd/lima.bat $@
.PHONY: _output/bin/nerdctl.lima
_output/bin/nerdctl.lima:
mkdir -p _output/bin
cp -a ./cmd/nerdctl.lima $@
_output/bin/apptainer.lima: ./cmd/apptainer.lima
@mkdir -p _output/bin
cp -a $^ $@
_output/bin/docker.lima: ./cmd/docker.lima
@mkdir -p _output/bin
cp -a $^ $@
_output/bin/podman.lima: ./cmd/podman.lima
@mkdir -p _output/bin
cp -a $^ $@
_output/bin/kubectl.lima: ./cmd/kubectl.lima
@mkdir -p _output/bin
cp -a $^ $@
.PHONY: _output/bin/limactl$(exe)
_output/bin/limactl$(exe):
# The hostagent must be compiled with CGO_ENABLED=1 so that net.LookupIP() in the DNS server
# calls the native resolver library and not the simplistic version in the Go library.
CGO_ENABLED=1 $(GO_BUILD) -o $@ ./cmd/limactl
.PHONY: _output/share/lima/lima-guestagent.Linux-x86_64
_output/share/lima/lima-guestagent.Linux-x86_64:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
chmod 644 $@
.PHONY: _output/share/lima/lima-guestagent.Linux-aarch64
_output/share/lima/lima-guestagent.Linux-aarch64:
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
chmod 644 $@
.PHONY: _output/share/lima/lima-guestagent.Linux-armv7l
_output/share/lima/lima-guestagent.Linux-armv7l:
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
chmod 644 $@
.PHONY: _output/share/lima/lima-guestagent.Linux-riscv64
_output/share/lima/lima-guestagent.Linux-riscv64:
GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
chmod 644 $@
.PHONY: manpages
manpages: _output/bin/limactl$(exe)
@mkdir -p _output/share/man/man1
$< generate-doc _output/share/man/man1 \
--output _output --prefix $(PREFIX)
.PHONY: docsy
docsy: _output/bin/limactl$(exe)
@mkdir -p website/_output/docsy
$< generate-doc --type docsy website/_output/docsy \
--output _output --prefix $(PREFIX)
.PHONY: diagrams
diagrams: docs/lima-sequence-diagram.png
docs/lima-sequence-diagram.png: docs/images/lima-sequence-diagram.puml
$(PLANTUML) ./docs/images/lima-sequence-diagram.puml
.PHONY: install
install: uninstall
mkdir -p "$(DEST)"
# Use tar rather than cp, for better symlink handling
( cd _output && tar c * | tar Cxv "$(DEST)" )
if [ "$(shell uname -s )" != "Linux" -a ! -e "$(DEST)/bin/nerdctl" ]; then ln -sf nerdctl.lima "$(DEST)/bin/nerdctl"; fi
if [ "$(shell uname -s )" != "Linux" -a ! -e "$(DEST)/bin/apptainer" ]; then ln -sf apptainer.lima "$(DEST)/bin/apptainer"; fi
.PHONY: uninstall
uninstall:
@test -f "$(DEST)/bin/lima" || echo "lima not found in $(DEST) prefix"
rm -rf \
"$(DEST)/bin/lima" \
"$(DEST)/bin/lima$(bat)" \
"$(DEST)/bin/limactl$(exe)" \
"$(DEST)/bin/nerdctl.lima" \
"$(DEST)/bin/apptainer.lima" \
"$(DEST)/bin/docker.lima" \
"$(DEST)/bin/podman.lima" \
"$(DEST)/bin/kubectl.lima" \
"$(DEST)/share/man/man1/lima.1" \
"$(DEST)/share/man/man1/limactl"*".1" \
"$(DEST)/share/lima" "$(DEST)/share/doc/lima"
if [ "$$(readlink "$(DEST)/bin/nerdctl")" = "nerdctl.lima" ]; then rm "$(DEST)/bin/nerdctl"; fi
if [ "$$(readlink "$(DEST)/bin/apptainer")" = "apptainer.lima" ]; then rm "$(DEST)/bin/apptainer"; fi
.PHONY: check-generated
check-generated:
@test -z "$$(git status --short | grep ".pb.desc" | tee /dev/stderr)" || \
((git diff $$(find . -name '*.pb.desc') | cat) && \
(echo "Please run 'make generate' when making changes to proto files and check-in the generated file changes" && false))
.PHONY: lint
lint: check-generated
golangci-lint run ./...
yamllint .
find . -name '*.sh' | xargs shellcheck
find . -name '*.sh' | xargs shfmt -s -d
.PHONY: clean
clean:
rm -rf _output vendor
.PHONY: install-tools
install-tools:
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
.PHONY: generate
generate:
go generate ./...
.PHONY: artifacts-darwin
artifacts-darwin:
mkdir -p _artifacts
GOOS=darwin GOARCH=amd64 make clean binaries
$(TAR) -C _output/ -czvf _artifacts/lima-$(VERSION_TRIMMED)-Darwin-x86_64.tar.gz ./
GOOS=darwin GOARCH=arm64 make clean binaries
$(TAR) -C _output -czvf _artifacts/lima-$(VERSION_TRIMMED)-Darwin-arm64.tar.gz ./
.PHONY: artifacts-linux
artifacts-linux:
mkdir -p _artifacts
GOOS=linux GOARCH=amd64 make clean binaries
$(TAR) -C _output/ -czvf _artifacts/lima-$(VERSION_TRIMMED)-Linux-x86_64.tar.gz ./
GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc make clean binaries
$(TAR) -C _output/ -czvf _artifacts/lima-$(VERSION_TRIMMED)-Linux-aarch64.tar.gz ./
.PHONY: artifacts-windows
artifacts-windows:
mkdir -p _artifacts
GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc make clean binaries
$(TAR) -C _output/ -czvf _artifacts/lima-$(VERSION_TRIMMED)-Windows-x86_64.tar.gz ./
cd _output && $(ZIP) -r ../_artifacts/lima-$(VERSION_TRIMMED)-Windows-x86_64.zip *
.PHONY: artifacts-misc
artifacts-misc:
mkdir -p _artifacts
go mod vendor
$(TAR) -czf _artifacts/lima-$(VERSION_TRIMMED)-go-mod-vendor.tar.gz go.mod go.sum vendor
.PHONY: codesign
codesign:
ifeq ($(GOOS),darwin)
codesign --entitlements vz.entitlements -s - ./_output/bin/limactl
endif