~smlavine/dots

ref: 9a16213514f293447bfe6e755d4f4505c6dc8db6 dots/Makefile -rw-r--r-- 1.2 KiB
9a162135Sebastian LaVine Add qutebrowser config 4 months ago
                                                                                
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
.POSIX:

all: install

install:
	# First, create any necessary directories.
	# awk is used to prepend $HOME instead of sed to avoid sed's delimiter
	# collision.
	find src -mindepth 1 -type d | sed 's/^src//' | \
		awk -v home="$(HOME)" '{ print "\"" home $$0 "\"" }' | \
		xargs mkdir -pv
	# Next, copy all files to their locations in $HOME.
	# 'sed p' repeats each line. The awk command prepends $HOME to make a
	# path to the file's destination. The paste command combines the two
	# lines together.
	find src -mindepth 1 -type f | sed p | \
		awk -v home="$(HOME)" \
		'NR%2==1 { print "cp -v -T " $$0 } \
		NR%2==0 { sub("^src",""); print "\"" home $$0 "\"" }' | \
		paste -d' ' - - | sh

uninstall:
	# The order of commands is reversed from that in install, because we
	# only want to remove empty directories, for safety's sake.
	find src -mindepth 1 -type f | \
		awk -v home="$(HOME)" \
		'{ sub("^src",""); print "rm -v " "\"" home $$0 "\"" }' | sh
	# Child directories echo first (-depth) so that parent directories are
	# emptied before removed.
	find src -mindepth 2 -type d -depth | sed 's/^src//' | \
		awk -v home="$(HOME)" '{ print "\"" home $$0 "\"" }' | \
		xargs rmdir -v

.PHONY: all install uninstall