blob: a30afb2f9f13c54721367d6f85a973e3d3d47818 [file] [log] [blame]
Fred Drakee2e904f1998-03-10 23:23:05 +00001#! /depot/gnu/plat/bin/bash
2
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 Drakeac8f91a1998-04-02 15:37:13 +000016L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
17
Fred Drakedbc879e1998-03-11 15:33:44 +000018LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
19LOGGING=''
20
Fred Drakee2e904f1998-03-10 23:23:05 +000021usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000022 MYNAME=`basename $0`
23 echo "usage: $MYNAME [options...] file ..."
24 cat <<EOF
25
26Options specifying formats to build:
27 --html HyperText Markup Language
28 --pdf Portable Document Format (default)
29 --ps PostScript
30 --dvi "DeVice Indepentent" format from TeX
31
32 More than one output format may be specified.
33
34HTML options:
35 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000036 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000037 --split, -s Specify a section level for page splitting.
38
39Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000040 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000041 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000042 --help, -H Show this text.
43 --logging, -l Log stdout and stderr to a file (*.how).
44 --debugging, -D Echo commands as they are executed.
45 --keep, -k Keep temporary files around.
46 --quiet, -q Do not print command output to stdout.
47 (stderr is also lost, sorry; see *.how for errors)
48
49EOF
50
51 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000052}
53
Fred Drake88053541998-04-24 21:57:12 +000054# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
55# The values here are the defaults after modification by perl/l2hinit.perl.
56#
57ADDRESS=''
58MAX_LINK_DEPTH=3
59MAX_SPLIT_DEPTH=8
60
Fred Drakee2e904f1998-03-10 23:23:05 +000061build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000062 TEXFILE=`kpsewhich $1.tex`
Fred Drake88053541998-04-24 21:57:12 +000063 if [ "$ADDRESS" ] ; then
64 latex2html -init_file $L2H_INIT_FILE \
65 -address "$ADDRESS" \
66 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
Fred Drake8dbf46a1998-05-15 17:13:08 +000067 -dir $1 $TEXFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000068 else
Fred Drake88053541998-04-24 21:57:12 +000069 latex2html -init_file $L2H_INIT_FILE \
70 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
Fred Drake19c7c841998-05-07 21:20:39 +000071 -dir $1 $TEXFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000072 fi
Fred Drake88053541998-04-24 21:57:12 +000073 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +000074 (cd $1; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000075 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000076}
77
Fred Drake12f842e1998-04-17 02:52:12 +000078use_latex() {
79 # two args: <file> <latextype>
80 MYFILE=$1
81 MYLATEX=$2
82 #
83 # We really have to do it three times to get all the page numbers right,
84 # since the length of the ToC makes a real difference.
85 #
86 $MYDIR/newind.py >$MYFILE.ind
87 $MYDIR/newind.py modindex >mod$MYFILE.ind
88 $MYLATEX $MYFILE || exit $?
89 if [ -f mod$MYFILE.idx ] ; then
90 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000091 fi
Fred Drake12f842e1998-04-17 02:52:12 +000092 if [ -f $MYFILE.idx ] ; then
93 $MYDIR/fix_hack $MYFILE.idx
94 makeindex $MYFILE.idx
95 $MYDIR/indfix.py $MYFILE.ind
96 fi
Fred Drake8cab5491998-07-23 19:13:52 +000097 if [ -f $MYFILE.syn ] ; then
98 # This hack is due to a bug with the module synopsis support that
99 # causes the last module synopsis to be written out twice in
100 # howto documents (not present for manuals). Repeated below.
101 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
102 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000103 $MYLATEX $MYFILE || exit $?
104 if [ -f mod$MYFILE.idx ] ; then
105 makeindex mod$MYFILE.idx
106 fi
107 if [ -f $MYFILE.idx ] ; then
108 $MYDIR/fix_hack $MYFILE.idx || exit $?
109 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
110 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000111 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000112 $MYDIR/toc2bkm.py -c section $MYFILE
113 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000114 if [ -f $MYFILE.syn ] ; then
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 $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000118}
119
Fred Drake12f842e1998-04-17 02:52:12 +0000120build_dvi() {
121 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000122}
123
124build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000125 use_latex $1 pdflatex
126}
127
128build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000129 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000130}
131
132cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000133 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 +0000134 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000135 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000136 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000137 fi
Fred Drake8dbf46a1998-05-15 17:13:08 +0000138 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000139}
140
141# figure out what our targets are:
142while [ "$1" ] ; do
143 case "$1" in
144 --pdf|--pd)
145 BUILD_PDF=true
146 USE_DEFAULT_FORMAT=false
147 shift 1
148 ;;
Fred Drake88053541998-04-24 21:57:12 +0000149 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000150 BUILD_PS=true
151 USE_DEFAULT_FORMAT=false
152 shift 1
153 ;;
154 --dvi|--dv|--d)
155 BUILD_DVI=true
156 USE_DEFAULT_FORMAT=false
157 shift 1
158 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000159 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000160 BUILD_HTML=true
161 USE_DEFAULT_FORMAT=false
162 shift 1
163 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000164 -H|--help|--hel|--he)
165 usage 0
166 ;;
Fred Drake35049521998-05-11 19:04:06 +0000167 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000168 ADDRESS="$2"
169 shift 2
170 ;;
Fred Drake35049521998-05-11 19:04:06 +0000171 --a4)
172 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
173 shift 1
174 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000175 --letter|--lette|--lett|--let|--le)
176 shift 1
177 ;;
Fred Drake88053541998-04-24 21:57:12 +0000178 --link|--lin|--li)
179 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000180 shift 2
181 ;;
Fred Drake88053541998-04-24 21:57:12 +0000182 -s|--split|--spli|--spl|--sp|--s)
183 MAX_SPLIT_DEPTH="$2"
184 shift 2
185 ;;
186 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000187 LOGGING=true
188 shift 1
189 ;;
190 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
191 DEBUGGING=true
192 shift 1
193 ;;
194 -k|--keep|--kee|--ke|--k)
195 DISCARD_TEMPS=''
196 shift 1
197 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000198 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000199 QUIET=true
200 shift 1
201 ;;
Fred Drake88053541998-04-24 21:57:12 +0000202 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000203 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000204 break
205 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000206 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000207 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000208 ;;
209 *)
210 break;;
211 esac
212done
213
214if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000215 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000216fi
217
218if [ $USE_DEFAULT_FORMAT = true ] ; then
219 eval "BUILD_$DEFAULT_FORMAT=true"
220fi
221
Fred Drakedbc879e1998-03-11 15:33:44 +0000222if [ "$DEBUGGING" ] ; then
223 set -x
224fi
225
Fred Drake664b36f1998-03-11 15:41:21 +0000226if [ "$QUIET" ] ; then
227 exec >/dev/null
228fi
229
Fred Drakef4fc4761998-05-14 20:03:14 +0000230COMMONTEXINPUTS=$TOPDIR/texinputs:$TEXINPUTS
231
Fred Drakee2e904f1998-03-10 23:23:05 +0000232for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000233 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000234 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000235 #
236 # Put the directory the .tex file is in is also the first directory in
237 # TEXINPUTS, to allow files there to override files in the common area.
238 #
Fred Drakef4fc4761998-05-14 20:03:14 +0000239 TEXINPUTS=$FILEDIR:$COMMONTEXINPUTS
240 export TEXINPUTS
241 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000242 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000243 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000244 fi
245 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000246 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000247 fi
248 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000249 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000250 fi
251 if [ "$BUILD_HTML" ] ; then
252 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
253 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000254 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000255 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000256 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000257 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000258 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000259 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000260 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000261 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000262 if [ "$LOGGING" ] ; then
263 cp $LOGFILE $FILE.how
264 fi
265 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000266done