blob: 6fa83b2006a833c84221894ef46c21d7063b9dcf [file] [log] [blame]
Fred Drake11300cc1998-08-05 04:48:18 +00001#! /usr/bin/env bash
Fred Drakee2e904f1998-03-10 23:23:05 +00002
Fred Drakec794c381998-08-12 17:50:07 +00003# This script may be invoked by naming it directly or via a shell alias,
4# but NOT through a symbolic link. Perhaps a future version will allow
5# the use of a symbolic link.
6#
7# Using a symbolic link will cause the script to not be able to locate
8# its support files.
9
Fred Drakee2e904f1998-03-10 23:23:05 +000010MYDIR=`dirname $0`
Fred Drakef558e311998-03-24 17:48:20 +000011WORKDIR=`pwd`
12cd $MYDIR
13MYDIR=`pwd`
Fred Drakeac8f91a1998-04-02 15:37:13 +000014cd ..
15TOPDIR=`pwd`
Fred Drakef558e311998-03-24 17:48:20 +000016cd $WORKDIR
Fred Drakee2e904f1998-03-10 23:23:05 +000017
18# DEFAULT_FORMAT must be upper case...
19DEFAULT_FORMAT=PDF
20USE_DEFAULT_FORMAT=true
Fred Drakedbc879e1998-03-11 15:33:44 +000021DISCARD_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +000022
Fred Drake11300cc1998-08-05 04:48:18 +000023ICONSERVER=''
24
Fred Drakee1feb8f1998-08-28 20:21:04 +000025TEMPBASE=mkhowto-$LOGNAME-$$
Fred Drakeac8f91a1998-04-02 15:37:13 +000026
Fred Drakee1feb8f1998-08-28 20:21:04 +000027L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
28L2H_AUX_INIT_FILE=/usr/tmp/$TEMPBASE.perl
29
30LOGFILE=/usr/tmp/$TEMPBASE.how
Fred Drakedbc879e1998-03-11 15:33:44 +000031LOGGING=''
32
Fred Drakee2e904f1998-03-10 23:23:05 +000033usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000034 MYNAME=`basename $0`
35 echo "usage: $MYNAME [options...] file ..."
36 cat <<EOF
37
38Options specifying formats to build:
39 --html HyperText Markup Language
40 --pdf Portable Document Format (default)
41 --ps PostScript
42 --dvi "DeVice Indepentent" format from TeX
Fred Drake78b8c3d1998-08-12 17:52:16 +000043 --text ASCII text
Fred Drakeac8f91a1998-04-02 15:37:13 +000044
Fred Drake9f6f0da1998-08-12 18:07:51 +000045 More than one output format may be specified, or --all.
Fred Drakeac8f91a1998-04-02 15:37:13 +000046
47HTML options:
48 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000049 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000050 --split, -s Specify a section level for page splitting.
Fred Drake11300cc1998-08-05 04:48:18 +000051 --iconserver, -i Specify location of icons (default: ../).
Fred Drakeac8f91a1998-04-02 15:37:13 +000052
53Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000054 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000055 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000056 --help, -H Show this text.
57 --logging, -l Log stdout and stderr to a file (*.how).
58 --debugging, -D Echo commands as they are executed.
59 --keep, -k Keep temporary files around.
60 --quiet, -q Do not print command output to stdout.
61 (stderr is also lost, sorry; see *.how for errors)
62
63EOF
Fred Drake9f6f0da1998-08-12 18:07:51 +000064 if [ "$2" ] ; then
65 echo "$2"
66 echo
67 fi
Fred Drake11300cc1998-08-05 04:48:18 +000068
Fred Drakeac8f91a1998-04-02 15:37:13 +000069 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000070}
71
Fred Drake88053541998-04-24 21:57:12 +000072# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
73# The values here are the defaults after modification by perl/l2hinit.perl.
74#
75ADDRESS=''
76MAX_LINK_DEPTH=3
77MAX_SPLIT_DEPTH=8
78
Fred Drakee2e904f1998-03-10 23:23:05 +000079build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000080 TEXFILE=`kpsewhich $1.tex`
Fred Drake9940bd71998-08-06 20:15:20 +000081 BUILDDIR=${2:-$1}
Fred Drake11300cc1998-08-05 04:48:18 +000082 latex2html \
83 -init_file $L2H_INIT_FILE \
84 -init_file $L2H_AUX_INIT_FILE \
Fred Drake9940bd71998-08-06 20:15:20 +000085 -dir $BUILDDIR $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000086 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +000087 (cd $BUILDDIR; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000088 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000089}
90
Fred Drake12f842e1998-04-17 02:52:12 +000091use_latex() {
92 # two args: <file> <latextype>
93 MYFILE=$1
94 MYLATEX=$2
95 #
96 # We really have to do it three times to get all the page numbers right,
97 # since the length of the ToC makes a real difference.
98 #
99 $MYDIR/newind.py >$MYFILE.ind
100 $MYDIR/newind.py modindex >mod$MYFILE.ind
101 $MYLATEX $MYFILE || exit $?
102 if [ -f mod$MYFILE.idx ] ; then
103 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +0000104 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000105 if [ -f $MYFILE.idx ] ; then
106 $MYDIR/fix_hack $MYFILE.idx
107 makeindex $MYFILE.idx
108 $MYDIR/indfix.py $MYFILE.ind
109 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000110 if [ -f $MYFILE.syn ] ; then
111 # This hack is due to a bug with the module synopsis support that
112 # causes the last module synopsis to be written out twice in
113 # howto documents (not present for manuals). Repeated below.
114 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
115 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000116 $MYLATEX $MYFILE || exit $?
117 if [ -f mod$MYFILE.idx ] ; then
118 makeindex mod$MYFILE.idx
119 fi
120 if [ -f $MYFILE.idx ] ; then
121 $MYDIR/fix_hack $MYFILE.idx || exit $?
122 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
123 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000124 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000125 $MYDIR/toc2bkm.py -c section $MYFILE
126 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000127 if [ -f $MYFILE.syn ] ; then
128 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
129 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000130 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000131}
132
Fred Drake12f842e1998-04-17 02:52:12 +0000133build_dvi() {
134 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000135}
136
137build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000138 use_latex $1 pdflatex
139}
140
141build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000142 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000143}
144
Fred Drake9940bd71998-08-06 20:15:20 +0000145build_text() {
146 lynx -nolist -dump $2/index.html >$1.txt
147}
148
Fred Drake11300cc1998-08-05 04:48:18 +0000149l2hoption() {
150 if [ "$2" ] ; then
151 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
152 fi
153}
154
Fred Drake12f842e1998-04-17 02:52:12 +0000155cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000156 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind $1.syn
Fred Drakec9b8a571998-04-29 21:28:25 +0000157 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000158 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000159 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000160 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000161 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000162 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000163}
164
Fred Drakee1feb8f1998-08-28 20:21:04 +0000165parse_option() {
166 # When using a long option with a parameter separated by '=',
167 # generalize the parsing of the two:
168 OPTION="$1"
169 unset VALUE
170 STUFF=`echo "$1" | grep '^--[-a-zA-Z0-9]*='`
171 if [ "$STUFF" ] ; then
172 # This leaves OPTION=--option= and VALUE=value
173 OPTION=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\1/'`
174 VALUE=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\2/'`
175 fi
176}
177
Fred Drakee2e904f1998-03-10 23:23:05 +0000178# figure out what our targets are:
179while [ "$1" ] ; do
Fred Drakee1feb8f1998-08-28 20:21:04 +0000180 parse_option "$1"
181 case "$OPTION" in
Fred Drake9f6f0da1998-08-12 18:07:51 +0000182 --all|--al)
183 BUILD_PDF=true
184 BUILD_PS=true
185 BUILD_DVI=true
186 BUILD_HTML=true
187 BUILD_TEXT=true
188 USE_DEFAULT_FORMAT=false
189 shift 1
190 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000191 --pdf|--pd)
192 BUILD_PDF=true
193 USE_DEFAULT_FORMAT=false
194 shift 1
195 ;;
Fred Drake88053541998-04-24 21:57:12 +0000196 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000197 BUILD_PS=true
198 USE_DEFAULT_FORMAT=false
199 shift 1
200 ;;
201 --dvi|--dv|--d)
202 BUILD_DVI=true
203 USE_DEFAULT_FORMAT=false
204 shift 1
205 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000206 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000207 BUILD_HTML=true
208 USE_DEFAULT_FORMAT=false
209 shift 1
210 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000211 --text|--tex|--te|--t)
212 BUILD_TEXT=true
213 USE_DEFAULT_FORMAT=false
214 shift 1
215 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000216 -H|--help|--hel|--he)
217 usage 0
218 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000219 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
220 ICONSERVER="$2"
221 shift 2
222 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000223 --iconserver=*|--iconserve=*|--iconserv=*|--iconser=*|--iconse=*|--icons=*|--icon=*|--ico=*|--ic=*|--i=*)
224 ICONSERVER="$VALUE"
225 shift 1
226 ;;
Fred Drake35049521998-05-11 19:04:06 +0000227 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000228 ADDRESS="$2"
229 shift 2
230 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000231 --address=*|--addres=*|--addre=*|-addr=*|--add=*|--ad=*)
232 ADDRESS="$VALUE"
233 shift 1
234 ;;
Fred Drake35049521998-05-11 19:04:06 +0000235 --a4)
236 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
237 shift 1
238 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000239 --letter|--lette|--lett|--let|--le)
240 shift 1
241 ;;
Fred Drake88053541998-04-24 21:57:12 +0000242 --link|--lin|--li)
243 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000244 shift 2
245 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000246 --link=*|--lin=*|--li=*)
247 LINK="$VALUE"
248 shift 1
249 ;;
Fred Drake88053541998-04-24 21:57:12 +0000250 -s|--split|--spli|--spl|--sp|--s)
251 MAX_SPLIT_DEPTH="$2"
252 shift 2
253 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000254 --split=|--spli=|--spl=|--sp=|--s=)
255 MAX_SPLIT_DEPTH="$VALUE"
256 shift 1
257 ;;
Fred Drake88053541998-04-24 21:57:12 +0000258 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000259 LOGGING=true
260 shift 1
261 ;;
262 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
263 DEBUGGING=true
264 shift 1
265 ;;
266 -k|--keep|--kee|--ke|--k)
267 DISCARD_TEMPS=''
268 shift 1
269 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000270 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000271 QUIET=true
272 shift 1
273 ;;
Fred Drake88053541998-04-24 21:57:12 +0000274 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000275 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000276 break
277 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000278 -*)
Fred Drakee1feb8f1998-08-28 20:21:04 +0000279 usage 2 "Unknown option: ${VALUE%=}"
Fred Drakee2e904f1998-03-10 23:23:05 +0000280 ;;
281 *)
282 break;;
283 esac
284done
285
286if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000287 # check for a single .tex file in .
288 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
289 if [ "$COUNT" -eq 1 ] ; then
290 set -- `ls -1 *.tex`
Fred Drake9f6f0da1998-08-12 18:07:51 +0000291 elif [ "$COUNT" -gt 1 ] ; then
292 usage 2 "Could not deduce which file(s) to process as HOWTO documents."
Fred Drake9940bd71998-08-06 20:15:20 +0000293 else
Fred Drake9f6f0da1998-08-12 18:07:51 +0000294 usage 2 "No file to process."
Fred Drake9940bd71998-08-06 20:15:20 +0000295 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000296fi
297
298if [ $USE_DEFAULT_FORMAT = true ] ; then
299 eval "BUILD_$DEFAULT_FORMAT=true"
300fi
301
Fred Drake664b36f1998-03-11 15:41:21 +0000302if [ "$QUIET" ] ; then
303 exec >/dev/null
304fi
305
Fred Drake9940bd71998-08-06 20:15:20 +0000306if [ "$DEBUGGING" ] ; then
307 set -x
308fi
309
Fred Drake11300cc1998-08-05 04:48:18 +0000310echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
311echo '# generated by mkhowto.sh -- do no edit' >>$L2H_AUX_INIT_FILE
Fred Drakee1feb8f1998-08-28 20:21:04 +0000312if [ "$ICONSERVER" ] ; then
313 ICONSERVER="${ICONSERVER%/}"
314fi
Fred Drake11300cc1998-08-05 04:48:18 +0000315l2hoption ICONSERVER "$ICONSERVER"
316l2hoption ADDRESS "$ADDRESS"
317l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
318l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
319echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000320
Fred Drakee2e904f1998-03-10 23:23:05 +0000321for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000322 FILEDIR=`dirname $FILE`
Fred Drakee1feb8f1998-08-28 20:21:04 +0000323 FILE=`basename $FILE .tex`
Fred Drakef4fc4761998-05-14 20:03:14 +0000324 #
325 # Put the directory the .tex file is in is also the first directory in
326 # TEXINPUTS, to allow files there to override files in the common area.
327 #
Fred Drake11300cc1998-08-05 04:48:18 +0000328 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000329 export TEXINPUTS
330 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000331 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000332 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000333 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000334 fi
335 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000336 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000337 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000338 fi
339 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000340 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000341 fi
342 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000343 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000344 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000345 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000346 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000347 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000348 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000349 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000350 if [ "$BUILD_TEXT" ] ; then
351 if [ ! "$HAVE_TEMPS" ] ; then
352 # need to get aux file
353 build_dvi $FILE 2>&1 | tee -a $LOGFILE
354 HAVE_TEMPS=true
355 fi
356 # this is why building text really has to be last:
357 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
358 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
359 l2hoption MAX_SPLIT_DEPTH 1
360 echo '1;' >>$L2H_AUX_INIT_FILE
361 TEMPDIR=$FILE.temp-html
362 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
363 else
364 TEMPDIR=$FILE
365 fi
366 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
367 fi
368
Fred Drakedbc879e1998-03-11 15:33:44 +0000369 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000370 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000371 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000372 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000373 if [ "$LOGGING" ] ; then
374 cp $LOGFILE $FILE.how
375 fi
376 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000377done
Fred Drake11300cc1998-08-05 04:48:18 +0000378
379rm -f $L2H_AUX_INIT_FILE