-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
182 lines (139 loc) · 5.87 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
OUTDIR?=build
REFSDIR?=$(OUTDIR)/refs
EXAMPLESDIR?=$(OUTDIR)/examples
XMLDEPS=xep.xsd xep.ent xep.dtd ref.xsl
TEXMLDEPS=xep2texml.xsl $(OUTDIR)/xmpp.pdf $(OUTDIR)/xmpp-text.pdf
XEPDIRS=. inbox
HTMLDEPS=xep.xsl $(CSSTARGETS) $(JSTARGETS)
base_CSSTARGETS=xmpp.css prettify.css
CSSTARGETS=$(addprefix $(OUTDIR)/,$(base_CSSTARGETS))
proto_CSSTARGETS=$(addprefix $(OUTDIR)/inbox/,$(base_CSSTARGETS))
base_JSTARGETS=prettify.js
JSTARGETS=$(addprefix $(OUTDIR)/,$(base_JSTARGETS))
proto_JSTARGETS=$(addprefix $(OUTDIR)/inbox/,$(base_JSTARGETS))
proto_HTMLDEPS=xep.xsl $(proto_CSSTARGETS) $(proto_JSTARGETS)
DO_XELATEX=cd $(OUTDIR); xelatex --interaction=nonstopmode -no-shell-escape "$(notdir $(basename $@)).tex" >/dev/null
xeps=$(wildcard *.xml)
proto_xeps=$(wildcard inbox/*.xml)
all_xeps=$(xeps) $(proto_xeps)
xep_xmls=$(patsubst %.xml,$(OUTDIR)/%.xml,$(xeps))
proto_xep_xmls=$(patsubst %.xml,$(OUTDIR)/%.xml,$(proto_xeps))
all_xep_xmls=$(xep_xmls) $(proto_xep_xmls)
xep_ancillary=$(patsubst %,$(OUTDIR)/%,xep.xsl)
xep_htmls=$(patsubst %.xml,$(OUTDIR)/%.html,$(xeps))
proto_xep_htmls=$(patsubst %.xml,$(OUTDIR)/%.html,$(proto_xeps))
all_xep_htmls=$(xep_htmls) $(proto_xep_htmls)
xep_pdfs=$(patsubst %.xml,$(OUTDIR)/%.pdf,$(xeps))
xep_refs=$(patsubst xep-%.xml, $(REFSDIR)/reference.XSF.XEP-%.xml, $(xeps))
xep_examples=$(patsubst xep-%.xml, $(EXAMPLESDIR)/%.xml, $(xeps))
all_xep_check_ok=$(patsubst %.xml, .%.xml.check.ok, $(xeps))
.PHONY: help
help:
@echo 'XEP makefile targets:'
@echo ' '
@echo ' help - (this message)'
@echo ' all - build all XEPs (same as make html)'
@echo ' refs - build all IETF refs'
@echo ' html - build all XEPs'
@echo ' inbox-html - build all ProtoXEPs'
@echo ' check - check all XEPs for errors'
@echo ' clean - recursively unlink the build tree'
@echo ' preview - builds html whenever an XEP changes (requires inotify-tools)'
@echo ' examples - extract all examples'
@echo ' xep-xxxx - build HTML, PDF, examples, and reference for the XEP'
@echo ' xep-xxxx.pdf - build xep-xxxx.pdf (requires xelatex and texml)'
@echo ' xep-xxxx.html - build xep-xxxx.html'
@echo ' '
@echo 'Output directory: "$(OUTDIR)/"'
.PHONY: all
all: html
.PHONY: xeplist
xeplist: $(OUTDIR)/xeplist.xml
.PHONY: html
html: $(xep_htmls)
.PHONY: xml
xml: $(xep_xmls) $(xep_ancillary)
.PHONY: inbox-html
inbox-html: $(proto_xep_htmls)
.PHONY: inbox-xml
inbox-xml: $(OUTDIR)/inbox $(proto_xep_xmls)
.PHONY: pdf
pdf: $(xep_pdfs)
.PHONY: refs
refs: $(xep_refs)
.PHONY: examples
examples: $(xep_examples)
.PHONY: check
check: $(all_xep_check_ok)
.PHONY: xep-%
xep-%: $(OUTDIR)/xep-%.html $(REFSDIR)/reference.XSF.XEP-%.xml $(OUTDIR)/xep-%.pdf $(EXAMPLESDIR)/%.xml;
.PHONY: xep-%.html
xep-%.html: $(OUTDIR)/xep-%.html ;
.PHONY: xep-%.pdf
xep-%.pdf: $(OUTDIR)/xep-%.pdf ;
$(all_xep_xmls): $(OUTDIR)/%.xml: %.xml $(XMLDEPS)
xmllint --nonet --noent --loaddtd --dropdtd $< --output $@
$(OUTDIR)/xep.xsl: xep.xsl $(OUTDIR)
cp $< $@
$(OUTDIR)/xeplist.xml: $(wildcard *.xml) $(wildcard inbox/*.xml) $(OUTDIR)
./tools/extract-metadata.py > $@
$(EXAMPLESDIR)/%.xml: xep-%.xml $(XMLDEPS) examples.xsl | $(EXAMPLESDIR)
xsltproc --path $(CURDIR) examples.xsl "$<" > "$@" && echo "Finished building $@"
$(REFSDIR)/reference.XSF.XEP-%.xml: xep-%.xml $(XMLDEPS) ref.xsl | $(REFSDIR)
xsltproc --path $(CURDIR) ref.xsl "$<" > "$@" && echo "Finished building $@"
.%.xml.check.ok: %.xml
xmllint --nonet --noout --noent --loaddtd --valid "$<"
# Check for non-data URIs, the result set of the XPath expression below should be empty
# Disabled for now, see
# https://github.com/xsf/xeps/issues/1316 and https://gitlab.gnome.org/GNOME/libxml2/-/issues/673
# xmllint --loaddtd --xpath "//img/@src[not(starts-with(., 'data:'))]" $< > /dev/null
touch $@
$(xep_htmls): $(OUTDIR)/xep-%.html: xep-%.xml $(XMLDEPS) $(HTMLDEPS) | $(OUTDIR)
xsltproc --path $(CURDIR) --param htmlbase "$(if $(findstring inbox,$<),'../','./')" xep.xsl "$<" > "$@" && echo "Finished building $@"
$(proto_xep_htmls): $(OUTDIR)/inbox/%.html: inbox/%.xml $(XMLDEPS) $(proto_HTMLDEPS) | $(OUTDIR)
xsltproc --path $(CURDIR) --param htmlbase "$(if $(findstring inbox,$<),'../','./')" xep.xsl "$<" > "$@" && echo "Finished building $@"
$(OUTDIR)/xmpp.pdf $(OUTDIR)/xmpp-text.pdf: | $(OUTDIR)
cp "resources/$(notdir $@)" "$@"
$(OUTDIR)/%.pdf: %.xml $(XMLDEPS) $(TEXMLDEPS)
xsltproc --path $(CURDIR) xep2texml.xsl "$<" > "$(@:.pdf=.tex.xml)"
texml -e utf8 "$(@:.pdf=.tex.xml)" "$(@:.pdf=.tex)"
sed -i -e 's|\([\s"]\)\([^"]http://[^ "]*\)|\1\\path{\2}|g' \
-e 's|\\hyperref\[#\([^}]*\)\]|\\hyperref\[\1\]|g' \
-e 's|\\pageref{#\([^}]*\)}|\\pageref{\1}|g' "$(@:.pdf=.tex)"
while ($(DO_XELATEX) ; \
grep -q "Rerun to get" $(<:.xml=.log) ) do true; \
done
echo "Finished building $@"
$(JSTARGETS): | $(OUTDIR)
cp "$(notdir $@)" "$@"
$(CSSTARGETS): | $(OUTDIR)
cp "$(notdir $@)" "$@"
$(proto_JSTARGETS): | $(OUTDIR)/inbox
cp "$(notdir $@)" "$@"
$(proto_CSSTARGETS): | $(OUTDIR)/inbox
cp "$(notdir $@)" "$@"
$(EXAMPLESDIR) $(REFSDIR) $(OUTDIR) $(OUTDIR)/inbox:
mkdir -p "$@"
.PHONY: clean
clean:
rm -rf $(OUTDIR)
.PHONY: preview
preview: $(OUTDIR)
inotifywait -m -e close_write,moved_to --format '%e %w %f' $(XEPDIRS) | \
while read -r event dir file; do \
if [ "$${file: -4}" == ".xml" ]; then \
xsltproc --path $(CURDIR) xep.xsl "$${dir}/$${file}" > "$(OUTDIR)/$${file%.*}.html" && echo "Built $${file%.*}.html $${event}"; \
fi \
done
.PHONY: docker
docker:
docker build -t xmpp-org/extensions .
.PHONY: dockerhtml
dockerhtml:
docker build -t xmpp-org/extensions . --build-arg NCORES=9 --build-arg TARGETS="html inbox-html"
.PHONY: testdocker
testdocker:
docker run -d --name tmpxeps -p 3080:80 xmpp-org/extensions
.PHONY: stopdocker
stopdocker:
docker stop tmpxeps; docker rm -v tmpxeps