blob: e53569b6dfa9914ec45c8574f7c8d869cce0e57d [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 Drake437ff861998-10-07 16:46:54 +000050 --split, -s Specify a section level for page splitting, default: $MAX_SPLIT_DEPTH.
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
Fred Drake437ff861998-10-07 16:46:54 +000077MAX_SPLIT_DEPTH=6
Fred Drake88053541998-04-24 21:57:12 +000078
Fred Drakee2e904f1998-03-10 23:23:05 +000079build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000080 TEXFILE=`kpsewhich $1.tex`
Fred Drakeb5210951998-10-16 17:34:34 +000081 TEXFILE="${TEXFILE#./}"
Fred Drake9940bd71998-08-06 20:15:20 +000082 BUILDDIR=${2:-$1}
Fred Drake11300cc1998-08-05 04:48:18 +000083 latex2html \
84 -init_file $L2H_INIT_FILE \
85 -init_file $L2H_AUX_INIT_FILE \
Fred Drake9940bd71998-08-06 20:15:20 +000086 -dir $BUILDDIR $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000087 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +000088 (cd $BUILDDIR; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000089 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000090}
91
Fred Drake12f842e1998-04-17 02:52:12 +000092use_latex() {
93 # two args: <file> <latextype>
94 MYFILE=$1
95 MYLATEX=$2
96 #
97 # We really have to do it three times to get all the page numbers right,
98 # since the length of the ToC makes a real difference.
99 #
100 $MYDIR/newind.py >$MYFILE.ind
101 $MYDIR/newind.py modindex >mod$MYFILE.ind
102 $MYLATEX $MYFILE || exit $?
103 if [ -f mod$MYFILE.idx ] ; then
104 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +0000105 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000106 if [ -f $MYFILE.idx ] ; then
107 $MYDIR/fix_hack $MYFILE.idx
108 makeindex $MYFILE.idx
109 $MYDIR/indfix.py $MYFILE.ind
110 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000111 if [ -f $MYFILE.syn ] ; then
112 # This hack is due to a bug with the module synopsis support that
113 # causes the last module synopsis to be written out twice in
114 # howto documents (not present for manuals). Repeated below.
115 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
116 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000117 $MYLATEX $MYFILE || exit $?
118 if [ -f mod$MYFILE.idx ] ; then
119 makeindex mod$MYFILE.idx
120 fi
121 if [ -f $MYFILE.idx ] ; then
122 $MYDIR/fix_hack $MYFILE.idx || exit $?
123 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
124 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000125 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000126 $MYDIR/toc2bkm.py -c section $MYFILE
127 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000128 if [ -f $MYFILE.syn ] ; then
129 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
130 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000131 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000132}
133
Fred Drake12f842e1998-04-17 02:52:12 +0000134build_dvi() {
135 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000136}
137
138build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000139 use_latex $1 pdflatex
140}
141
142build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000143 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000144}
145
Fred Drake9940bd71998-08-06 20:15:20 +0000146build_text() {
147 lynx -nolist -dump $2/index.html >$1.txt
148}
149
Fred Drake11300cc1998-08-05 04:48:18 +0000150l2hoption() {
151 if [ "$2" ] ; then
152 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
153 fi
154}
155
Fred Drake12f842e1998-04-17 02:52:12 +0000156cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000157 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 +0000158 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000159 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000160 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000161 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000162 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000163 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000164}
165
Fred Drakee1feb8f1998-08-28 20:21:04 +0000166parse_option() {
167 # When using a long option with a parameter separated by '=',
168 # generalize the parsing of the two:
169 OPTION="$1"
170 unset VALUE
171 STUFF=`echo "$1" | grep '^--[-a-zA-Z0-9]*='`
172 if [ "$STUFF" ] ; then
173 # This leaves OPTION=--option= and VALUE=value
174 OPTION=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\1/'`
175 VALUE=`echo "$STUFF" | sed 's/^\(--[-a-zA-Z0-9]*=\)\(.*\)$/\2/'`
176 fi
177}
178
Fred Drakee2e904f1998-03-10 23:23:05 +0000179# figure out what our targets are:
180while [ "$1" ] ; do
Fred Drakee1feb8f1998-08-28 20:21:04 +0000181 parse_option "$1"
182 case "$OPTION" in
Fred Drake9f6f0da1998-08-12 18:07:51 +0000183 --all|--al)
184 BUILD_PDF=true
185 BUILD_PS=true
186 BUILD_DVI=true
187 BUILD_HTML=true
188 BUILD_TEXT=true
189 USE_DEFAULT_FORMAT=false
190 shift 1
191 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000192 --pdf|--pd)
193 BUILD_PDF=true
194 USE_DEFAULT_FORMAT=false
195 shift 1
196 ;;
Fred Drake88053541998-04-24 21:57:12 +0000197 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000198 BUILD_PS=true
199 USE_DEFAULT_FORMAT=false
200 shift 1
201 ;;
202 --dvi|--dv|--d)
203 BUILD_DVI=true
204 USE_DEFAULT_FORMAT=false
205 shift 1
206 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000207 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000208 BUILD_HTML=true
209 USE_DEFAULT_FORMAT=false
210 shift 1
211 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000212 --text|--tex|--te|--t)
213 BUILD_TEXT=true
214 USE_DEFAULT_FORMAT=false
215 shift 1
216 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000217 -H|--help|--hel|--he)
218 usage 0
219 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000220 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
221 ICONSERVER="$2"
222 shift 2
223 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000224 --iconserver=*|--iconserve=*|--iconserv=*|--iconser=*|--iconse=*|--icons=*|--icon=*|--ico=*|--ic=*|--i=*)
225 ICONSERVER="$VALUE"
226 shift 1
227 ;;
Fred Drake35049521998-05-11 19:04:06 +0000228 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000229 ADDRESS="$2"
230 shift 2
231 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000232 --address=*|--addres=*|--addre=*|-addr=*|--add=*|--ad=*)
233 ADDRESS="$VALUE"
234 shift 1
235 ;;
Fred Drake35049521998-05-11 19:04:06 +0000236 --a4)
237 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
238 shift 1
239 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000240 --letter|--lette|--lett|--let|--le)
241 shift 1
242 ;;
Fred Drake88053541998-04-24 21:57:12 +0000243 --link|--lin|--li)
244 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000245 shift 2
246 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000247 --link=*|--lin=*|--li=*)
248 LINK="$VALUE"
249 shift 1
250 ;;
Fred Drake88053541998-04-24 21:57:12 +0000251 -s|--split|--spli|--spl|--sp|--s)
252 MAX_SPLIT_DEPTH="$2"
253 shift 2
254 ;;
Fred Drakee1feb8f1998-08-28 20:21:04 +0000255 --split=|--spli=|--spl=|--sp=|--s=)
256 MAX_SPLIT_DEPTH="$VALUE"
257 shift 1
258 ;;
Fred Drake88053541998-04-24 21:57:12 +0000259 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000260 LOGGING=true
261 shift 1
262 ;;
263 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
264 DEBUGGING=true
265 shift 1
266 ;;
267 -k|--keep|--kee|--ke|--k)
268 DISCARD_TEMPS=''
269 shift 1
270 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000271 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000272 QUIET=true
273 shift 1
274 ;;
Fred Drake88053541998-04-24 21:57:12 +0000275 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000276 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000277 break
278 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000279 -*)
Fred Drakee1feb8f1998-08-28 20:21:04 +0000280 usage 2 "Unknown option: ${VALUE%=}"
Fred Drakee2e904f1998-03-10 23:23:05 +0000281 ;;
282 *)
283 break;;
284 esac
285done
286
287if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000288 # check for a single .tex file in .
289 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
290 if [ "$COUNT" -eq 1 ] ; then
291 set -- `ls -1 *.tex`
Fred Drake9f6f0da1998-08-12 18:07:51 +0000292 elif [ "$COUNT" -gt 1 ] ; then
293 usage 2 "Could not deduce which file(s) to process as HOWTO documents."
Fred Drake9940bd71998-08-06 20:15:20 +0000294 else
Fred Drake9f6f0da1998-08-12 18:07:51 +0000295 usage 2 "No file to process."
Fred Drake9940bd71998-08-06 20:15:20 +0000296 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000297fi
298
299if [ $USE_DEFAULT_FORMAT = true ] ; then
300 eval "BUILD_$DEFAULT_FORMAT=true"
301fi
302
Fred Drake664b36f1998-03-11 15:41:21 +0000303if [ "$QUIET" ] ; then
304 exec >/dev/null
305fi
306
Fred Drake9940bd71998-08-06 20:15:20 +0000307if [ "$DEBUGGING" ] ; then
308 set -x
309fi
310
Fred Drake11300cc1998-08-05 04:48:18 +0000311echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
312echo '# generated by mkhowto.sh -- do no edit' >>$L2H_AUX_INIT_FILE
Fred Drakee1feb8f1998-08-28 20:21:04 +0000313if [ "$ICONSERVER" ] ; then
314 ICONSERVER="${ICONSERVER%/}"
315fi
Fred Drake11300cc1998-08-05 04:48:18 +0000316l2hoption ICONSERVER "$ICONSERVER"
317l2hoption ADDRESS "$ADDRESS"
318l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
319l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
320echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000321
Fred Drakee2e904f1998-03-10 23:23:05 +0000322for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000323 FILEDIR=`dirname $FILE`
Fred Drakee1feb8f1998-08-28 20:21:04 +0000324 FILE=`basename $FILE .tex`
Fred Drakef4fc4761998-05-14 20:03:14 +0000325 #
326 # Put the directory the .tex file is in is also the first directory in
327 # TEXINPUTS, to allow files there to override files in the common area.
328 #
Fred Drake11300cc1998-08-05 04:48:18 +0000329 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000330 export TEXINPUTS
331 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000332 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000333 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000334 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000335 fi
336 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000337 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000338 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000339 fi
340 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000341 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000342 fi
343 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000344 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000345 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000346 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000347 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000348 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000349 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000350 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000351 if [ "$BUILD_TEXT" ] ; then
352 if [ ! "$HAVE_TEMPS" ] ; then
353 # need to get aux file
354 build_dvi $FILE 2>&1 | tee -a $LOGFILE
355 HAVE_TEMPS=true
356 fi
357 # this is why building text really has to be last:
358 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
359 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
360 l2hoption MAX_SPLIT_DEPTH 1
361 echo '1;' >>$L2H_AUX_INIT_FILE
362 TEMPDIR=$FILE.temp-html
363 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
364 else
365 TEMPDIR=$FILE
366 fi
367 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
368 fi
369
Fred Drakedbc879e1998-03-11 15:33:44 +0000370 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000371 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000372 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000373 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000374 if [ "$LOGGING" ] ; then
375 cp $LOGFILE $FILE.how
376 fi
377 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000378done
Fred Drake11300cc1998-08-05 04:48:18 +0000379
Fred Drakeb0b19001998-10-07 16:41:40 +0000380if [ ! "$DEBUGGING" ] ; then
381 rm -f $L2H_AUX_INIT_FILE
382fi