summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/unicode-math/Makefile
blob: c85ecdb407b15a6d83674d4d22c9170867a7278d (plain)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

#### MAKEFILE CONFIG ####

SHELL = /bin/sh
.SILENT:
.SUFFIXES:

#### BEGIN ####

help:
	echo 'UNICODE-MATH makefile targets:'
	echo ' '
	echo '                  help  -  (this message)'
	echo '                  ctan  -  generate archive for CTAN'
	echo '                   doc  -  compile documentation inside build/'
	echo '                 clean  -  remove build directory and compiled files'
	echo ' '
	echo '               install  -  install the package into your home texmf tree'
	echo '           install-sys  -  install the package into the system-wide texmf tree'
	echo '                           (may require administration privileges)'
	echo ' install TEXMF=<texmf>  -  install the package into the path <texmf>'
	echo ' '
	echo '                  test  -  run the test suite'
	echo '               initest  -  initialise any new tests'
	echo ' '
	echo '         xfile F=<abc>  -  compile file <abc> with XeLaTeX'
	echo '         lfile F=<abc>  -  compile file <abc> with LuaLaTeX'
	echo ' '
	echo 'To add a new test, add a file called umtest****.ltx to'
	echo 'directory testfiles/,  run `make initest` and ensure'
	echo 'that the output umtest****.safe.png is correct.'
	echo ' '
	echo '`make test` will then compare future compilations of the'
	echo 'test file against this original and warn against any changes.'
	echo '`make build/umtest****.diff.png` will check a single test.'
	echo ' '
	echo 'I recommend `make -j4 test` or thereabouts to parallelise'
	echo 'the testing.'



#### SETUP ####

# file and folder names:

PKG = unicode-math
TBL = $(PKG)-table.tex
SUITE = $(PKG)-testsuite
XMPL = unimath-example.ltx
SYM = unimath-symbols

testdir=testfiles
builddir=build
tds=$(builddir)/$(PKG).tds

UPDATE = `which dtx-update` || true  # TODO: generalise

# these files end up in the CTAN directory:
PKGSOURCE = $(PKG).dtx $(TBL) Makefile
DOC     = $(PKG).pdf $(SUITE).pdf README $(XMPL) $(SYM).pdf
CTANFILES = $(PKGSOURCE)  $(DOC)  ../$(testdir)
BUILDCTAN = $(addprefix $(builddir)/,$(CTANFILES))
BUILDDOC = $(addprefix $(builddir)/,$(DOC))

# these are what's needed to compile and make stuff:

LTXSOURCE = $(PKG).sty $(TBL)

SUITESOURCE = \
  $(testdir)/umtest-preamble.tex \
  $(testdir)/umtest-suite.tex

SWEETSAUCE = ginger and chilli

TESTOUT = $(shell ls $(testdir)/umtest*.safe.png)
BUILDTESTSRC = $(subst $(testdir)/,$(builddir)/,$(subst .safe.png,.ltx,$(TESTOUT)))
BUILDTESTTARGET = $(subst $(testdir)/,$(builddir)/,$(subst .safe.png,.diff.png,$(TESTOUT)))

BUILDSOURCE = $(addprefix $(builddir)/,$(LTXSOURCE))
BUILDSUITE  = $(subst $(testdir)/,$(builddir)/,$(SUITESOURCE))
BUILDFILES  = $(BUILDSOURCE) $(BUILDSUITE) $(BUILDTESTSRC)

# and this is how the TDS zip file is produced:

TDSFILES = \
	$(tds)/source/latex/$(PKG)/$(PKG).dtx \
	$(tds)/source/latex/$(PKG)/$(SUITE).ltx \
	$(tds)/source/latex/$(PKG)/$(SYM).ltx \
	$(tds)/source/latex/$(PKG)/Makefile \
	$(tds)/source/latex/$(PKG)/$(testdir) \
	$(tds)/doc/latex/$(PKG)/unicode-math.pdf \
	$(tds)/doc/latex/$(PKG)/unicode-math-testsuite.pdf \
	$(tds)/doc/latex/$(PKG)/README \
	$(tds)/doc/latex/$(PKG)/$(XMPL) \
	$(tds)/doc/latex/$(PKG)/$(SYM).pdf \
	$(tds)/tex/latex/$(PKG)/unicode-math.sty \
	$(tds)/tex/latex/$(PKG)/unicode-math-table.tex



#### BASICS ####

doc: $(BUILDDOC)

README:

$(XMPL):

clean:
	rm -rf $(builddir)
	rm -f $(PKG).zip $(PKG).pdf $(SUITE).pdf

$(PKG).pdf: $(builddir)/$(PKG).pdf
	cp $<  $@

$(SUITE).pdf: $(builddir)/$(SUITE).pdf
	cp $<  $@


#### BUILD FILES

$(builddir)/$(PKG).dtx: $(PKG).dtx
	mkdir -p $(builddir)
	$(UPDATE)
	cp -f  $<  $@

$(builddir)/$(PKG).sty: $(builddir)/$(PKG).dtx
	echo "Updating $@"
	cd $(builddir); \
	tex $(PKG).dtx > /dev/null ;

$(builddir)/unicode-math-table.tex: unicode-math-table.tex
	echo "Updating $@"
	cp -f  $<  $@

$(builddir)/$(PKG).pdf:  $(builddir)/$(PKG).dtx $(BUILDSOURCE)
	cd $(builddir); \
	xelatex $(PKG).dtx && \
	makeindex -s gind.ist $(PKG) && \
	xelatex $(PKG).dtx;

$(builddir)/$(SYM).pdf:  $(builddir)/$(SYM).ltx
	cd $(builddir); \
	xelatex $(SYM).ltx && \
	xelatex $(SYM).ltx;

$(builddir)/$(SUITE).pdf: $(SUITE).ltx $(BUILDSUITE)
	xelatex -output-directory=$(builddir) $<

$(builddir)/umtest-preamble.tex: $(testdir)/umtest-preamble.tex
	cp -f  $<  $@

$(builddir)/umtest-suite.tex: $(testdir)/umtest-suite.tex
	cp -f  $<  $@

$(builddir)/%.ltx: $(testdir)/%.ltx
	cp -f  $<  $@

$(builddir)/README: README.markdown
	cp -f  $< $@

$(builddir)/Makefile: Makefile
	cp -f  $< $@

$(builddir)/$(SUITE).ltx: $(SUITE).ltx
	cp -f  $< $@

$(builddir)/$(XMPL): $(XMPL)
	cp -f  $< $@

$(builddir)/$(SYM).ltx: $(SYM).ltx
	cp -f  $< $@


##### CTAN INSTALLATION #####

../$(testdir):

tds: $(TDSFILES)
	cd $(builddir); \
	zip -r $(PKG).tds.zip $(PKG).tds -x *.DS_Store -x *.safe.png

ctan: $(BUILDCTAN) tds
	cd $(builddir); \
	zip -r \
	  ../$(PKG).zip  $(CTANFILES)  $(PKG).tds.zip \
	  -x *.DS_Store -x *.safe.png

$(tds)/doc/latex/$(PKG)/% \
$(tds)/tex/latex/$(PKG)/% \
$(tds)/source/latex/$(PKG)/% : $(builddir)/%
	mkdir -p $(shell dirname $@)
	cp -f  $< $@

$(tds)/source/latex/$(PKG)/$(testdir):
	cp -rf $(testdir)  $(tds)/source/latex/$(PKG)/$(testdir)

##### LOCAL TEXMF INSTALLATION #####

TEXMFHOME=$(shell kpsewhich --var-value TEXMFHOME)
TEXMFLOCAL=$(shell kpsewhich --var-value TEXMFLOCAL)

install: $(TDSFILES)
	if test -n "$(TEXMFHOME)" ; then \
		echo "Installing in '$(TEXMFHOME)'."; \
		cp -rf  $(tds)/  $(TEXMFHOME); \
	else \
		echo "Cannot locate your home texmf tree. Specify manually with\n\n    make install TEXMFHOME=/path/to/texmf\n" ; \
		false ; \
	fi ;

install-sys: $(TDSFILES)
	if test -n "$(TEXMFLOCAL)" ; then \
		echo "Installing in '$(TEXMFLOCAL)'."; \
		cp -rf  $(tds)/  $(TEXMFLOCAL); \
	else \
		echo "Cannot locate your system-wide local texmf tree. Specify manually with\n\n    make install TEXMFLOCAL=/path/to/texmf\n" ; \
		false ; \
	fi ;



##### USEFUL FOR TEST FILES #####

xfile: $(F)  $(BUILDSOURCE)
	if [ "$(F)" = "" ] ; then \
	  echo "Need a filename!\nE.g.  \`make xfile F=test.ltx\`" ; \
	  false ; \
	fi
	echo Typesetting $(F):
	cp -f $(F) $(builddir)/$(F)
	cd $(builddir); xelatex $(F)

lfile: $(F)  $(BUILDSOURCE)
	if [ "$(F)" = "" ] ; then \
	  echo "Need a filename!\nE.g.  \`make lfile F=test.ltx\`" ; \
	  false ; \
	fi
	echo Typesetting $(F):
	cp -f $(F) $(builddir)/$(F)
	cd $(builddir); lualatex $(F)


#############
# TESTSUITE #
#############


#### All tests ####

test: $(BUILDFILES) $(BUILDTESTTARGET)
	cd $(testdir); \
	ls umtest*.ltx | sed -e 's/umtest\(.*\).ltx/\\inserttest{\1}/g' > umtest-suite.tex


#### Each step of the process ####

$(builddir)/%.diff.png: $(builddir)/%.test.png
	echo '$*: Comparing with good PNG.'
	if [ "${shell compare -metric RMSE $(builddir)/$*.test.png $(testdir)/$*.safe.png $(builddir)/$*.diff.png | grep 'dB'}" = "0 dB" ] ; then \
	  echo '$*: Test passed.' ; \
	else \
	  echo '$*: Test failed.' ; \
	  false ; \
	fi

$(builddir)/%.test.png: $(builddir)/%.pdf
	echo '$*: Converting PDF to PNG.'
	convert -density 300x300  $<  $(builddir)/$*.test.png

$(builddir)/umtest%.pdf: $(BUILDSOURCE) $(BUILDSUITE) $(builddir)/umtest%.ltx
	echo 'umtest$*: Generating PDF output.'
	cd $(builddir); xelatex -interaction=batchmode umtest$*.ltx > /dev/null


#### Generating new tests ####

lonelystub = $(shell cd $(testdir); ls | egrep 'umtest(.*\.ltx)|(.*\.safe.png)' | cut -d . -f 1 | uniq -u)
lonelyfile = $(addsuffix .safe.png,$(lonelystub))
lonelypath = $(addprefix $(testdir)/,$(lonelyfile))
lonelytest = $(addprefix $(builddir)/,$(addsuffix .test.png,$(lonelystub)))

initest: $(lonelypath)

$(lonelypath): $(lonelytest)
	cp  `echo $@ | sed -e s/$(testdir)/$(builddir)/ -e s/.safe.png/.test.png/`  $@