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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
.POSIX:
DATE = 1970-01-01
VERSION = 0.1.0
NAME = euandre.org
NAME_UC = $(NAME)
PORT = 3333
LANGUAGES = en
all:
include deps.mk
$(derived-assets): Makefile deps.mk
## ---- what this site has beyond the canonical rules -------------
## The favicons this site renders from img/favicon.svg, rather than
## carrying as sources the way papo.im does: derived, so clean takes
## them.
side-assets += src/content/favicon.ico src/content/favicon.png
side-assets += have.txt want.txt stale.txt kept.txt dirs.txt rmlist.txt
integration-tests = \
.PRECIOUS: $(integration-tests)
$(integration-tests): ALWAYS
sh $@
check-integration: $(integration-tests)
check: check-unit check-integration
i18n:
po4a po/po4a.cfg
run:
serve -n -p $(PORT) -d '$(DESTDIR)$(HTMLDIR)'
want.txt: install.txt
sort install.txt | sed 's|^|/srv/www/|' > $@
## Files and links only: install.txt names no directories, so an
## unfiltered find would call every one of them stale --- /srv/www
## among them.
have.txt:
ssh euandre.org 'find /srv/www \( -type f -o -type l \)' | sort > $@
stale.txt: have.txt want.txt
comm -23 have.txt want.txt > $@
## Which directories the pruning empties: those that held something
## stale and hold nothing that stays. Both are read off the two
## lists already in hand, so nothing has to walk the tree over there
## asking rmdir to refuse most of what it is offered.
##
## In no particular order: rm -rf takes a directory with whatever is
## under it, so a parent reached before its child carries the child
## away and the child's own turn finds nothing left to do. The
## sorting that remains is comm's, which needs both sides ordered.
kept.txt: have.txt want.txt stale.txt
comm -12 have.txt want.txt | ancestors /srv/www | sort -u > $@
dirs.txt: stale.txt kept.txt
ancestors /srv/www < stale.txt | sort -u | comm -23 - kept.txt > $@
rmlist.txt: stale.txt dirs.txt
cat stale.txt dirs.txt > $@
## Prune, then send. Ask the server what it has, take away the list
## "all" already wrote, and delete what is left over; then extract.
##
## Only the stale names go, so a page that stays is never taken from
## under a reader, and there is no moment when the site is missing.
## The comparison is comm here rather than a script over there, and
## every step lands in a file that says what it holds, so what is
## about to be removed can be read before it is.
##
## Emptied by name rather than replaced wholesale: /srv is root's, so
## /srv/www's own directory entry cannot be removed or remade.
upload: rmlist.txt install.tar
cat rmlist.txt | ssh euandre.org xargs rm -rf
cat install.tar | ssh euandre.org tar -xf - -C /srv/www
## Remove all derived artifacts produced during the build.
clean:
rm -rf $(derived-assets) $(side-assets)
## The legacy-URL symlinks sit in directories mkwb symlinks had
## to create; removing the links leaves those empty. Naming
## them drifts the moment a link is added --- which it did ---
## so let rmdir decide: git cannot track an empty directory, so
## under the content root an empty one is always residue.
## -depth walks bottom-up, which is what prunes a whole branch.
find src/content -depth -type d -exec rmdir {} + 2>/dev/null || true
## Install into $(DESTDIR)$(PREFIX) by extracting what "all"
## already packed: the same two tarballs that go to a server, so
## installing next door and deploying across a network are the one
## operation. tar(1) rather than rsync(1), one fewer dependency
## outside the fleet. Unlike rsync --delete it adds without
## pruning --- an install over a tree still holding a page whose
## source is gone leaves that page there --- so install into an
## empty $(DESTDIR), or uninstall first.
install: all
mkdir -p '$(DESTDIR)$(HTMLDIR)' '$(DESTDIR)$(SRCDIR)'
cat install.tar | tar -xf - -C '$(DESTDIR)$(HTMLDIR)'
cat sources.tar | tar -xf - -C '$(DESTDIR)$(SRCDIR)'
## Remove what install placed.
uninstall:
rm -rf \
'$(DESTDIR)$(SRCDIR)' \
'$(DESTDIR)$(HTMLDIR)' \
ALWAYS:
|