Made "upgrade" target idempotent and added it as dependency to "install".
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sat, 02 Jan 2021 00:27:54 +0200
changeset 1665 3685e2321a9b
parent 1664 72275301c19d
child 1666 06937ff1ec5f
Made "upgrade" target idempotent and added it as dependency to "install".
Makefile
--- a/Makefile	Fri Jan 01 21:34:09 2021 +0200
+++ b/Makefile	Sat Jan 02 00:27:54 2021 +0200
@@ -107,25 +107,20 @@
 ################################################################
 # Install/uninstall targets.
 
-.PHONY: check-install-comapt
-check-install-comapt:
-	\
-if [ -f ~/.emacs ]; then \
-  echo Old style install detected, run '"$(MAKE) upgrade"' first; \
-  false; \
-fi
-	\
-if [ -f $(emacsdir)/init.el ]; then \
-  if [ ! -f $(COMPAT_FILE) ]; then \
-    echo $(COMPAT_FILE) missing, run '"$(MAKE) upgrade"' first; \
-    exit 1; \
-  fi; \
-fi
-	read ver <$(COMPAT_FILE); if [ "$$ver" -ne $(COMPAT_VER) ]; then echo "*** "Run '"$(MAKE) upgrade"' first" ***"; exit 1; fi
+ifneq '' '$(filter upgrade,$(MAKECMDGOALS))'
+  ifeq '' '$(filter install%,$(MAKECMDGOALS))'
+    $(error "upgrade" should be invoked from "install")
+  endif
+endif
 
 .PHONY: upgrade
 upgrade:
 	\
+if [[ -f ~/.emacs ]]; then \
+  echo An old style install detected, delete ~/.emacs first.; \
+  false; \
+fi
+	\
 [[ -f $(COMPAT_FILE) ]] || exit 0; \
 read ver <$(COMPAT_FILE); \
 if [[ "$$ver" -gt $(COMPAT_VER) ]]; then \
@@ -135,7 +130,6 @@
 for ((i=ver+1; i <= $(COMPAT_VER); i++)); do \
   $(SHELL) upgrade/$$i.bash; \
 done
-	$(MAKE) install
 
 .PHONY: install-all
 install-all: install
@@ -147,7 +141,7 @@
 endef
 
 .PHONY: install
-install: check-install-comapt
+install: upgrade
 	mkdir -p $(mylispdir)
 	echo $(COMPAT_VER) >$(COMPAT_FILE)
 	$(cleanup_mylispdir)