-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
211 lines (172 loc) · 6.77 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# jqt management
#
project := jqt
########################################################################
# Parameters (redefine as you like)
########################################################################
prefix ?= /usr/local
bindir ?= $(prefix)/bin
datadir ?= $(prefix)/share
mandir ?= $(prefix)/share/man
########################################################################
# Prerequisites
########################################################################
# We are using some of the newest GNU Make features... so require GNU
# Make version >= 3.82
version_test := $(filter 3.82,$(firstword $(sort $(MAKE_VERSION) 3.82)))
ifndef version_test
$(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed)
endif
# Paranoia
ifeq (0,$(shell id --user))
ifeq (,$(filter install uninstall,$(MAKECMDGOALS)))
$(error Root only can make "(un)install" targets)
endif
SUDO :=
else
SUDO := sudo
endif
########################################################################
# Configuration
########################################################################
# Disable builtins.
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
# Warn when an undefined variable is referenced.
MAKEFLAGS += --warn-undefined-variables
# Make will not print the recipe used to remake files.
.SILENT:
# Eliminate use of the built-in implicit rules. Also clear out the
# default list of suffixes for suffix rules.
.SUFFIXES:
# Sets the default goal to be used if no targets were specified on the
# command line.
.DEFAULT_GOAL := all
# When it is time to consider phony targets, make will run its recipe
# unconditionally, regardless of whether a file with that name exists or
# what its last-modification time is.
.PHONY: all
# When a target is built all lines of the recipe will be given to a
# single invocation of the shell.
# !!!Does not work in make <= 3.82 event it is documented!!!
#.ONESHELL:
# Default shell: if we require GNU Make, why not require Bash?
SHELL := /bin/bash
# The argument(s) passed to the shell are taken from the variable
# .SHELLFLAGS.
.SHELLFLAGS := -o errexit -o pipefail -o nounset -c
# Make will delete the target of a rule if it has changed and its recipe
# exits with a nonzero exit status.
.DELETE_ON_ERROR:
########################################################################
# Rules
########################################################################
# Warning: only `dnf`! Use this rule as template to your own script.
setup:
@rpm -q --quiet general-purpose-preprocessor || sudo dnf -y install general-purpose-preprocessor
@rpm -q --quiet jq || sudo dnf -y install jq
@rpm -q --quiet pandoc || sudo dnf -y install pandoc
@test -d /usr/share/doc/PyYAML || sudo dnf -y install PyYAML
# Default target
all: check
########################################################################
# Utilities
########################################################################
.PHONY: clean clobber install uninstall
clean:
rm -f tests/generated/* jqt.1.gz
clobber: clean
install:
[[ -e jqt.1.gz ]] || { cd docs && make ../jqt.1.gz; }
test -d $(bindir) || $(SUDO) mkdir --verbose --parents $(bindir)
test -d $(datadir)/$(project) || $(SUDO) mkdir --verbose --parents $(datadir)/$(project)
test -d $(mandir)/man1 || $(SUDO) mkdir --verbose --parents $(mandir)/man1
$(SUDO) install --verbose --compare --mode 555 bin/* $(bindir)
$(SUDO) install --verbose --compare --mode 644 share/* $(datadir)/$(project)
$(SUDO) install --verbose --compare --mode 644 jqt.1.gz $(mandir)/man1
uninstall:
$(SUDO) rm --verbose --force -- $(addprefix $(prefix)/,$(wildcard bin/*))
$(SUDO) rm --verbose --force -- $(mandir)/man1/jqt.1.gz
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
check: test-jqt test-expand test-format
#
# Test JQT
#
.PHONY: test-jqt test-cond test-expr test-loop test-macros test-syntax
test-jqt: test-cond test-expr test-loop test-macros test-syntax
define TestJQT
# Run one example
test-$(1)-%.jqt:
echo "==> jqt: $$(subst test-,,$$(basename $$@))"
if test -e tests/jqt/$$(subst test-,,$$(basename $$@)).json; then \
jqt -ifilters -Ltests/jqt/filters -Mtop:tests/jqt/$$(subst test-,,$$(basename $$@)).json -dtests/jqt/md-00.md tests/jqt/$$(subst test-,,$$@) tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt; \
else \
jqt -ifilters -Ltests/jqt/filters -dtests/jqt/md-00.md tests/jqt/$$(subst test-,,$$@) tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt; \
fi
diff tests/jqt/expected/$$(subst test-,,$$(basename $$@)).txt tests/jqt/generated/$$(subst test-,,$$(basename $$@)).txt
# Run one example named without file suffix
test-$(1)-%: test-$(1)-%.jqt ;
# Run all tests
test-$(1): $(sort $(subst tests/jqt/,test-,$(wildcard tests/jqt/$(1)-[0-9][0-9].jqt)))
endef
$(eval $(call TestJQT,cond))
$(eval $(call TestJQT,expr))
$(eval $(call TestJQT,loop))
$(eval $(call TestJQT,macros))
$(eval $(call TestJQT,syntax))
#
# Test macro expansion
#
.PHONY: test-expand test-mpjqt
test-expand: test-mpjqt test-mpmd test-mpjson
define TestMacroExpand
# Run one example
test-$(2)-%.$(1):
echo "==> expand: $$(subst test-,,$$(basename $$@))"
jqt -P $(1) tests/expand/$$(subst test-,,$$@) > tests/expand/generated/$$(subst test-,,$$@)
diff tests/expand/expected/$$(subst test-,,$$@) tests/expand/generated/$$(subst test-,,$$@)
# Run one example named without file suffix
test-$(2)-%: test-$(2)-%.$(1) ;
# Run all tests
test-$(2): $(sort $(subst tests/expand/,test-,$(wildcard tests/expand/$(2)-[0-9][0-9].$(1))))
endef
$(eval $(call TestMacroExpand,jqt,mpjqt))
$(eval $(call TestMacroExpand,md,mpmd))
$(eval $(call TestMacroExpand,json,mpjson))
#
# Test file format conversions
#
.PHONY: test-format test-csv test-yaml
test-format: test-csv test-yaml
define TestFileFormat
# Run one example
test-$(1)-%.sh:
echo "==> format: $$(subst test-,,$$(basename $$@))"
$(SHELL) tests/format/$$(subst test-,,$$@)
# Run one example named without file suffix
test-$(1)-%: test-$(1)-%.sh ;
# Run all tests
test-$(1): $(sort $(subst tests/format/,test-,$(wildcard tests/format/$(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
$(eval $(call TestFileFormat,csv))
$(eval $(call TestFileFormat,yaml))
# vim:ai:sw=8:ts=8:noet:syntax=make