From eff7623a9a2e9c7ccedb2c95a1730ac4d523ed9c Mon Sep 17 00:00:00 2001 From: Donovan Glover Date: Tue, 23 Oct 2018 22:46:49 -0400 Subject: [PATCH] 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. --- Makefile | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 769b7176..16456214 100644 --- a/Makefile +++ b/Makefile @@ -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_PACKAGES := $(wildcard */) NS_SUCCESS := "SUCCESS: Stow command executed succesfully!" +NS_STOW_COMMAND := $(if ${package},ns_stow_package,ns_stow_all) ns_stow_package = \ 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 install: -ifdef package - @$(call ns_stow_package,S) -else - @$(call ns_stow_all,S) -endif + @$(call ${NS_STOW_COMMAND},S) .PHONY: uninstall uninstall: -ifdef package - @$(call ns_stow_package,D) -else - @$(call ns_stow_all,D) -endif + @$(call ${NS_STOW_COMMAND},D) .PHONY: prune prune: -ifdef package - @$(call ns_stow_package,R) -else - @$(call ns_stow_all,R) -endif + @$(call ${NS_STOW_COMMAND},R)