summaryrefslogtreecommitdiff
path: root/Makefile
blob: 5e70c84c6528f6d8d80ff291dcf37ac18ad2098c (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
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)/.%) || rsync $(if $(WRITE_REVERSE),,-n) -ui $(@:dot/%=$(HOME)/.%) $@
endif

install: $(DESTINATIONS)

simulate-install:
	$(MAKE) -n install