blob: a33f6b468dd3e4c6621737f8b53d33610b7237b8 [file] [log] [blame]
Fred Drake11300cc1998-08-05 04:48:18 +00001#! /usr/bin/env bash
Fred Drakee2e904f1998-03-10 23:23:05 +00002
3MYDIR=`dirname $0`
Fred Drakef558e311998-03-24 17:48:20 +00004WORKDIR=`pwd`
5cd $MYDIR
6MYDIR=`pwd`
Fred Drakeac8f91a1998-04-02 15:37:13 +00007cd ..
8TOPDIR=`pwd`
Fred Drakef558e311998-03-24 17:48:20 +00009cd $WORKDIR
Fred Drakee2e904f1998-03-10 23:23:05 +000010
11# DEFAULT_FORMAT must be upper case...
12DEFAULT_FORMAT=PDF
13USE_DEFAULT_FORMAT=true
Fred Drakedbc879e1998-03-11 15:33:44 +000014DISCARD_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +000015
Fred Drake11300cc1998-08-05 04:48:18 +000016ICONSERVER=''
17
Fred Drakeac8f91a1998-04-02 15:37:13 +000018L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
Fred Drake11300cc1998-08-05 04:48:18 +000019L2H_AUX_INIT_FILE=/usr/tmp/mkhowto-$LOGNAME-$$.perl
Fred Drakeac8f91a1998-04-02 15:37:13 +000020
Fred Drakedbc879e1998-03-11 15:33:44 +000021LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
22LOGGING=''
23
Fred Drakee2e904f1998-03-10 23:23:05 +000024usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000025 MYNAME=`basename $0`
26 echo "usage: $MYNAME [options...] file ..."
27 cat <<EOF
28
29Options specifying formats to build:
30 --html HyperText Markup Language
31 --pdf Portable Document Format (default)
32 --ps PostScript
33 --dvi "DeVice Indepentent" format from TeX
34
35 More than one output format may be specified.
36
37HTML options:
38 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000039 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000040 --split, -s Specify a section level for page splitting.
Fred Drake11300cc1998-08-05 04:48:18 +000041 --iconserver, -i Specify location of icons (default: ../).
Fred Drakeac8f91a1998-04-02 15:37:13 +000042
43Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000044 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000045 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000046 --help, -H Show this text.
47 --logging, -l Log stdout and stderr to a file (*.how).
48 --debugging, -D Echo commands as they are executed.
49 --keep, -k Keep temporary files around.
50 --quiet, -q Do not print command output to stdout.
51 (stderr is also lost, sorry; see *.how for errors)
52
53EOF
Fred Drake11300cc1998-08-05 04:48:18 +000054
Fred Drakeac8f91a1998-04-02 15:37:13 +000055 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000056}
57
Fred Drake88053541998-04-24 21:57:12 +000058# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
59# The values here are the defaults after modification by perl/l2hinit.perl.
60#
61ADDRESS=''
62MAX_LINK_DEPTH=3
63MAX_SPLIT_DEPTH=8
64
Fred Drakee2e904f1998-03-10 23:23:05 +000065build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000066 TEXFILE=`kpsewhich $1.tex`
Fred Drake9940bd71998-08-06 20:15:20 +000067 BUILDDIR=${2:-$1}
Fred Drake11300cc1998-08-05 04:48:18 +000068 latex2html \
69 -init_file $L2H_INIT_FILE \
70 -init_file $L2H_AUX_INIT_FILE \
Fred Drake9940bd71998-08-06 20:15:20 +000071 -dir $BUILDDIR $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000072 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +000073 (cd $BUILDDIR; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000074 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000075}
76
Fred Drake12f842e1998-04-17 02:52:12 +000077use_latex() {
78 # two args: <file> <latextype>
79 MYFILE=$1
80 MYLATEX=$2
81 #
82 # We really have to do it three times to get all the page numbers right,
83 # since the length of the ToC makes a real difference.
84 #
85 $MYDIR/newind.py >$MYFILE.ind
86 $MYDIR/newind.py modindex >mod$MYFILE.ind
87 $MYLATEX $MYFILE || exit $?
88 if [ -f mod$MYFILE.idx ] ; then
89 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000090 fi
Fred Drake12f842e1998-04-17 02:52:12 +000091 if [ -f $MYFILE.idx ] ; then
92 $MYDIR/fix_hack $MYFILE.idx
93 makeindex $MYFILE.idx
94 $MYDIR/indfix.py $MYFILE.ind
95 fi
Fred Drake8cab5491998-07-23 19:13:52 +000096 if [ -f $MYFILE.syn ] ; then
97 # This hack is due to a bug with the module synopsis support that
98 # causes the last module synopsis to be written out twice in
99 # howto documents (not present for manuals). Repeated below.
100 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
101 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000102 $MYLATEX $MYFILE || exit $?
103 if [ -f mod$MYFILE.idx ] ; then
104 makeindex mod$MYFILE.idx
105 fi
106 if [ -f $MYFILE.idx ] ; then
107 $MYDIR/fix_hack $MYFILE.idx || exit $?
108 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
109 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000110 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000111 $MYDIR/toc2bkm.py -c section $MYFILE
112 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000113 if [ -f $MYFILE.syn ] ; then
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 $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000117}
118
Fred Drake12f842e1998-04-17 02:52:12 +0000119build_dvi() {
120 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000121}
122
123build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000124 use_latex $1 pdflatex
125}
126
127build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000128 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000129}
130
Fred Drake9940bd71998-08-06 20:15:20 +0000131build_text() {
132 lynx -nolist -dump $2/index.html >$1.txt
133}
134
Fred Drake11300cc1998-08-05 04:48:18 +0000135l2hoption() {
136 if [ "$2" ] ; then
137 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
138 fi
139}
140
Fred Drake12f842e1998-04-17 02:52:12 +0000141cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000142 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 +0000143 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000144 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000145 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000146 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000147 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000148 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000149}
150
151# figure out what our targets are:
152while [ "$1" ] ; do
153 case "$1" in
154 --pdf|--pd)
155 BUILD_PDF=true
156 USE_DEFAULT_FORMAT=false
157 shift 1
158 ;;
Fred Drake88053541998-04-24 21:57:12 +0000159 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000160 BUILD_PS=true
161 USE_DEFAULT_FORMAT=false
162 shift 1
163 ;;
164 --dvi|--dv|--d)
165 BUILD_DVI=true
166 USE_DEFAULT_FORMAT=false
167 shift 1
168 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000169 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000170 BUILD_HTML=true
171 USE_DEFAULT_FORMAT=false
172 shift 1
173 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000174 --text|--tex|--te|--t)
175 BUILD_TEXT=true
176 USE_DEFAULT_FORMAT=false
177 shift 1
178 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000179 -H|--help|--hel|--he)
180 usage 0
181 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000182 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
183 ICONSERVER="$2"
184 shift 2
185 ;;
Fred Drake35049521998-05-11 19:04:06 +0000186 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000187 ADDRESS="$2"
188 shift 2
189 ;;
Fred Drake35049521998-05-11 19:04:06 +0000190 --a4)
191 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
192 shift 1
193 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000194 --letter|--lette|--lett|--let|--le)
195 shift 1
196 ;;
Fred Drake88053541998-04-24 21:57:12 +0000197 --link|--lin|--li)
198 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000199 shift 2
200 ;;
Fred Drake88053541998-04-24 21:57:12 +0000201 -s|--split|--spli|--spl|--sp|--s)
202 MAX_SPLIT_DEPTH="$2"
203 shift 2
204 ;;
205 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000206 LOGGING=true
207 shift 1
208 ;;
209 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
210 DEBUGGING=true
211 shift 1
212 ;;
213 -k|--keep|--kee|--ke|--k)
214 DISCARD_TEMPS=''
215 shift 1
216 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000217 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000218 QUIET=true
219 shift 1
220 ;;
Fred Drake88053541998-04-24 21:57:12 +0000221 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000222 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000223 break
224 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000225 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000226 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000227 ;;
228 *)
229 break;;
230 esac
231done
232
233if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000234 # check for a single .tex file in .
235 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
236 if [ "$COUNT" -eq 1 ] ; then
237 set -- `ls -1 *.tex`
238 else
239 usage 2
240 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000241fi
242
243if [ $USE_DEFAULT_FORMAT = true ] ; then
244 eval "BUILD_$DEFAULT_FORMAT=true"
245fi
246
Fred Drake664b36f1998-03-11 15:41:21 +0000247if [ "$QUIET" ] ; then
248 exec >/dev/null
249fi
250
Fred Drake9940bd71998-08-06 20:15:20 +0000251if [ "$DEBUGGING" ] ; then
252 set -x
253fi
254
Fred Drake11300cc1998-08-05 04:48:18 +0000255echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
256echo '# generated by mkhowto.sh -- do no edit' >>$L2H_AUX_INIT_FILE
257l2hoption ICONSERVER "$ICONSERVER"
258l2hoption ADDRESS "$ADDRESS"
259l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
260l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
261echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000262
Fred Drakee2e904f1998-03-10 23:23:05 +0000263for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000264 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000265 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000266 #
267 # Put the directory the .tex file is in is also the first directory in
268 # TEXINPUTS, to allow files there to override files in the common area.
269 #
Fred Drake11300cc1998-08-05 04:48:18 +0000270 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000271 export TEXINPUTS
272 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000273 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000274 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000275 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000276 fi
277 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000278 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000279 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000280 fi
281 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000282 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000283 fi
284 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000285 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000286 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000287 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000288 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000289 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000290 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000291 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000292 if [ "$BUILD_TEXT" ] ; then
293 if [ ! "$HAVE_TEMPS" ] ; then
294 # need to get aux file
295 build_dvi $FILE 2>&1 | tee -a $LOGFILE
296 HAVE_TEMPS=true
297 fi
298 # this is why building text really has to be last:
299 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
300 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
301 l2hoption MAX_SPLIT_DEPTH 1
302 echo '1;' >>$L2H_AUX_INIT_FILE
303 TEMPDIR=$FILE.temp-html
304 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
305 else
306 TEMPDIR=$FILE
307 fi
308 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
309 fi
310
Fred Drakedbc879e1998-03-11 15:33:44 +0000311 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000312 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000313 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000314 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000315 if [ "$LOGGING" ] ; then
316 cp $LOGFILE $FILE.how
317 fi
318 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000319done
Fred Drake11300cc1998-08-05 04:48:18 +0000320
321rm -f $L2H_AUX_INIT_FILE