-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
119 lines (95 loc) · 3.4 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
# jqt management
#
project=jqt
include make.d/config.make
include make.d/debug.make
########################################################################
# Parameters (redefine as you like)
########################################################################
prefix ?= /usr/local
bindir ?= $(prefix)/bin
datadir ?= $(prefix)/share
########################################################################
# Rules
########################################################################
# Configure tools
include make.d/setup.make
# Default target
all: check
########################################################################
# Utilities
########################################################################
.PHONY: clean clobber install uninstall
clean:
rm -f tests/generated/*
clobber: clean
install:
test -d $(bindir) || $(SUDO) mkdir --verbose --parents $(bindir)
test -d $(datadir)/$(project) || $(SUDO) mkdir --verbose --parents $(datadir)/$(project)
$(SUDO) install --verbose --compare --mode 555 bin/* $(bindir)
$(SUDO) install --verbose --compare --mode 644 share/* $(datadir)/$(project)
uninstall:
$(SUDO) rm --verbose --force -- $(addprefix $(prefix)/,$(wildcard bin/*))
test -d $(datadir)/$(project) \
&& $(SUDO) rm --verbose --force --recursive $(datadir)/$(project) \
|| true
# Show targets
.PHONY: help
help:
echo 'Targets:'; \
$(MAKE) --print-data-base --just-print 2>&1 \
| grep -v '^[mM]akefile' \
| awk '/^[^ \t.%][-A-Za-z0-9_]*:/ { print $$1 }' \
| sort --unique \
| sed 's/:\+$$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=4
########################################################################
# Tests
########################################################################
.PHONY: check jqt format cond expr loop macros syntax expand csv yaml
check: expand jqt format
jqt: cond expr loop macros syntax
format: csv yaml
define TestJQT
# Run one example
$(1)-%.jqt:
echo "==> $$(basename $$@)"
if [[ -e tests/$$(basename $$@).json ]]; then \
jqt -ifilters -Ltests/filters -Mtop:tests/$$(basename $$@).json -dtests/md-00.md tests/$$@ tests/generated/$$(basename $$@).txt; \
else \
jqt -ifilters -Ltests/filters -dtests/md-00.md tests/$$@ tests/generated/$$(basename $$@).txt; \
fi
diff tests/expected/$$(basename $$@).txt tests/generated/$$(basename $$@).txt
# Run one example named without file suffix
$(1)-%: $(1)-%.jqt ;
# Run all tests
$(1): $(sort $(subst tests/,,$(wildcard tests/$(1)-[0-9][0-9].jqt)))
endef
$(foreach t,cond expr loop macros syntax,$(eval $(call TestJQT,$(t))))
define TestGPP
# Run one example
$(2)-%.$(1):
echo "==> $$(basename $$@)"
jqt -E tests/$$@ > tests/generated/$$@
diff tests/expected/$$@ tests/generated/$$@
# Run one example named without file suffix
$(2)-%: $(2)-%.$(1) ;
# Run all tests
$(2): $(sort $(subst tests/,,$(wildcard tests/$(2)-[0-9][0-9].$(1))))
endef
$(eval $(call TestGPP,jqt,expand))
define TestFileFormat
# Run one example
$(1)-%.sh:
echo "==> $$(basename $$@)"
$(SHELL) tests/$$@
# Run one example named without file suffix
$(1)-%: $(1)-%.sh ;
# Run all tests
$(1): $(sort $(subst tests/,,$(wildcard tests/$(1)-[0-9][0-9].sh)))
# Check output of all filters is empty for empty input
test -z "$$$$(for f in bin/$(1)2* bin/*2$(1); do echo | $$$$f; done)" \
|| { echo 1>&2 'EMPTY-FAILED'; false; }
endef
$(foreach t,csv yaml,$(eval $(call TestFileFormat,$(t))))
# vim:ai:sw=8:ts=8:noet:syntax=make