Makefile: Don't repeat yourself

Instead of writing the same if conditional in three different places,
I can set a variable based on the conditional and use that instead.
This commit is contained in:
Donovan Glover 2018-10-23 22:46:49 -04:00
parent 21814cda7f
commit eff7623a9a
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65

View File

@ -12,6 +12,7 @@ NS_REPO_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
NS_STOW_OPTIONS := --dir="${NS_REPO_PATH}" --target="${HOME}" --no-folding --verbose=${verbose} NS_STOW_OPTIONS := --dir="${NS_REPO_PATH}" --target="${HOME}" --no-folding --verbose=${verbose}
NS_STOW_PACKAGES := $(wildcard */) NS_STOW_PACKAGES := $(wildcard */)
NS_SUCCESS := "SUCCESS: Stow command executed succesfully!" NS_SUCCESS := "SUCCESS: Stow command executed succesfully!"
NS_STOW_COMMAND := $(if ${package},ns_stow_package,ns_stow_all)
ns_stow_package = \ ns_stow_package = \
echo "STATUS: Found package variable. Stow operation will be performed if it is a valid directory..."; \ echo "STATUS: Found package variable. Stow operation will be performed if it is a valid directory..."; \
@ -27,24 +28,12 @@ ns_stow_all =
.PHONY: install .PHONY: install
install: install:
ifdef package @$(call ${NS_STOW_COMMAND},S)
@$(call ns_stow_package,S)
else
@$(call ns_stow_all,S)
endif
.PHONY: uninstall .PHONY: uninstall
uninstall: uninstall:
ifdef package @$(call ${NS_STOW_COMMAND},D)
@$(call ns_stow_package,D)
else
@$(call ns_stow_all,D)
endif
.PHONY: prune .PHONY: prune
prune: prune:
ifdef package @$(call ${NS_STOW_COMMAND},R)
@$(call ns_stow_package,R)
else
@$(call ns_stow_all,R)
endif