Makefile: Improve output appearance.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 14 Mar 2022 17:53:42 +0000 (17:53 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 14 Mar 2022 20:06:38 +0000 (20:06 +0000)
Makefile

index 30acdd8..8cfecb5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -8,8 +8,11 @@ force:
 V                      ?= 0
 V_AT                    = $(V_AT_$V)
 V_AT_0                  = @
+v-print                         = $(call v-print.$V,$1,$2)
+v-print.1               = :
+v-print.0               = printf "  %-8s %s\n" "$1" "$2"
 v-tag                   = $(call v-tag.$V,$1)
-v-tag.0                         = @printf "  %-8s %s\n" "$1" "$@";
+v-tag.0                         = @$(call v-print.0,$1,$@);
 
 TARGETS                         =
 CLEANFILES             += $(TARGETS)
@@ -137,11 +140,22 @@ all: $(TARGETS)
 CHECKS                  = $(foreach p,$(PLAYLISTS), check/$p)
 check: $(CHECKS)
 $(CHECKS): check/%: %.m3u8
-       diff -u $< ref/$*.m3u8
+       $(V_AT)diff -u $< ref/$*.m3u8
 .PHONY: check $(CHECKS)
 
 LINKS                   = $(foreach p,$(PLAYLISTS), link/$p)
 link: $(LINKS)
 $(LINKS): link/%:
-       ln -frs $*.m3u8 "$(ARCHIVEROOT)/$($*_INITIAL)/$($*_FULLNAME).m3u8"
+       $(V_AT) \
+               ok=nil t="$(ARCHIVEROOT)/$($*_INITIAL)/$($*_FULLNAME).m3u8"; \
+               if [ -L "$$t" ]; then \
+                 case $$(realpath "$$t") in \
+                   "$(abspath $*.m3u8)") ok=t ;; \
+                 esac; \
+               fi; \
+               case $$ok in \
+                 t) ;; \
+                 *) $(call v-print,LINK,$*); \
+                       ln -frs $*.m3u8 "$$t.new" && mv "$$t.new" "$$t" ;; \
+               esac
 .PHONY: link $(LINKS)