Skip to content

Commit

Permalink
Makefile: add a symlink check to targets that create symlinks.
Browse files Browse the repository at this point in the history
Signed-off-by: Norio Nomura <[email protected]>
  • Loading branch information
norio-nomura committed Oct 4, 2024
1 parent 7137d62 commit f3b5079
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,17 @@ MKDIR_TARGETS += _output/share/lima/templates _output/share/lima/templates/exper
_output/share/lima/templates/%: examples/%
cp -aL $< $@

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

# _output/share/lima/examples
.PHONY: create-examples-link
create-examples-link: _output/share/lima/examples
_output/share/lima/examples: _output/share/lima/templates
_output/share/lima/examples: _output/share/lima/templates $$(call force_link,$$@)
# remove the existing directory or symlink
rm -rf $@
ifneq ($(GOOS),windows)
ln -sf templates $@
else
Expand All @@ -311,17 +317,20 @@ _output/share/doc/lima/%: % | _output/share/doc/lima

MKDIR_TARGETS += _output/share/doc/lima


.PHONY: create-links-in-doc-dir
create-links-in-doc-dir: _output/share/doc/lima/templates _output/share/doc/lima/examples
_output/share/doc/lima/templates: _output/share/lima/templates
_output/share/doc/lima/templates: _output/share/lima/templates $$(call force_link,$$@)
# remove the existing directory or symlink
rm -rf $@
ifneq ($(GOOS),windows)
ln -sf ../../lima/templates $@
else
# copy from templates built in build process
cp -aL $< $@
endif
_output/share/doc/lima/examples: _output/share/doc/lima/templates
_output/share/doc/lima/examples: _output/share/doc/lima/templates $$(call force_link,$$@)
# remove the existing directory or symlink
rm -rf $@
ifneq ($(GOOS),windows)
ln -sf templates $@
else
Expand Down

0 comments on commit f3b5079

Please sign in to comment.