Skip to content

Commit 0b9508f

Browse files
committed
Refactor os and arch conditionals in Makefile
Prepare for adding another operating system for guestagents. Correct some typos in the helper functions and documentation. Signed-off-by: Anders F Björklund <[email protected]>
1 parent 75221d6 commit 0b9508f

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

Makefile

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ help-targets:
8080
@echo '- helpers : Copy nerdctl.lima, apptainer.lima, docker.lima, podman.lima, and kubectl.lima'
8181
@echo
8282
@echo 'Targets for files in _output/share/lima/:'
83-
@echo '- guestagents : Build guestagents for archs enabled by CONFIG_GUESTAGENT_ARCHS_*'
83+
@echo '- guestagents : Build guestagents for archs enabled by CONFIG_GUESTAGENT_ARCH_*'
8484
@echo '- native-guestagent : Build guestagent for native arch'
8585
@echo '- additional-guestagents : Build guestagents for archs other than native arch'
86-
@echo '- <arch>-guestagent : Build guestagent for <arch>: $(sort $(GUESTAGENT_ARCHS))'
86+
@echo '- <arch>-guestagent : Build guestagent for <arch>: $(sort $(LINUX_GUESTAGENT_ARCHS))'
8787
@echo
8888
@echo 'Targets for files in _output/share/lima/templates/:'
8989
@echo '- templates : Copy templates'
@@ -256,27 +256,30 @@ LINUX_GUESTAGENT_PATH_COMMON = _output/share/lima/lima-guestagent.Linux-
256256

257257
# How to add architecture specific guestagent:
258258
# 1. Add the architecture to GUESTAGENT_ARCHS
259-
# 2. Add ENVS_$(LINUX_GUESTAGENT_PATH_COMMON)<arch> to set GOOS, GOARCH, and other necessary environment variables
260-
GUESTAGENT_ARCHS = aarch64 armv7l riscv64 x86_64
259+
# 2. Add ENVS_$(*_GUESTAGENT_PATH_COMMON)<arch> to set GOOS, GOARCH, and other necessary environment variables
260+
LINUX_GUESTAGENT_ARCHS = aarch64 armv7l riscv64 x86_64
261261

262-
ALL_GUESTAGENTS_NOT_COMPRESSED = $(addprefix $(LINUX_GUESTAGENT_PATH_COMMON),$(GUESTAGENT_ARCHS))
262+
ifeq ($(CONFIG_GUESTAGENT_OS_LINUX),y)
263+
ALL_GUESTAGENTS_NOT_COMPRESSED += $(addprefix $(LINUX_GUESTAGENT_PATH_COMMON),$(LINUX_GUESTAGENT_ARCHS))
264+
endif
263265
ifeq ($(CONFIG_GUESTAGENT_COMPRESS),y)
264266
$(info Guestagents are unzipped each time to check the build configuration; they may be gunzipped afterward.)
265267
gz=.gz
266268
endif
267269

268270
ALL_GUESTAGENTS = $(addsuffix $(gz),$(ALL_GUESTAGENTS_NOT_COMPRESSED))
269271

270-
# guestagent path for the given architectures. it may has .gz extension if CONFIG_GUESTAGENT_COMPRESS is enabled.
271-
# $(1): list of architectures
272-
guestaget_path = $(foreach arch,$(1),$(LINUX_GUESTAGENT_PATH_COMMON)$(arch)$(gz))
273-
274-
NATIVE_GUESTAGENT_ARCH = $(shell uname -m | sed -e s/arm64/aarch64/)
275-
NATIVE_GUESTAGENT = $(call guestaget_path,$(NATIVE_GUESTAGENT_ARCH))
276-
ADDITIONAL_GUESTAGENT_ARCHS = $(filter-out $(NATIVE_GUESTAGENT_ARCH),$(GUESTAGENT_ARCHS))
277-
ADDITIONAL_GUESTAGENTS = $(call guestaget_path,$(ADDITIONAL_GUESTAGENT_ARCHS))
272+
# guestagent path for the given platform. it may has .gz extension if CONFIG_GUESTAGENT_COMPRESS is enabled.
273+
# $(1): operating system (os)
274+
# $(2): list of architectures
275+
guestagent_path = $(foreach arch,$(2),$($(1)_GUESTAGENT_PATH_COMMON)$(arch)$(gz))
278276

279277
ifeq ($(CONFIG_GUESTAGENT_OS_LINUX),y)
278+
NATIVE_GUESTAGENT_ARCH = $(shell uname -m | sed -e s/arm64/aarch64/)
279+
NATIVE_GUESTAGENT = $(call guestagent_path,LINUX,$(NATIVE_GUESTAGENT_ARCH))
280+
ADDITIONAL_GUESTAGENT_ARCHS = $(filter-out $(NATIVE_GUESTAGENT_ARCH),$(LINUX_GUESTAGENT_ARCHS))
281+
ADDITIONAL_GUESTAGENTS = $(call guestagent_path,LINUX,$(ADDITIONAL_GUESTAGENT_ARCHS))
282+
endif
280283

281284
# config_guestagent_arch returns expanded value of CONFIG_GUESTAGENT_ARCH_<arch>
282285
# $(1): architecture
@@ -285,18 +288,19 @@ config_guestagent_arch = $(filter y,$(CONFIG_GUESTAGENT_ARCH_$(shell echo $(1)|t
285288

286289
# guestagent_path_enabled_by_config returns the path to the guestagent binary for the given architecture,
287290
# or an empty string if the CONFIG_GUESTAGENT_ARCH_<arch> is not set.
288-
guestagent_path_enabled_by_config = $(if $(call config_guestagent_arch,$(1)),$(call guestaget_path,$(1)))
291+
guestagent_path_enabled_by_config = $(if $(call config_guestagent_arch,$(2)),$(call guestagent_path,$(1),$(2)))
289292

293+
ifeq ($(CONFIG_GUESTAGENT_OS_LINUX),y)
290294
# apply CONFIG_GUESTAGENT_ARCH_*
291-
GUESTAGENTS = $(foreach arch,$(GUESTAGENT_ARCHS),$(call guestagent_path_enabled_by_config,$(arch)))
295+
GUESTAGENTS += $(foreach arch,$(LINUX_GUESTAGENT_ARCHS),$(call guestagent_path_enabled_by_config,LINUX,$(arch)))
292296
endif
293297

294298
.PHONY: guestagents native-guestagent additional-guestagents
295299
guestagents: $(GUESTAGENTS)
296300
native-guestagent: $(NATIVE_GUESTAGENT)
297301
additional-guestagents: $(ADDITIONAL_GUESTAGENTS)
298302
%-guestagent:
299-
@[ "$(findstring $(*),$(GUESTAGENT_ARCHS))" == "$(*)" ] && make $(call guestaget_path,$*)
303+
@[ "$(findstring $(*),$(LINUX_GUESTAGENT_ARCHS))" == "$(*)" ] && make $(call guestagent_path,LINUX,$*)
300304

301305
# environment variables for linx-guestagent. these variable are used for checking force build.
302306
ENVS_$(LINUX_GUESTAGENT_PATH_COMMON)aarch64 = CGO_ENABLED=0 GOOS=linux GOARCH=arm64

0 commit comments

Comments
 (0)