-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
66 lines (59 loc) · 1.57 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
# Author: Eric Pruitt (https://www.codevat.com)
# License: 2-Clause BSD (http://opensource.org/licenses/BSD-2-Clause)
.POSIX:
.SILENT: test-all test-corpora test-width-data wcwidth.awk
AWK = awk
AWKS = \
"busybox awk" \
"env LC_ALL=C gawk --posix" \
"gawk" \
"mawk" \
"original-awk" \
all: test
width-data: generate-width-data.c
$(CC) -o $(<:.c=) $< && ./$(<:.c=) > $@
clean:
rm -f generate-width-data
wcwidth.awk: template.awk width-data
insert=$$( \
grep -v "^-1 " width-data \
| tr "\n" "," \
| fold -w 71 \
| sed -e 's/^.*$$/ "\0" \\\\/' -e '$$s/," \\\\$$/"/' \
) && \
$(AWK) -v insert="$$insert" ' \
/^[ \t]*#.*\[WIDTH DATA\]/ { \
print insert; \
next; \
} \
{ \
print; \
} \
' template.awk > [email protected]
mv [email protected] $@
echo "$@: file generated succesfully"
test-all test-corpora test-width-data: wcwidth.awk
fallback="$(AWK)" && \
for awk in $(AWKS); do \
if ! $$awk "BEGIN { exit }" 2>/dev/null; then \
test "$$fallback" && awk="$$fallback" || continue; \
fi; \
fallback=""; \
using="$$awk -f wcwidth.awk -f test.awk"; \
printf "%s:\n" "$$awk"; \
if [ "$@" = "test-all" ] || [ "$@" = "test-width-data" ]; then \
name="width data invariance"; \
test "$@" = "test-all" || name="sanity check"; \
printf "\055 %s: " "$$name"; \
$$using -v TERSE=1 width-data:width-data; \
echo "OK"; \
fi; \
if [ "$@" = "test-all" ] || [ "$@" = "test-corpora" ]; then \
for path in test-data/*-corpus.text; do \
printf "\055 %s: " "$$path"; \
$$using -v TERSE=1 "$$path"; \
echo "OK"; \
done; \
fi; \
done
test: test-width-data