blob: ec480c517db6ced45eee657aeccc7e8ae7ef7fbf [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 Drake11300cc1998-08-05 04:48:18 +000067 latex2html \
68 -init_file $L2H_INIT_FILE \
69 -init_file $L2H_AUX_INIT_FILE \
70 -dir $1 $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000071 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +000072 (cd $1; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000073 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000074}
75
Fred Drake12f842e1998-04-17 02:52:12 +000076use_latex() {
77 # two args: <file> <latextype>
78 MYFILE=$1
79 MYLATEX=$2
80 #
81 # We really have to do it three times to get all the page numbers right,
82 # since the length of the ToC makes a real difference.
83 #
84 $MYDIR/newind.py >$MYFILE.ind
85 $MYDIR/newind.py modindex >mod$MYFILE.ind
86 $MYLATEX $MYFILE || exit $?
87 if [ -f mod$MYFILE.idx ] ; then
88 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000089 fi
Fred Drake12f842e1998-04-17 02:52:12 +000090 if [ -f $MYFILE.idx ] ; then
91 $MYDIR/fix_hack $MYFILE.idx
92 makeindex $MYFILE.idx
93 $MYDIR/indfix.py $MYFILE.ind
94 fi
Fred Drake8cab5491998-07-23 19:13:52 +000095 if [ -f $MYFILE.syn ] ; then
96 # This hack is due to a bug with the module synopsis support that
97 # causes the last module synopsis to be written out twice in
98 # howto documents (not present for manuals). Repeated below.
99 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
100 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000101 $MYLATEX $MYFILE || exit $?
102 if [ -f mod$MYFILE.idx ] ; then
103 makeindex mod$MYFILE.idx
104 fi
105 if [ -f $MYFILE.idx ] ; then
106 $MYDIR/fix_hack $MYFILE.idx || exit $?
107 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
108 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000109 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000110 $MYDIR/toc2bkm.py -c section $MYFILE
111 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000112 if [ -f $MYFILE.syn ] ; then
113 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
114 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000115 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000116}
117
Fred Drake12f842e1998-04-17 02:52:12 +0000118build_dvi() {
119 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000120}
121
122build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000123 use_latex $1 pdflatex
124}
125
126build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000127 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000128}
129
Fred Drake11300cc1998-08-05 04:48:18 +0000130l2hoption() {
131 if [ "$2" ] ; then
132 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
133 fi
134}
135
Fred Drake12f842e1998-04-17 02:52:12 +0000136cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000137 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 +0000138 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000139 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000140 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000141 fi
Fred Drake8dbf46a1998-05-15 17:13:08 +0000142 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000143}
144
145# figure out what our targets are:
146while [ "$1" ] ; do
147 case "$1" in
148 --pdf|--pd)
149 BUILD_PDF=true
150 USE_DEFAULT_FORMAT=false
151 shift 1
152 ;;
Fred Drake88053541998-04-24 21:57:12 +0000153 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000154 BUILD_PS=true
155 USE_DEFAULT_FORMAT=false
156 shift 1
157 ;;
158 --dvi|--dv|--d)
159 BUILD_DVI=true
160 USE_DEFAULT_FORMAT=false
161 shift 1
162 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000163 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000164 BUILD_HTML=true
165 USE_DEFAULT_FORMAT=false
166 shift 1
167 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000168 -H|--help|--hel|--he)
169 usage 0
170 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000171 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
172 ICONSERVER="$2"
173 shift 2
174 ;;
Fred Drake35049521998-05-11 19:04:06 +0000175 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000176 ADDRESS="$2"
177 shift 2
178 ;;
Fred Drake35049521998-05-11 19:04:06 +0000179 --a4)
180 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
181 shift 1
182 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000183 --letter|--lette|--lett|--let|--le)
184 shift 1
185 ;;
Fred Drake88053541998-04-24 21:57:12 +0000186 --link|--lin|--li)
187 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000188 shift 2
189 ;;
Fred Drake88053541998-04-24 21:57:12 +0000190 -s|--split|--spli|--spl|--sp|--s)
191 MAX_SPLIT_DEPTH="$2"
192 shift 2
193 ;;
194 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000195 LOGGING=true
196 shift 1
197 ;;
198 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
199 DEBUGGING=true
200 shift 1
201 ;;
202 -k|--keep|--kee|--ke|--k)
203 DISCARD_TEMPS=''
204 shift 1
205 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000206 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000207 QUIET=true
208 shift 1
209 ;;
Fred Drake88053541998-04-24 21:57:12 +0000210 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000211 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000212 break
213 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000214 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000215 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000216 ;;
217 *)
218 break;;
219 esac
220done
221
222if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000223 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000224fi
225
226if [ $USE_DEFAULT_FORMAT = true ] ; then
227 eval "BUILD_$DEFAULT_FORMAT=true"
228fi
229
Fred Drakedbc879e1998-03-11 15:33:44 +0000230if [ "$DEBUGGING" ] ; then
231 set -x
232fi
233
Fred Drake664b36f1998-03-11 15:41:21 +0000234if [ "$QUIET" ] ; then
235 exec >/dev/null
236fi
237
Fred Drake11300cc1998-08-05 04:48:18 +0000238echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
239echo '# generated by mkhowto.sh -- do no edit' >>$L2H_AUX_INIT_FILE
240l2hoption ICONSERVER "$ICONSERVER"
241l2hoption ADDRESS "$ADDRESS"
242l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
243l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
244echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000245
Fred Drakee2e904f1998-03-10 23:23:05 +0000246for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000247 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000248 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000249 #
250 # Put the directory the .tex file is in is also the first directory in
251 # TEXINPUTS, to allow files there to override files in the common area.
252 #
Fred Drake11300cc1998-08-05 04:48:18 +0000253 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000254 export TEXINPUTS
255 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000256 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000257 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000258 fi
259 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000260 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000261 fi
262 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000263 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000264 fi
265 if [ "$BUILD_HTML" ] ; then
266 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
267 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000268 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000269 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000270 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000271 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000272 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000273 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000274 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000275 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000276 if [ "$LOGGING" ] ; then
277 cp $LOGFILE $FILE.how
278 fi
279 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000280done
Fred Drake11300cc1998-08-05 04:48:18 +0000281
282rm -f $L2H_AUX_INIT_FILE