Update Makefile to support multiple package directories

It is now possible to install only a specific set of dotfiles instead
of everything at once. To do this, simply run make and set the "package"
variable from the shell. For example, to only stow my vim config, use
`make package=vim`.
This commit is contained in:
Donovan Glover 2018-10-22 18:06:27 -04:00
parent b85f938296
commit 20de137550
No known key found for this signature in database
GPG Key ID: EA7408A77AE1BE65

View File

@ -7,19 +7,44 @@
# make uninstall Uninstalls dotfiles # make uninstall Uninstalls dotfiles
# make prune Removes stale links # make prune Removes stale links
NS_REPO_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) verbose ?= 2
NS_REPO_DIR := $(shell basename $(NS_REPO_PATH)) NS_REPO_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
NS_PARENT_PATH := $(shell dirname $(NS_REPO_PATH)) NS_STOW_OPTIONS := --dir="${NS_REPO_PATH}" --target="${HOME}" --no-folding --verbose=${verbose}
NS_STOW_OPTIONS := "${NS_REPO_DIR}" --dir="${NS_PARENT_PATH}" --target="${HOME}" --no-folding --verbose=2 NS_STOW_PACKAGES := $(wildcard */)
NS_SUCCESS := "SUCCESS: Stow command executed succesfully!"
ns_stow_package = \
echo "STATUS: Found package variable. Stow operation will be performed if it is a valid directory..."; \
test -d ${package} && \
(stow -${1} ${package} ${NS_STOW_OPTIONS} && \
echo ${NS_SUCCESS}) || \
echo "FAILURE: Not a valid target directory."
ns_stow_all = \
echo "STATUS: No package variable given. Performing stow operation on all directories..."; \
$(foreach package,$(NS_STOW_PACKAGES),stow -${1} $(package) ${NS_STOW_OPTIONS} &&) \
echo ${NS_SUCCESS}
.PHONY: install .PHONY: install
install: install:
stow -S ${NS_STOW_OPTIONS} ifdef package
@$(call ns_stow_package,S)
else
@$(call ns_stow_all,S)
endif
.PHONY: uninstall .PHONY: uninstall
uninstall: uninstall:
stow -D ${NS_STOW_OPTIONS} ifdef package
@$(call ns_stow_package,D)
else
@$(call ns_stow_all,D)
endif
.PHONY: prune .PHONY: prune
prune: prune:
stow -R ${NS_STOW_OPTIONS} ifdef package
@$(call ns_stow_package,R)
else
@$(call ns_stow_all,R)
endif