summaryrefslogtreecommitdiff
path: root/web/pwebmac/makeall
blob: 6f0762a8d92d949fe8e36e8e37963a8702df5d12 (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
#!/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//:

# WEB and CWEB programs we want to get formatted; 'xetex.web' must be last,
# because it switches the TEX engine!
for f in \
	$KNUTHWARE/*.web \
	common ctangle cweave ctwill ctie tie \
	pdftex.web xetex.web
do
	if $CHANGES
	then
		c=$(basename $f .web).ch

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

		case $f in
			*.web ) weave $f $c ;;
			"common" ) cweave -f $f comm-w2c ;;
			"ctangle" ) cweave -f $f ctang-w2c ;;
			"cweave" ) cweave -f $f cweav-w2c ;;
			"ctwill" ) cweave -f cweave $f-w2c $f ;;
			"ctie" ) cweave -f $f $f-k ;;
			"tie" ) cweave -f $f $f-w2c ;;
		esac

		# make full documentation with changes applied
		sed -i -e "s/\(\\\\let\\\\maybe=\)\\\\iffalse/\1\\\\iftrue/" \
			$(basename $f .web).tex
	else
		case $f in
			*.web ) weave $f ;;
			"common"|"ctangle"|"cweave"|"ctie"|"tie" )
				cweave -f $f ;;
			"ctwill" ) cweave -f cweave $f-w2c $f ;;
		esac
	fi

	f=$(basename $f .web)

	# use extended macros for TeX Live PDF documentation
	if $NEW
	then
		sed -i -e "1 s/\\\\input webmac/\\\\input pwebmac/" $f.tex
	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 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/" \
			-e "70,77d" $f.tex ;;

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

		# amend '\N' redefinition for PDF outlines in mf.tex and
		# tex.tex (also pdftex.web and xetex.web); depends on the
		# extended 'pwebmac.tex' macros
		"mf"|"tex"|"pdftex"|"xetex" )
			if [ "xetex" = $f ]
			then
				# purge obsolete macros from XeTeX
				sed -i -e "/\\\\input xewebmac/d" $f.tex
				# only XeTeX can process XeTeX
				TEX=xetex
			fi
			if $NEW
			then
				if [ "pdftex" = $f ]
				then
					# pdfTeX has a looong table-of-contents
					cat > pdftex.patch << FI
  \advance\vsize by 4\baselineskip
  \ifacro\advance\pdfpageheight by 4\baselineskip\fi
FI
					sed -i -e "/\\\\def\\\\topofcontents.*/ {
						r pdftex.patch
						}"  $f.tex
				fi
				# 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
			fi ;;

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

			# 'cwebmac.tex' needs a little push for 'xetex'
			# FIX: should be fixed upstream in 'cwebmac.tex'.
			if [ "xetex" = $TEX ]
			then
				sed -i -e "1 s/\(\\\\input cwebmac\)/\\\\let\\\\pdf+\n\1\n/" \
					$f.tex
			fi ;;
	esac

	if $PDFTOCFRONT
	then
		# shift table-of-contents pages to the front in PDF
		sed -i -e "1 s/\(webmac\)/\1\n\\\\input pdfwebtocfront/" $f.tex
		sed -i -e "2 s/\(cwebmac\)/\1\n\\\\input pdfwebtocfront/" $f.tex
		$TEX $f # run TeX twice
	fi

	$TEX $f
done

if $PDFTOCFRONT
then
	# create tarballs for publication
	pax vftovp.pdf vptovf.pdf -wvzf $OUTDIR/etc.tar.gz -s ,^,etc/,
	pax mf.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 -wvzf $OUTDIR/tex.tar.gz -s ,^,tex/,
	pax dvitype.pdf pltotf.pdf pooltype.pdf tftopl.pdf \
		-wvzf $OUTDIR/texware.tar.gz -s ,^,texware/,
	pax 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 common.pdf ctangle.pdf cweave.pdf ctwill.pdf \
		-wvzf $OUTDIR/cweb.tar.gz -s ,^,cweb/,
fi

exit 0