Skip to content

Commit c6631b5

Browse files
committed
Makefile: Set dependencies to _output/bin/limactl$(exe) and _output/share/lima/lima-guestagent.Linux-%
Dependencies are defined using glob patterns: - `limactl`: `go.mod`, `./cmd/limactl/**/!(*_test.go)`, `./pkg/**/!(*_test.go)`. `vz.entitlements` will be added if darwin. - `lima-guestagent`: `go.mod`, `./cmd/lima-guestagent/**/!(*_test.go)`, and `./pkg/**/!(*_test.go)`. Those patterns are expanded by `bash` using `shopt`: `extglob`, `globstar`, and `nullglob`. Signed-off-by: Norio Nomura <[email protected]>
1 parent 5db1b15 commit c6631b5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,23 @@ binaries: clean \
112112
documentation create-links-in-doc-dir
113113

114114
# _output/bin
115-
.PHONY: limactl _output/bin/limactl$(exe) lima helpers
115+
.PHONY: limactl lima helpers
116116
limactl: _output/bin/limactl$(exe) codesign lima
117117

118-
_output/bin/limactl$(exe):
118+
# returns a list of files expanded from $(1) excluding directories.
119+
glob_excluding_dir = $(shell bash -c -O extglob -O globstar -O nullglob 'for f in $(1); do test -d $$f || echo $$f; done')
120+
FILES_IN_PKG = $(call glob_excluding_dir, ./pkg/**/!(*_test.go))
121+
122+
# returns a list of files which are dependencies for the command $(1).
123+
dependencis_for_cmd = go.mod $(call glob_excluding_dir, ./cmd/$(1)/**/!(*_test.go)) $(FILES_IN_PKG)
124+
125+
# dependencies for limactl
126+
DEPENDENCIES_FOR_LIMACTL = $(call dependencis_for_cmd,limactl)
127+
ifeq ($(GOOS),darwin)
128+
DEPENDENCIES_FOR_LIMACTL += vz.entitlements
129+
endif
130+
131+
_output/bin/limactl$(exe): $(DEPENDENCIES_FOR_LIMACTL)
119132
# The hostagent must be compiled with CGO_ENABLED=1 so that net.LookupIP() in the DNS server
120133
# calls the native resolver library and not the simplistic version in the Go library.
121134
CGO_ENABLED=1 $(GO_BUILD) -o $@ ./cmd/limactl
@@ -163,7 +176,7 @@ native-guestagent: $(NATIVE_GUESTAGENT)
163176
additional-guestagents: $(ADDITIONAL_GUESTAGENTS)
164177
%-guestagent:
165178
@[ "$(findstring $(*),$(GUESTAGENT_ARCHS))" == "$(*)" ] && make _output/share/lima/lima-guestagent.Linux-$*
166-
_output/share/lima/lima-guestagent.Linux-%: | _output/share/lima
179+
_output/share/lima/lima-guestagent.Linux-%: $(call dependencis_for_cmd,lima-guestagent) | _output/share/lima
167180
GOOS=linux $(GUESTAGENT_ARCH_ENVS_$*) CGO_ENABLED=0 $(GO_BUILD) -o $@ ./cmd/lima-guestagent
168181
chmod 644 $@
169182
ifeq ($(CONFIG_GUESTAGENT_COMPRESS),y)

0 commit comments

Comments
 (0)