forked from legionus/libshell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
150 lines (119 loc) · 4.8 KB
/
Makefile
File metadata and controls
150 lines (119 loc) · 4.8 KB
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
140
141
142
143
144
145
146
147
148
149
150
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
mandocs_TARGETS = $(wildcard mans/shell-*.scd)
docs_TARGETS = mans/libshell.scd $(mandocs_TARGETS)
man_TARGETS = $(docs_TARGETS:.scd=.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: %.scd
@[ -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_SHELL =
CHECK_SHELL += /bin/sh # POSIX Shell
CHECK_SHELL += /bin/dash # Debian Almquist Shell (https://git.kernel.org/pub/scm/utils/dash/dash.git)
CHECK_SHELL += /bin/bash /bin/bash3 /bin/bash4 # GNU Bourne-Again Shell (https://git.savannah.gnu.org/cgit/bash.git)
CHECK_SHELL += /bin/mksh /bin/lksh # MirBSD Korn Shell (https://mbsd.evolvis.org/mksh.htm)
check-tests:
@cd tests; rc=0; \
for TEST_SHELL in $(wildcard $(CHECK_SHELL)); do export TEST_SHELL; \
echo "Running tests with $$TEST_SHELL"; \
if ! $$TEST_SHELL -efu ./runtests; then \
echo >&2 "ERROR: tests failed."; \
echo; \
rc=1; \
fi; \
done; \
exit $$rc;
check-documented:
@sed -n -e 's/^## \([^[:space:]]\+\)$$/\1/p' ${mandocs_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"; \
rc=1; \
else \
echo "All functions are documented."; \
fi; \
echo; \
rm -f -- \
"$(CURDIR)/.shell-funcs-documented" \
"$(CURDIR)/.shell-funcs-not-documented" \
"$(CURDIR)/.shell-funcs"; \
exit $$rc;
check: check-tests check-documented
NULL =
SPACE = $(NULL) $(NULL)
COMMA = ,
DISABLE_SHELLCHECK =
DISABLE_SHELLCHECK += SC1090 # (warning): ShellCheck can't follow non-constant source. Use a directive to specify location.
DISABLE_SHELLCHECK += SC1091 # (info): Not following: file was not specified as input (see shellcheck -x).
DISABLE_SHELLCHECK += SC2004 # (style): $/${} is unnecessary on arithmetic variables.
DISABLE_SHELLCHECK += SC2015 # (info): Note that A && B || C is not if-then-else. C may run when A is true.
DISABLE_SHELLCHECK += SC2034 # (warning): foo appears unused. Verify it or export it.
DISABLE_SHELLCHECK += SC2086 # (info): Double quote to prevent globbing and word splitting.
DISABLE_SHELLCHECK += SC2154 # (warning): variable is referenced but not assigned.
DISABLE_SHELLCHECK += SC2295 # (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.
DISABLE_SHELLCHECK += SC2329 # (info): This function is never invoked. Check usage (or ignored if invoked indirectly).
verify:
@for f in ${bin_TARGETS}; do \
ftype=$$(file -b "$$f"); \
[ -z "$${ftype##*shell script*}" ] || continue; \
echo "Checking $$f"; \
shellcheck -s dash -e $(subst $(SPACE),$(COMMA),$(sort $(DISABLE_SHELLCHECK))) "$$f"; \
done
clean: $(SUBDIRS)
$(RM) -- ${man_TARGETS} ${capability_TARGETS} shell-lib DEPS SYMS