summaryrefslogtreecommitdiff
path: root/web/pwebmac/makeall
blob: 228860f3c3bb13714dd6d156ef8c2894934b9719 (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
288
289
290
291
292
293
294
295
#!/bin/sh
# Test driver for 'pwebmac.tex' in combination with various TeX engines.
# Production tool for all major WEB programs in TeX Live (invoked as
# './makeall --new --pdftocfront --tex={pdftex,xetex}').
# Public domain.  Originally written by Andreas Scherer, 2020.

LONGOPTS=changes,new,outdir:,pdftocfront,tex:
SHRTOPTS=cno:pt:

CHANGES=false # apply main changefile to WEB source
NEW=false # '\input pwebmac' instead of '\input webmac'
OUTDIR=. # path where the resulting tarballs are placed
PDFTOCFRONT=false # push table-of-contents to front of PDF output
TEX=tex # or 'pdftex' or 'xetex'

getopt -T >/dev/null

if [ $? -eq 4 ] # Check for Linux-getopt with extensions
then OPTS=$(getopt -n downloadable-programs -o $SHRTOPTS -l $LONGOPTS -- "$@")
else OPTS=$(getopt $SHRTOPTS $*)
fi

if [ $? -eq 0 ] # Check return code from getopt
then eval set -- $OPTS
else echo "Failed to parse options." >&2; exit 1
fi

while true
do
	case "$1" in
		-c | --changes ) CHANGES=true; shift ;;
		-n | --new ) NEW=true; shift ;;
		-o | --outdir ) OUTDIR="$2"; shift 2 ;;
		-p | --pdftocfront ) PDFTOCFRONT=true; shift ;;
		-t | --tex ) TEX=$2; shift 2 ;;
		-- ) shift; break ;;
		* ) break ;;
	esac
done

KNUTHWHERE=$(locate /bibtex.web)
KNUTHWARE=$(dirname $KNUTHWHERE)

export CWEBINPUTS=$KNUTHWARE//:
export WEBINPUTS=$KNUTHWARE//:

if [ xetex = $TEX ]
then CWEAVE="cweave -f -lp+"
else CWEAVE="cweave -f"
fi
CTWILL="ctwill -f +lpdf"

# WEB and CWEB programs we want to get formatted
for f in \
	$KNUTHWARE/*.web pdftex.web xetex.web \
	common ctangle cweave ctwill ctie tie
do
	f=$(basename $f .web)

	if [ ctwill = $f ]
	then
		# amend TeX Live's 'prod-twill.w' for (c)twill'ing
		if [ ! -e prod-twill.w ]
		then
			tie -m prod-twill.w prod-twill.w prod-mini.ch
		fi
		# apply tons of editorial changes to 'ctwill.w'
		CWEBINPUTS=.:$CWEBINPUTS \
			ctie -m $f.w cweave.w $f-w2c.ch $f-mini.ch
		cp -an $KNUTHWARE/cwebdir/*.bux .
		$CTWILL $f
		$CTWILL $f

	elif $CHANGES
	then
		# pdftex.ch and xetex.ch for TeX Live are assembled here
		WEBINPUTS=$KNUTHWARE/../../Work//:$WEBINPUTS:

		case $f in
			common ) $CWEAVE $f comm-w2c ;;
			ctangle ) $CWEAVE $f ctang-w2c ;;
			cweave ) $CWEAVE $f cweav-w2c ;;
			ctie ) $CWEAVE $f $f-k ;;
			tie ) $CWEAVE $f $f-w2c ;;

			* ) weave $f $f ;;
		esac

		# FIX: XeTeX uses '\pdfTeX' from section 114, which
		# is not changed and thus 'disappears'
		if [ xetex = $f ]
		then
			sed -i -e "s/\(\\\\let\\\\maybe\)/\\\\def\\\\pdfTeX{pdf\\\\TeX}\n\1/" \
				$f.tex
		fi

		# only document changed modules/sections
		sed -i -e "s/\(\\\\let\\\\maybe=\)\\\\iftrue/\1\\\\iffalse/" \
			$f.tex
	else
		case $f in
			c* | tie ) $CWEAVE $f ;;

			* ) weave $f ;;
		esac
	fi

	if $NEW
	then
		# use extended WEB macros for TeX Live PDF documentation
		sed -i -e "1 s/\\\\input webmac/\\\\input pwebmac/" $f.tex

		# timestamp on table-of-contents page or the first page
		case $f in
			c* | tie ) ;; # do nothing for CWEB programs

			bibtex | patgen | tangle | weave )
				sed -i -e "s/\(\\\\def\\\\title\)/\\\\datecontentspage\n\1/" $f.tex ;;

			mf | tex | pdftex | xetex )
				sed -i -e "s/\(\\\\def\\\\botofcontents\)/\\\\datethis\n\1/" $f.tex

				# amend '\N' redefinition for PDF outlines in
				# Metafont and TeX (also pdfTeX and XeTeX)
				# 'pwebmac' defines headers differently
				sed -i -e "s/\(\\\\outer\\\\def\\\\N.*{\)/\1%/" \
					 -e "s/\\\\def\\\\rhead\(.*}\)/\\\\gtitle=\1\\\\MN#1.\\\\vfill\\\\eject/" \
					 $f.tex

				# active links in PDF outlines/bookmarks
				cat > texmf-pdf.patch << FI
  \ifacro{\toksF={}\makeoutlinetoks{[#2] #3}\outlinedone\outlinedone}\fi
FI
				sed -i -e "/\\\\outer\\\\def\\\\N/ {
					r texmf-pdf.patch
					}" $f.tex

				cat > texmf-pdf.patch << FI
  \ifpdf\special{pdf: outline 0 << /Title (\the\toksE) /Dest
    [ @thispage /FitH @ypos ] >>}\fi
FI
				sed -i -e "/  \\\\edef\\\\next/ {
					r texmf-pdf.patch
					}" $f.tex
				rm texmf-pdf.patch ;;

			* ) sed -i -e "s/\(\\\\def\\\\botofcontents\)/%\1/" \
				-e "s/  \\\\centerline{\(\\\\hsize\)/\\\\def\\\\covernote{\1/" \
				-e "s/\(Publishing Company.}}\)}/\1\n\\\\datecontentspage/" \
				-e "s/\(trademark of the American Mathematical Society.}}\)}/\1\n\\\\datecontentspage/" \
				$f.tex ;;
		esac
	fi

	# replace former convention to indicate "not a title page"
	# to include page headers for table-of-contents
	# FIX: most of the WEB codes will be corrected.
	sed -i -e "s/\\\\def\\\\titlepage{F}/\\\\titlefalse/" $f.tex

	# special treatment for individual (C)WEB programs
	case $f in
		# purge conflict between bibtex.web and webmac.tex
		# 'E' no longer free to be active character
		# fix table-of-contents page for bibtex
		# FIX: don't wait for Oren Patashnik.
		bibtex ) sed -i -e "s/titlefalse/titletrue/" $f.tex
			if ! $CHANGES
			then
				sed -i -e "71,78d" $f.tex
			fi ;;

		# make room for new material in weave.web
		# FIX: should be fixed upstream.
		tangle ) sed -i -e "s/number{123}/number{125}/" $f.tex ;;

		# FIX: purge obsolete macros from XeTeX
		xetex ) sed -i -e "/\\\\input xewebmac/d" $f.tex ;;

		# Use nicer format for C comments and assignment
		common | ctangle | cweave | ctie | tie ) # sans ctwill
			sed -i -e "1 s/\(cwebmac\)/\1\n\\\\input Xcwebmac/" \
				$f.tex ;;
	esac

	# shift table-of-contents pages to the front in PDF
	if $PDFTOCFRONT && [ ctwill != $f ]
	then
		sed -i -e "0,/\\\\N[1{]/s/\(\\\\N[1{]\)/\\\\input pdfwebtocfront\n\n\1/" \
			$f.tex

		# only XeTeX can process XETEX.WEB
		if [ xetex = $f ]
		then $f $f # run TeX twice
		else $TEX $f # run TeX twice
		fi
	fi

	# only XeTeX can process XETEX.WEB
	if [ xetex = $f ]
	then $f $f
	else $TEX $f
	fi

	if [ ctwill = $f ]
	then
		# sort mini-indexes
		ctwill-refsort < $f.ref > $f.sref
		$TEX $f
	fi
done

# Finally, build the remaining documents
# * TeX and Metafont test routines
# * WEB and CWEB manuals
if ! $CHANGES
then
	export TEXINPUTS=./:$(kpsewhich --var-value=TEXMFDIST)//:$KNUTHWARE//

	# FIX: Prepare 'trapman' for automatic processing; several input
	# files are renamed in TeX Live (in fact, there are additional
	# files for MetaPost).
	rm -f trapman.tex cwebman.tex

	f=$(kpsewhich -engine tex trapman)
	tie -m $(basename $f) $f /opt/github/web/$(basename $f .tex).ch

	# Prepare 'cwebman' with footnotes describing the extended CWEB.
	f=$(kpsewhich -engine tex cwebman)
	tie -m $(basename $f) $f $(basename $f .tex)-w2c.ch

	for f in trip trap web cweb
	do
		$TEX ${f}man
	done
fi

if $PDFTOCFRONT
then
	# create tarballs for publication
	if $CHANGES
	then
		for f in *.pdf
		do
			mv $f $(basename $f .pdf)-changes.pdf
		done
		pax vftovp-changes.pdf vptovf-changes.pdf \
			-wvzf "$OUTDIR/etc-changes.tar.gz" -s ,^,etc/,
		pax mf-changes.pdf -wvzf "$OUTDIR/mf-changes.tar.gz" -s ,^,mf/,
		pax gftodvi-changes.pdf gftopk-changes.pdf \
			gftype-changes.pdf mft-changes.pdf \
			-wvzf "$OUTDIR/mfware-changes.tar.gz" -s ,^,mfware/,
		pax tex-changes.pdf -wvzf "$OUTDIR/tex-changes.tar.gz" -s ,^,tex/,
		pax dvitype-changes.pdf pltotf-changes.pdf \
			pooltype-changes.pdf tftopl-changes.pdf \
			-wvzf "$OUTDIR/texware-changes.tar.gz" -s ,^,texware/,
		pax tangle-changes.pdf weave-changes.pdf \
			-wvzf "$OUTDIR/web-changes.tar.gz" -s ,^,web/,
		pax bibtex-changes.pdf \
			-wvzf "$OUTDIR/bibtex-changes.tar.gz" -s ,^,bibtex/,
		pax dvicopy-changes.pdf patgen-changes.pdf \
			pktogf-changes.pdf pktype-changes.pdf \
			-wvzf "$OUTDIR/other-changes.tar.gz" -s ,^,other/,
		pax pdftex-changes.pdf \
			-wvzf "$OUTDIR/pdftex-changes.tar.gz" -s ,^,pdftex/,
		pax xetex-changes.pdf \
			-wvzf "$OUTDIR/xetex-changes.tar.gz" -s ,^,xetex/,
		pax ctie-changes.pdf \
			-wvzf "$OUTDIR/ctie-changes.tar.gz" -s ,^,ctie/,
		pax tie-changes.pdf \
			-wvzf "$OUTDIR/tie-changes.tar.gz" -s ,^,tie/,
		pax common-changes.pdf ctangle-changes.pdf cweave-changes.pdf \
			-wvzf "$OUTDIR/cweb-changes.tar.gz" -s ,^,cweb/,
	else
		pax vftovp.pdf vptovf.pdf -wvzf "$OUTDIR/etc.tar.gz" -s ,^,etc/,
		pax mf.pdf trapman.pdf -wvzf "$OUTDIR/mf.tar.gz" -s ,^,mf/,
		pax gftodvi.pdf gftopk.pdf gftype.pdf mft.pdf \
			-wvzf "$OUTDIR/mfware.tar.gz" -s ,^,mfware/,
		pax tex.pdf tripman.pdf -wvzf "$OUTDIR/tex.tar.gz" -s ,^,tex/,
		pax dvitype.pdf pltotf.pdf pooltype.pdf tftopl.pdf \
			-wvzf "$OUTDIR/texware.tar.gz" -s ,^,texware/,
		pax webman.pdf tangle.pdf weave.pdf \
			-wvzf "$OUTDIR/web.tar.gz" -s ,^,web/,
		pax bibtex.pdf -wvzf "$OUTDIR/bibtex.tar.gz" -s ,^,bibtex/,
		pax dvicopy.pdf patgen.pdf pktogf.pdf pktype.pdf \
			-wvzf "$OUTDIR/other.tar.gz" -s ,^,other/,
		pax pdftex.pdf -wvzf "$OUTDIR/pdftex.tar.gz" -s ,^,pdftex/,
		pax xetex.pdf -wvzf "$OUTDIR/xetex.tar.gz" -s ,^,xetex/,
		pax ctie.pdf -wvzf "$OUTDIR/ctie.tar.gz" -s ,^,ctie/,
		pax tie.pdf -wvzf "$OUTDIR/tie.tar.gz" -s ,^,tie/,
		pax cwebman.pdf common.pdf ctangle.pdf cweave.pdf ctwill.pdf \
			-wvzf "$OUTDIR/cweb.tar.gz" -s ,^,cweb/,
	fi
fi

exit 0