blob: fe47beac28d1e8c7b1f5e1bce2c10117eba5cd2e [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 Drakee2e904f1998-03-10 23:23:05 +000018# This is needed to support kpathsea based TeX installations. Others are
19# not supported. ;-)
Fred Drakedbc879e1998-03-11 15:33:44 +000020TEXINPUTS=`dirname $MYDIR`/texinputs:$TEXINPUTS
Fred Drakee2e904f1998-03-10 23:23:05 +000021export TEXINPUTS
22
Fred Drakedbc879e1998-03-11 15:33:44 +000023LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
24LOGGING=''
25
Fred Drakee2e904f1998-03-10 23:23:05 +000026usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000027 MYNAME=`basename $0`
28 echo "usage: $MYNAME [options...] file ..."
29 cat <<EOF
30
31Options specifying formats to build:
32 --html HyperText Markup Language
33 --pdf Portable Document Format (default)
34 --ps PostScript
35 --dvi "DeVice Indepentent" format from TeX
36
37 More than one output format may be specified.
38
39HTML options:
40 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000041 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000042 --split, -s Specify a section level for page splitting.
43
44Other options:
45 --help, -H Show this text.
46 --logging, -l Log stdout and stderr to a file (*.how).
47 --debugging, -D Echo commands as they are executed.
48 --keep, -k Keep temporary files around.
49 --quiet, -q Do not print command output to stdout.
50 (stderr is also lost, sorry; see *.how for errors)
51
52EOF
53
54 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000055}
56
Fred Drake88053541998-04-24 21:57:12 +000057# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
58# The values here are the defaults after modification by perl/l2hinit.perl.
59#
60ADDRESS=''
61MAX_LINK_DEPTH=3
62MAX_SPLIT_DEPTH=8
63
Fred Drakee2e904f1998-03-10 23:23:05 +000064build_html() {
Fred Drake88053541998-04-24 21:57:12 +000065 if [ "$ADDRESS" ] ; then
66 latex2html -init_file $L2H_INIT_FILE \
67 -address "$ADDRESS" \
68 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
69 $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000070 else
Fred Drake88053541998-04-24 21:57:12 +000071 latex2html -init_file $L2H_INIT_FILE \
72 -link $MAX_LINK_DEPTH -split $MAX_SPLIT_DEPTH \
73 $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000074 fi
Fred Drake88053541998-04-24 21:57:12 +000075 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +000076 (cd $FILE; $MYDIR/node2label.pl *.html) || exit $?
77 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000078}
79
Fred Drake12f842e1998-04-17 02:52:12 +000080use_latex() {
81 # two args: <file> <latextype>
82 MYFILE=$1
83 MYLATEX=$2
84 #
85 # We really have to do it three times to get all the page numbers right,
86 # since the length of the ToC makes a real difference.
87 #
88 $MYDIR/newind.py >$MYFILE.ind
89 $MYDIR/newind.py modindex >mod$MYFILE.ind
90 $MYLATEX $MYFILE || exit $?
91 if [ -f mod$MYFILE.idx ] ; then
92 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000093 fi
Fred Drake12f842e1998-04-17 02:52:12 +000094 if [ -f $MYFILE.idx ] ; then
95 $MYDIR/fix_hack $MYFILE.idx
96 makeindex $MYFILE.idx
97 $MYDIR/indfix.py $MYFILE.ind
98 fi
99 $MYLATEX $MYFILE || exit $?
100 if [ -f mod$MYFILE.idx ] ; then
101 makeindex mod$MYFILE.idx
102 fi
103 if [ -f $MYFILE.idx ] ; then
104 $MYDIR/fix_hack $MYFILE.idx || exit $?
105 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
106 fi
107 if [ -f $MYFILE.toc ] ; then
108 $MYDIR/toc2bkm.py -c section $MYFILE
109 fi
110 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000111}
112
Fred Drake12f842e1998-04-17 02:52:12 +0000113build_dvi() {
114 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000115}
116
117build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000118 use_latex $1 pdflatex
119}
120
121build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000122 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000123}
124
125cleanup() {
Fred Drakec9b8a571998-04-29 21:28:25 +0000126 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind
127 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000128 if [ ! "$BUILD_DVI" ] ; then
129 rm -f $FILE.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000130 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000131}
132
133# figure out what our targets are:
134while [ "$1" ] ; do
135 case "$1" in
136 --pdf|--pd)
137 BUILD_PDF=true
138 USE_DEFAULT_FORMAT=false
139 shift 1
140 ;;
Fred Drake88053541998-04-24 21:57:12 +0000141 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000142 BUILD_PS=true
143 USE_DEFAULT_FORMAT=false
144 shift 1
145 ;;
146 --dvi|--dv|--d)
147 BUILD_DVI=true
148 USE_DEFAULT_FORMAT=false
149 shift 1
150 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000151 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000152 BUILD_HTML=true
153 USE_DEFAULT_FORMAT=false
154 shift 1
155 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000156 -H|--help|--hel|--he)
157 usage 0
158 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000159 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
160 ADDRESS="$2"
161 shift 2
162 ;;
Fred Drake88053541998-04-24 21:57:12 +0000163 --link|--lin|--li)
164 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000165 shift 2
166 ;;
Fred Drake88053541998-04-24 21:57:12 +0000167 -s|--split|--spli|--spl|--sp|--s)
168 MAX_SPLIT_DEPTH="$2"
169 shift 2
170 ;;
171 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000172 LOGGING=true
173 shift 1
174 ;;
175 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
176 DEBUGGING=true
177 shift 1
178 ;;
179 -k|--keep|--kee|--ke|--k)
180 DISCARD_TEMPS=''
181 shift 1
182 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000183 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000184 QUIET=true
185 shift 1
186 ;;
Fred Drake88053541998-04-24 21:57:12 +0000187 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000188 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000189 break
190 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000191 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000192 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000193 ;;
194 *)
195 break;;
196 esac
197done
198
199if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000200 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000201fi
202
203if [ $USE_DEFAULT_FORMAT = true ] ; then
204 eval "BUILD_$DEFAULT_FORMAT=true"
205fi
206
Fred Drakedbc879e1998-03-11 15:33:44 +0000207if [ "$DEBUGGING" ] ; then
208 set -x
209fi
210
Fred Drake664b36f1998-03-11 15:41:21 +0000211if [ "$QUIET" ] ; then
212 exec >/dev/null
213fi
214
Fred Drakee2e904f1998-03-10 23:23:05 +0000215for FILE in $@ ; do
216 FILE=${FILE%.tex}
217 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000218 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000219 fi
220 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000221 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000222 fi
223 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000224 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000225 fi
226 if [ "$BUILD_HTML" ] ; then
227 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
228 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000229 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000230 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000231 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000232 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000233 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000234 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000235 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000236 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000237 if [ "$LOGGING" ] ; then
238 cp $LOGFILE $FILE.how
239 fi
240 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000241done