-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
74 lines (59 loc) · 2.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# The needed programs
SHELL = /bin/sh
STOW = stow
GZIP = gzip
TAR = bsdtar
RM = rm --recursive --force
# Collecting all the configuration files in the current directory.
# Imma explain it in bash:
#
# declare -a DOTFILES;
# for pkg in $(ls dotfiles/); do
# DOTFILES += $(basename $pkg);
# done
DOTFILES = $(foreach pkg,$(wildcard dotfiles/*),$(shell basename $(pkg)))
# These are some useful paths needed by stow to actually do its job:
# - First we have the `STOWDIR` (or stow directory as referred to by `man
# stwo`) that is the directory in which a copy of the package will be kept;
# - Then stow requires the actual directory in which the package wants to
# appear installed, in this case my dotfiles gets installed in 2 locations:
# - Home directory (as `HOMEDIR`);
# - Config directory defined by XDG standard (as `CONFDIR`).
STOWDIR = dotfiles
prefix = $(HOME)
# Configuring flags for creating a distribution archive (.tar.gz)
TARNAME = mattia\'s-shitty-dotfiles.tar
TARFLAGS = --create --file $(TARNAME)
ZIPFLAGS = --recursive --synchronous $(TARNAME)
# Gotta check some flags
# This is a variable the user can set to stow/unstow only some of the dotfiles
# and not all of them.
ifeq ($(programs),)
programs := $(DOTFILES)
endif
# While this determines the stow's level of verbosity
ifeq ($(verbosity),)
verbosity = 1
endif
# Commong flags needed every time stow runs
COMMON_FLAGS = --verbose=$(verbosity) --target=$(prefix) --dir=$(STOWDIR) --dotfiles
INSTALL_PROGRAM = $(STOW) $(COMMON_FLAGS)
# Test variables.
# This variables use the built-in command `command` to check if a program is
# installed or not. The `-v` flag will print the actual path of the binary.
STOW_CHCK := $(shell command -v $(STOW))
# If no output was given, hence no binary was found, throw an error to warn the
# user about what software needs to be installed.
ifeq ($(STOW_CHCK),)
$(error The program '$(STOW)' is needed to run this Makefile.)
endif
.PHONY: all install uninstall dist
install:
$(INSTALL_PROGRAM) --restow $(programs)
uninstall:
$(INSTALL_PROGRAM) --delete $(programs)
dist:
$(TAR) $(TARFLAGS) $(ROOTDIR)/*
$(GZIP) $(ZIPFLAGS)
$(RM) $(TARNAME)
.DEFAULT: install