-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
126 lines (100 loc) · 3.41 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
GEN_DEPS = $(CURDIR)/gen-deps.sh
GEN_SYMS = $(CURDIR)/gen-syms.sh
GEN_SINGLE = $(CURDIR)/gen-single.sh
GEN_VERS = $(CURDIR)/gen-version.sh
# https://git.sr.ht/~sircmpwn/scdoc
SCDOC ?= scdoc
PROJECT = libshell
VERSION = $(shell $(GEN_VERS))
DESTDIR ?=
datadir ?= /usr/share
man3dir ?= ${datadir}/man/man3
bindir ?= /bin
SUBDIRS = utils
capability_TARGETS = shell-regexp
bin_TARGETS = $(filter-out shell-lib,$(wildcard shell-*))
data_TARGETS = COPYING
mddocs_TARGETS = $(wildcard docs/shell-*.md)
docs_TARGETS = docs/libshell.md $(mddocs_TARGETS)
man_TARGETS = $(docs_TARGETS:.md=.3)
.PHONY: $(SUBDIRS)
all: ${bin_TARGETS} ${man_TARGETS} ${capability_TARGETS} DEPS SYMS $(SUBDIRS)
DEPS:
PATH="$(CURDIR):$(PATH)" $(GEN_DEPS) ${bin_TARGETS} > $@
SYMS:
PATH="$(CURDIR):$(PATH)" $(GEN_SYMS) ${bin_TARGETS} > $@
shell-lib: ${bin_TARGETS}
PATH="$(CURDIR):$(PATH)" $(GEN_SINGLE) ${bin_TARGETS} > $@
shell-regexp: shell-quote
ln -s -- $^ $@
%.3: %.md
@[ -z "$(SCDOC)" ] || $(SCDOC) < $< > $@
man: ${man_TARGETS}
install: install-bin install-man install-data $(SUBDIRS)
install-data: DEPS SYMS
install -d -m755 ${DESTDIR}${datadir}/${PROJECT}
cp $^ ${DESTDIR}${datadir}/${PROJECT}/
install-single: shell-lib
install -d -m755 ${DESTDIR}${bindir}
cp $^ ${DESTDIR}${bindir}/
install-bin: ${bin_TARGETS}
install -d -m755 ${DESTDIR}${bindir}
cp -a $^ ${DESTDIR}${bindir}/
install-man: ${man_TARGETS}
if [ -n "$(SCDOC)" ]; then \
install -d -m755 ${DESTDIR}${man3dir}; \
install -m644 $^ ${DESTDIR}${man3dir}; \
fi
$(SUBDIRS):
$(MAKE) $(MFLAGS) -C "$@" $(MAKECMDGOALS)
$(PROJECT)-$(VERSION).tar.xz:
tar --transform='s,^,$(PROJECT)-$(VERSION)/,' -Jcf $@ \
shell-* gen-* contrib tests docs LICENSE COPYING Makefile
$(PROJECT)-$(VERSION).tar.sign: $(PROJECT)-$(VERSION).tar.xz
xz -d -c $^ | \
gpg --armor --detach-sign \
--default-key $(GPG_KEY) \
--output $@
tar: $(PROJECT)-$(VERSION).tar.xz
release: $(PROJECT)-$(VERSION).tar.sign
check:
@cd tests; \
for sh in $${CHECK_SHELL:-/bin/sh /bin/dash /bin/bash /bin/bash3 /bin/bash4 /bin/mksh /bin/yash /bin/pdksh}; do \
[ -x "$$sh" ] || continue; \
echo "Running tests with $$sh"; \
if ! "$$sh" -efu ./runtests; then \
echo "Tests failed with $$sh"; \
echo; \
exit 1; \
fi; \
done
@sed -n -e 's/^## \([^[:space:]]\+\)$$/\1/p' ${mddocs_TARGETS} |sort -uo "$(CURDIR)/.shell-funcs-documented"
@sed -n -e 's/^\([A-Za-z][A-Za-z0-9_]\+\)().*/\1/p' ${bin_TARGETS} |sort -uo "$(CURDIR)/.shell-funcs"
@comm -13 \
"$(CURDIR)/.shell-funcs-documented" \
"$(CURDIR)/.shell-funcs" \
> "$(CURDIR)/.shell-funcs-not-documented"; \
rc=0; \
if [ "$$(wc -l < "$(CURDIR)/.shell-funcs-not-documented")" != "0" ]; then \
echo >&2 "ERROR: some functions are not documented:"; \
cat "$(CURDIR)/.shell-funcs-not-documented"; \
echo; \
rc=1; \
else \
echo "All functions are documented."; \
echo; \
fi; \
rm -f -- \
"$(CURDIR)/.shell-funcs-documented" \
"$(CURDIR)/.shell-funcs-not-documented" \
"$(CURDIR)/.shell-funcs"; \
exit $$rc;
verify:
@for f in ${bin_TARGETS}; do \
ftype=$$(file -b "$$f"); \
[ -z "$${ftype##*shell script*}" ] || continue; \
echo "Checking $$f"; \
shellcheck -s dash -e SC1090,SC1091,SC2004,SC2015,SC2034,SC2086,SC2154 "$$f"; \
done
clean: $(SUBDIRS)
$(RM) -- ${man_TARGETS} ${capability_TARGETS} shell-lib DEPS SYMS