summaryrefslogtreecommitdiff
path: root/Makefile
blob: b8bea183362c902814ea62673414c1c3d44f57c4 (plain)
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
ifndef HOME
$(error "$$HOME" must be defined)
endif

.DEFAULT_GOAL = simulate-install

SOURCES := $(shell find dot \( -type f -o -type l \) -not -name '.*')

DESTINATIONS = $(SOURCES:dot/%=${HOME}/.%)

${HOME}/.gitconfig:
	./src/gitconfig.sh

EXECUTABLES = $(filter dot/local/bin/%, $(SOURCES))

ifndef REVERSE
$(HOME)/.%: dot/%
	install -D -m $(if $(filter $<, $(EXECUTABLES)), 0755, 0644) $< $@
endif

.PHONY: install simulate-install diff

diff:
	$(MAKE) REVERSE=y reverse-all | less -E

help:
	@echo 'To see all files changed outside the source tree:'
	@echo
	@echo '  make diff'
	@echo
	@echo 'To show the diff of one file (e.g. .xinitrc):'
	@echo
	@echo '  make REVERSE=y dot/xinitrc'
	@echo
	@echo 'To _copy_ from $$HOME/.xinitrc into the source tree:'
	@echo
	@echo '  make REVERSE=y WRITE_REVERSE=y dot/xinitrc'
	@echo

ifdef REVERSE
.PHONY: reverse-all
reverse-all: $(SOURCES)
.FORCE:
$(SOURCES): .FORCE
	@diff -u3 $@ $(@:dot/%=$(HOME)/.%) 2>/dev/null || rsync $(if $(WRITE_REVERSE),,-n) --ignore-missing-args -ui $(@:dot/%=$(HOME)/.%) $@
endif

install: $(DESTINATIONS)

install-packages:
ifeq ($(shell id -u),0)
	install -m0644 eschew-unstable.pref /etc/apt/preferences.d/
	bash install-packages.bash
else
	sudo -- $(MAKE) -$(MAKEFLAGS) $@
endif

simulate-install:
	@echo
	@echo \#\# SIMULATED INSTALL \#\#
	@echo
	@echo run \'make install\' to execute the install commands shown below
	@echo
	@$(MAKE) -n install