-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
139 lines (109 loc) · 3.84 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
all: markdown manpages
release: all AUTHORS.md CHANGELOG.md
INSTALL_PREFIX:=/usr/local
ls_bin :=$(shell find . -maxdepth 1 -executable -type f -printf '%P\n')
ls_bin_sh :=$(shell find . -maxdepth 1 -executable -type f \
-exec sed -n '1s:^\#!.*[ /]sh$$:{}:p' {} \;)
install: install-bin install-man
clean:
rm -f AUTHORS.md
rm -f $(addprefix man/, $(addsuffix .8.gz, $(call ls_bin)))
[ ! -d man ] || rmdir man
for btrfs_mnt in btrfs.working.mnt btrfs-snapshots.working.mnt; do \
! mountpoint -q "/tmp/snazzer-tests/$$btrfs_mnt" || \
umount "/tmp/snazzer-tests/$$btrfs_mnt"; \
done
rm -rf /tmp/snazzer-tests
distclean: clean
rm -f tmp/bin/bats
rm -rf tmp/bats
[ ! -d tmp/bin ] || rmdir tmp/bin
[ ! -d tmp ] || rmdir tmp
test: bats-tests prune-tests
uninstall:
rm -f $(addprefix $(INSTALL_PREFIX)/bin/, $(call ls_bin))
rm -f $(addprefix $(INSTALL_PREFIX)/share/man/man8/, $(addsuffix .8.gz, \
$(call ls_bin)))
install-bin: $(addprefix $(INSTALL_PREFIX)/bin/, $(call ls_bin))
$(INSTALL_PREFIX)/bin/%: %
install -Dm755 $< $@
install-man: $(addprefix $(INSTALL_PREFIX)/share/man/man8/, $(addsuffix .8.gz, \
$(call ls_bin)))
$(INSTALL_PREFIX)/share/man/man8/%.8.gz: man/%.8.gz
install -Dm644 $< $@
bats-tests: | bats
PATH=.:tmp/bin:$$PATH bats tests/
bats:
@PATH=tmp/bin:$$PATH bats --help >/dev/null || (\
mkdir -p tmp/bin;\
[ -f tmp/bats/bin/bats ] ||\
git clone https://github.com/sstephenson/bats tmp/bats;\
ln -s ../bats/bin/bats tmp/bin/;\
)
prune-tests:
./snazzer-prune-candidates --tests
shellcheck-tests: | shellcheck
PATH=~/.cabal/bin:tmp/bin:$$PATH shellcheck $(call ls_bin_sh)
shellcheck:
@PATH=~/.cabal/bin/:$$PATH shellcheck --version >/dev/null || (\
mkdir -p tmp/bin;\
if ! cabal --version >/dev/null; then\
echo "ERROR: Missing cabal. Please install cabal-install" >&2;\
exit 1;\
fi;\
cabal update;\
cabal install ShellCheck;\
)
markdown: $(addprefix docs/, $(addsuffix .md, $(call ls_bin)))
docs/%.md: % | docs
./$< --man-markdown >$@
docs:
mkdir $@
manpages: $(addprefix man/, $(addsuffix .8.gz, $(call ls_bin)))
man/%.8.gz: % | man
./$< --man-roff | gzip >$@
man:
mkdir $@
AUTHORS.md:
echo "SNAZZER AUTHORS" > $@
echo "===============" >>$@
echo >>$@
echo "Compiled automatically from git history, in alphabetical order:" >> $@
echo >>$@
git log --format='- %aN <%aE>' | \
sort -u |grep -v 'Paul.W Harvey <[email protected]>' >> $@
# Print "0.0.1" from "v0.0.1-2-g4cb93f4", see also: tests/fixtures.sh
define git-describe-snazzer-version
$(shell git describe --tags | sed -n 's/v\?\([0-9.]*\).*/\1/p')
endef
define snazzer-version-escaped
$(subst .,\.,$(call git-describe-snazzer-version))
endef
# Sanity-check the changelog
CHANGELOG.md:
@echo "Building snazzer version $(call git-describe-snazzer-version)"
@printf "Checking there's a $@ entry for this version:\n "
@grep '^## $(call snazzer-version-escaped) - ' $@
@printf "Checking the [Unreleased] URL:\n "
@grep '^\[Unreleased\]: https://github.com/csirac2/snazzer/compare/v$(call \
snazzer-version-escaped)...HEAD' $@
.PHONY: CHANGELOG.md
# assumes "#!/usr/bin/env foo", rewrites to "#!/path/to/foo"
rewrite-shebangs-to-bin:
for script in $(call ls_bin);\
do\
script_bin=$$(sed -n '1s:.*[ /][ /]*\([^ /]*\)$$:\1:p' "$$script");\
sed -i "1s:.*[ /][ /]*\([^ /]*\)$$:#\!$$(which $$script_bin):g"\
"$$script";\
done
# assumes "#!/path/to/foo", rewrites to "#!/usr/bin/env foo"
rewrite-shebangs-to-env:
for script in $(call ls_bin);\
do\
script_bin=$$(sed -n '1s:.*[ /][ /]*\([^ /]*\)$$:\1:p' "$$script");\
sed -i "1s:.*[ /][ /]*\([^ /]*\)$$:#\!/usr/bin/env $$script_bin:g"\
"$$script";\
done
.PHONY: install uninstall install-bin install-man markdown manpages
.PHONY: all release clean distclean test bats-tests bats prune-tests
.PHONY: rewrite-shebangs-to-bin rewrite-shebangs-to-env