Skip to content

Commit 9f99c0d

Browse files
committed
Makefile: use .SECONDEXPANSION
https://www.gnu.org/software/make/manual/make.html#Secondary-Expansion Signed-off-by: Norio Nomura <[email protected]>
1 parent 95422d3 commit 9f99c0d

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

Makefile

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ GO_BUILD_FLAG_TAGS := $(addprefix -tags=,$(shell echo "$(GO_BUILDTAGS)"|tr " " "
5050
GO_BUILD := $(GO) build $(GO_BUILD_LDFLAGS) $(GO_BUILD_FLAG_TAGS)
5151

5252
.NOTPARALLEL:
53+
.SECONDEXPANSION:
5354

5455
.PHONY: all
5556
all: binaries manpages
@@ -177,7 +178,7 @@ endif
177178
# environment variables for limactl. this variable is used for checking force build.
178179
ENVS__output/bin/limactl$(exe) = CGO_ENABLED=1 $(addprefix GOOS=,$(GOOS)) $(addprefix GOARCH=,$(GOARCH))
179180

180-
_output/bin/limactl$(exe): $(DEPENDENCIES_FOR_LIMACTL) $(call force_build,_output/bin/limactl$(exe))
181+
_output/bin/limactl$(exe): $(DEPENDENCIES_FOR_LIMACTL) $$(call force_build,$$@)
181182
# The hostagent must be compiled with CGO_ENABLED=1 so that net.LookupIP() in the DNS server
182183
# calls the native resolver library and not the simplistic version in the Go library.
183184
$(ENVS_$@) $(GO_BUILD) -o $@ ./cmd/limactl
@@ -229,11 +230,7 @@ ENVS_$(LINUX_GUESTAGENT_PATH_COMMON)aarch64 = GOOS=linux GOARCH=arm64 CGO_ENABLE
229230
ENVS_$(LINUX_GUESTAGENT_PATH_COMMON)armv7l = GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=0
230231
ENVS_$(LINUX_GUESTAGENT_PATH_COMMON)riscv64 = GOOS=linux GOARCH=riscv64 CGO_ENABLED=0
231232
ENVS_$(LINUX_GUESTAGENT_PATH_COMMON)x86_64 = GOOS=linux GOARCH=amd64 CGO_ENABLED=0
232-
$(LINUX_GUESTAGENT_PATH_COMMON)aarch64: $(call force_build,$(LINUX_GUESTAGENT_PATH_COMMON)aarch64)
233-
$(LINUX_GUESTAGENT_PATH_COMMON)armv7l: $(call force_build,$(LINUX_GUESTAGENT_PATH_COMMON)armv7l)
234-
$(LINUX_GUESTAGENT_PATH_COMMON)riscv64: $(call force_build,$(LINUX_GUESTAGENT_PATH_COMMON)riscv64)
235-
$(LINUX_GUESTAGENT_PATH_COMMON)x86_64: $(call force_build,$(LINUX_GUESTAGENT_PATH_COMMON)x86_64)
236-
$(LINUX_GUESTAGENT_PATH_COMMON)%: $(call dependencis_for_cmd,lima-guestagent) | _output/share/lima
233+
$(LINUX_GUESTAGENT_PATH_COMMON)%: $(call dependencis_for_cmd,lima-guestagent) $$(call force_build,$$@) | _output/share/lima
237234
$(ENVS_$@) $(GO_BUILD) -o $@ ./cmd/lima-guestagent
238235
chmod 644 $@
239236
ifeq ($(CONFIG_GUESTAGENT_COMPRESS),y)
@@ -376,30 +373,37 @@ install-tools:
376373
generate:
377374
go generate ./...
378375

379-
.PHONY: artifacts-darwin artifact-darwin-arm64 artifact-darwin-x86_64
376+
.PHONY: artifacts-darwin
380377
artifacts-darwin: artifact-darwin-x86_64 artifact-darwin-arm64
381378
artifact-darwin-arm64: ENVS=GOOS=darwin GOARCH=arm64
382-
artifact-darwin-arm64: _artifacts/lima-$(VERSION_TRIMMED)-Darwin-arm64.tar.gz
383379
artifact-darwin-x86_64: ENVS=GOOS=darwin GOARCH=amd64
384-
artifact-darwin-x86_64: _artifacts/lima-$(VERSION_TRIMMED)-Darwin-x86_64.tar.gz
385380

386-
.PHONY: artifacts-linux artifact-linux-aarch64 artifact-linux-x86_64
381+
.PHONY: artifacts-linux
387382
artifacts-linux: artifact-linux-x86_64 artifact-linux-aarch64
388383
artifact-linux-aarch64: ENVS=GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc
389-
artifact-linux-aarch64: _artifacts/lima-$(VERSION_TRIMMED)-Linux-aarch64.tar.gz
390384
artifact-linux-x86_64: ENVS=GOOS=linux GOARCH=amd64 CC=x86_64-linux-gnu-gcc
391-
artifact-linux-x86_64: _artifacts/lima-$(VERSION_TRIMMED)-Linux-x86_64.tar.gz
392385

393-
.PHONY: artifacts-windows artifact-windows-x86_64
386+
.PHONY: artifacts-windows
394387
artifacts-windows: artifact-windows-x86_64
395388
artifact-windows-x86_64: ENVS=GOOS=windows GOARCH=amd64 CC=x86_64-w64-mingw32-gcc
396-
artifact-windows-x86_64: _artifacts/lima-$(VERSION_TRIMMED)-Windows-x86_64.tar.gz
397-
cd _output && $(ZIP) -r ../_artifacts/lima-$(VERSION_TRIMMED)-Windows-x86_64.zip *
389+
artifact-windows-%: _artifacts/lima-$(VERSION_TRIMMED)-Windows-$$*.tar.gz _artifacts/lima-$(VERSION_TRIMMED)-Windows-$$*.zip
390+
@true # do nothing
398391

392+
# returns the capitalized string of $(1).
393+
capitalize = $(shell bash -c 'word="$(1)"; echo $${word^}')
394+
artifact-%: _artifacts/lima-$(VERSION_TRIMMED)-$$(call capitalize,$$*).tar.gz
395+
@true # do nothing
396+
397+
# avoid removing the artifacts on completion of the targets.
398+
.PRECIOUS: _artifacts/lima-%.tar.gz _artifacts/lima-%.zip
399399
_artifacts/lima-%.tar.gz: | _artifacts
400400
$(ENVS) make clean binaries
401401
$(TAR) -C _output/ -czvf $@ ./
402402

403+
_artifacts/lima-%.zip: | _artifacts
404+
$(ENVS) make clean binaries
405+
cd _output && $(ZIP) -r ../$@ *
406+
403407
MKDIR_TARGETS += _artifacts
404408

405409
.PHONY: artifacts-misc

0 commit comments

Comments
 (0)