-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
219 lines (184 loc) · 9.39 KB
/
Copy pathMakefile
File metadata and controls
219 lines (184 loc) · 9.39 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
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
212
213
214
215
216
217
218
219
CONTRIBUTION = "lua-placeholders-$(shell git describe --tags --always).tar.gz"
PACKAGE_DIR = ${CURDIR}
CNF_LINE = -cnf-line shell_escape_commands=git
COMPILE = lualatex --interaction=nonstopmode --shell-restricted $(CNF_LINE)
RM = rm
ifeq ($(OS),Windows_NT)
RM = del
endif
export TEXINPUTS := $(PACKAGE_DIR)/tex//:
export LUAINPUTS := $(PACKAGE_DIR)/scripts//:
TEXMFHOME := $(HOME)/src/texmf-packaging
export TEXMFHOME
TEST_BUILD_DIR := $(PACKAGE_DIR)/test/build
TEST_EXPECTED := $(PACKAGE_DIR)/test/expected/example.txt
EXAMPLE_DIR := doc/lua-placeholders-example
.PHONY: doc/lua-placeholders-manual.pdf doc/lua-placeholders-example/example.pdf \
test test-example test-update test-clean
all: build clean
package: $(CONTRIBUTION)
build: doc/lua-placeholders-manual.pdf
clean:
cd doc && latexmk -c lua-placeholders-manual
cd doc/lua-placeholders-example && latexmk -c example
clean-all:
cd doc && latexmk -C lua-placeholders-manual
cd doc/lua-placeholders-example && latexmk -C example
doc/lua-placeholders-example/example.pdf: doc/lua-placeholders-example/example.tex tex/lua-placeholders.sty $(wildcard scripts/*.lua)
@echo "Creating example PDF"
cd doc/lua-placeholders-example && \
$(COMPILE) example
doc/lua-placeholders-manual.pdf: doc/lua-placeholders-example/example.pdf doc/lua-placeholders-manual.tex tex/lua-placeholders.sty $(wildcard scripts/*.lua)
@echo "Creating documentation PDF"
cd doc && \
$(COMPILE) lua-placeholders-manual && \
biber lua-placeholders-manual && \
$(COMPILE) lua-placeholders-manual && \
$(COMPILE) lua-placeholders-manual
$(CONTRIBUTION): doc/lua-placeholders-manual.pdf clean
@echo "Creating package tarball"
tar --transform 's,^\.,lua-placeholders,' \
--exclude=doc/.latexmkrc \
-czvf $(CONTRIBUTION) ./README.md ./doc ./scripts ./tex
test: test-example test-tables test-lists test-objects test-complex test-complex-empty test-luatex test-parse-filename
# ---------------------------------------------------------------------------
# Plain-Lua unit test for namespace.parse_filename. Runs the script under
# `lua` (no LuaTeX needed)
# ---------------------------------------------------------------------------
test-parse-filename:
@cd $(PACKAGE_DIR) && lua test/unit/parse-filename.lua
# ---------------------------------------------------------------------------
# Per-type case tests live under test/cases/<name>.tex (with sibling
# <name>-spec.yaml / <name>-payload.yaml). Same compile + normalise +
# diff pipeline as the rich example test.
# ---------------------------------------------------------------------------
TEST_CASES_DIR := $(PACKAGE_DIR)/test/cases
$(TEST_BUILD_DIR)/tables.pdf: $(TEST_CASES_DIR)/tables.tex \
$(TEST_CASES_DIR)/tables-spec.yaml \
$(TEST_CASES_DIR)/tables-payload.yaml \
tex/lua-placeholders.sty \
$(wildcard scripts/*.lua)
@mkdir -p $(TEST_BUILD_DIR)
cd $(TEST_CASES_DIR) && \
$(COMPILE) -output-directory=$(TEST_BUILD_DIR) tables
$(TEST_BUILD_DIR)/tables.txt: $(TEST_BUILD_DIR)/tables.pdf
pdftotext -layout $< $@.raw
sed -E \
-e 's|version [^ ]+ written on [0-9]{4}[-/][0-9]{2}[-/][0-9]{2}|version <VERSION> written on <DATE>|' \
-e 's|^[[:space:]]+[A-Z][a-z]+ [0-9]{1,2}, [0-9]{4}[[:space:]]*$$| <DATE>|' \
-e 's|^[[:space:]]+[0-9]{1,2}(st\|nd\|rd\|th) [A-Z][a-z]+ [0-9]{4}[[:space:]]*$$| <DATE>|' \
-e 's|^[[:space:]]+[0-9]{1,2} [a-z]+ [0-9]{4}[[:space:]]*$$| <DATE>|' \
$@.raw > $@
@$(RM) $@.raw
test-tables: $(TEST_BUILD_DIR)/tables.txt
@if [ ! -f $(PACKAGE_DIR)/test/expected/tables.txt ]; then \
echo "No expected file at test/expected/tables.txt."; \
echo "Run 'make test-tables-update' once to seed it, then commit."; \
exit 1; \
fi
@diff -u $(PACKAGE_DIR)/test/expected/tables.txt $< && echo "OK: tables matches"
test-tables-update: $(TEST_BUILD_DIR)/tables.txt
@mkdir -p $(PACKAGE_DIR)/test/expected
cp $< $(PACKAGE_DIR)/test/expected/tables.txt
@echo "Tables expected file updated"
# ---------------------------------------------------------------------------
# Generic per-case rule. For test/cases/<name>.tex with sibling YAML files,
# defining a make target test-<name> compiles, normalises, and diffs.
# ---------------------------------------------------------------------------
define CASE_template
$$(TEST_BUILD_DIR)/$(1).pdf: $$(TEST_CASES_DIR)/$(1).tex \
$$(wildcard $$(TEST_CASES_DIR)/$(1)-*.yaml) \
tex/lua-placeholders.sty \
$$(wildcard scripts/*.lua)
@mkdir -p $$(TEST_BUILD_DIR)
cd $$(TEST_CASES_DIR) && \
$$(COMPILE) -output-directory=$$(TEST_BUILD_DIR) $(1)
$$(TEST_BUILD_DIR)/$(1).txt: $$(TEST_BUILD_DIR)/$(1).pdf
pdftotext -layout $$< $$@.raw
sed -E \
-e 's|version [^ ]+ written on [0-9]{4}[-/][0-9]{2}[-/][0-9]{2}|version <VERSION> written on <DATE>|' \
-e 's|^[[:space:]]+[A-Z][a-z]+ [0-9]{1,2}, [0-9]{4}[[:space:]]*$$$$| <DATE>|' \
-e 's|^[[:space:]]+[0-9]{1,2}(st\|nd\|rd\|th) [A-Z][a-z]+ [0-9]{4}[[:space:]]*$$$$| <DATE>|' \
-e 's|^[[:space:]]+[0-9]{1,2} [a-z]+ [0-9]{4}[[:space:]]*$$$$| <DATE>|' \
$$@.raw > $$@
@$$(RM) $$@.raw
test-$(1): $$(TEST_BUILD_DIR)/$(1).txt
@if [ ! -f $$(PACKAGE_DIR)/test/expected/$(1).txt ]; then \
echo "No expected file at test/expected/$(1).txt."; \
echo "Run 'make test-$(1)-update' once to seed it, then commit."; \
exit 1; \
fi
@diff -u $$(PACKAGE_DIR)/test/expected/$(1).txt $$< && echo "OK: $(1) matches"
test-$(1)-update: $$(TEST_BUILD_DIR)/$(1).txt
@mkdir -p $$(PACKAGE_DIR)/test/expected
cp $$< $$(PACKAGE_DIR)/test/expected/$(1).txt
@echo "$(1) expected file updated"
endef
$(eval $(call CASE_template,lists))
$(eval $(call CASE_template,objects))
$(eval $(call CASE_template,complex))
$(eval $(call CASE_template,complex-empty))
# ---------------------------------------------------------------------------
# Plain LuaTeX target. Compiled with `luatex` (not lualatex), no LaTeX
# format and no .sty -- exercises tex/lua-placeholders.tex.
# ---------------------------------------------------------------------------
TEST_LUATEX_DIR := $(PACKAGE_DIR)/test/luatex
LUATEX_COMPILE := luatex --interaction=nonstopmode --shell-restricted
$(TEST_BUILD_DIR)/basic.pdf: $(TEST_LUATEX_DIR)/basic.tex \
$(TEST_LUATEX_DIR)/basic-spec.yaml \
$(TEST_LUATEX_DIR)/basic-payload.yaml \
tex/lua-placeholders.tex \
$(wildcard scripts/*.lua)
@mkdir -p $(TEST_BUILD_DIR)
cd $(TEST_LUATEX_DIR) && \
$(LUATEX_COMPILE) -output-directory=$(TEST_BUILD_DIR) basic
$(TEST_BUILD_DIR)/basic.txt: $(TEST_BUILD_DIR)/basic.pdf
pdftotext -layout $< $@
test-luatex: $(TEST_BUILD_DIR)/basic.txt
@if [ ! -f $(PACKAGE_DIR)/test/expected/basic.txt ]; then \
echo "No expected file at test/expected/basic.txt."; \
echo "Run 'make test-luatex-update' once to seed it, then commit."; \
exit 1; \
fi
@diff -u $(PACKAGE_DIR)/test/expected/basic.txt $< && echo "OK: luatex basic matches"
test-luatex-update: $(TEST_BUILD_DIR)/basic.txt
@mkdir -p $(PACKAGE_DIR)/test/expected
cp $< $(PACKAGE_DIR)/test/expected/basic.txt
@echo "luatex basic expected file updated"
# complex.tex and complex-empty.tex share complex-body.tex; complex-empty
# also reuses complex-spec.yaml (the wildcard captures only complex-empty-*).
$(TEST_BUILD_DIR)/complex.pdf: $(TEST_CASES_DIR)/complex-body.tex
$(TEST_BUILD_DIR)/complex-empty.pdf: $(TEST_CASES_DIR)/complex-body.tex \
$(TEST_CASES_DIR)/complex-spec.yaml
$(TEST_BUILD_DIR)/example.pdf: $(EXAMPLE_DIR)/example.tex \
$(EXAMPLE_DIR)/example.yaml \
$(EXAMPLE_DIR)/example-specification.yaml \
tex/lua-placeholders.sty \
$(wildcard scripts/*.lua)
@mkdir -p $(TEST_BUILD_DIR)
cd $(EXAMPLE_DIR) && \
$(COMPILE) -output-directory=$(TEST_BUILD_DIR) example
$(TEST_BUILD_DIR)/example.txt: $(TEST_BUILD_DIR)/example.pdf
pdftotext -layout $< $@.raw
sed -E \
-e 's|version [^ ]+ written on [0-9]{4}[-/][0-9]{2}[-/][0-9]{2}|version <VERSION> written on <DATE>|' \
-e 's|^[[:space:]]+[A-Z][a-z]+ [0-9]{1,2}, [0-9]{4}[[:space:]]*$$| <DATE>|' \
-e 's|^[[:space:]]+[0-9]{1,2}(st\|nd\|rd\|th) [A-Z][a-z]+ [0-9]{4}[[:space:]]*$$| <DATE>|' \
-e 's|^[[:space:]]+[0-9]{1,2} [a-z]+ [0-9]{4}[[:space:]]*$$| <DATE>|' \
-e 's|^([[:space:]]+).+\xe2\x8c\xa9.+\xe2\x8c\xaa[[:space:]]*$$|\1<AUTHOR>|' \
$@.raw > $@
@$(RM) $@.raw
test-example: $(TEST_BUILD_DIR)/example.txt
@if [ ! -f $(TEST_EXPECTED) ]; then \
echo "No example file at $(TEST_EXPECTED)."; \
echo "Run 'make test-update' once to seed it, then commit."; \
exit 1; \
fi
@diff -u $(TEST_EXPECTED) $< && echo "OK: example matches"
test-update: $(TEST_BUILD_DIR)/example.txt
@mkdir -p $(dir $(TEST_EXPECTED))
cp $< $(TEST_EXPECTED)
@echo "Example file updated: $(TEST_EXPECTED)"
@echo "Inspect with: git diff $(TEST_EXPECTED)"
test-clean:
$(RM) -rf $(TEST_BUILD_DIR)