Skip to content

Commit f3b5079

Browse files
committed
Makefile: add a symlink check to targets that create symlinks.
Signed-off-by: Norio Nomura <[email protected]>
1 parent 7137d62 commit f3b5079

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,17 @@ MKDIR_TARGETS += _output/share/lima/templates _output/share/lima/templates/exper
282282
_output/share/lima/templates/%: examples/%
283283
cp -aL $< $@
284284

285+
# returns "force" if GOOS==windows, or GOOS!=windows and the file $(1) is not a symlink.
286+
# $(1): target file
287+
# On Windows, always copy to ensure the target has the same file as the source.
288+
force_link = $(if $(filter windows,$(GOOS)),force,$(shell test ! -L $(1) && echo force))
285289

286290
# _output/share/lima/examples
287291
.PHONY: create-examples-link
288292
create-examples-link: _output/share/lima/examples
289-
_output/share/lima/examples: _output/share/lima/templates
293+
_output/share/lima/examples: _output/share/lima/templates $$(call force_link,$$@)
294+
# remove the existing directory or symlink
295+
rm -rf $@
290296
ifneq ($(GOOS),windows)
291297
ln -sf templates $@
292298
else
@@ -311,17 +317,20 @@ _output/share/doc/lima/%: % | _output/share/doc/lima
311317

312318
MKDIR_TARGETS += _output/share/doc/lima
313319

314-
315320
.PHONY: create-links-in-doc-dir
316321
create-links-in-doc-dir: _output/share/doc/lima/templates _output/share/doc/lima/examples
317-
_output/share/doc/lima/templates: _output/share/lima/templates
322+
_output/share/doc/lima/templates: _output/share/lima/templates $$(call force_link,$$@)
323+
# remove the existing directory or symlink
324+
rm -rf $@
318325
ifneq ($(GOOS),windows)
319326
ln -sf ../../lima/templates $@
320327
else
321328
# copy from templates built in build process
322329
cp -aL $< $@
323330
endif
324-
_output/share/doc/lima/examples: _output/share/doc/lima/templates
331+
_output/share/doc/lima/examples: _output/share/doc/lima/templates $$(call force_link,$$@)
332+
# remove the existing directory or symlink
333+
rm -rf $@
325334
ifneq ($(GOOS),windows)
326335
ln -sf templates $@
327336
else

0 commit comments

Comments
 (0)