blob: 6291cdb7acbf667e0c4b469496b0bc4906781728 [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 Drake476412a1998-04-17 20:25:55 +0000126 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ind mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000127 if [ ! "$BUILD_DVI" ] ; then
128 rm -f $FILE.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000129 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000130}
131
132# figure out what our targets are:
133while [ "$1" ] ; do
134 case "$1" in
135 --pdf|--pd)
136 BUILD_PDF=true
137 USE_DEFAULT_FORMAT=false
138 shift 1
139 ;;
Fred Drake88053541998-04-24 21:57:12 +0000140 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000141 BUILD_PS=true
142 USE_DEFAULT_FORMAT=false
143 shift 1
144 ;;
145 --dvi|--dv|--d)
146 BUILD_DVI=true
147 USE_DEFAULT_FORMAT=false
148 shift 1
149 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000150 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000151 BUILD_HTML=true
152 USE_DEFAULT_FORMAT=false
153 shift 1
154 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000155 -H|--help|--hel|--he)
156 usage 0
157 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000158 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
159 ADDRESS="$2"
160 shift 2
161 ;;
Fred Drake88053541998-04-24 21:57:12 +0000162 --link|--lin|--li)
163 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000164 shift 2
165 ;;
Fred Drake88053541998-04-24 21:57:12 +0000166 -s|--split|--spli|--spl|--sp|--s)
167 MAX_SPLIT_DEPTH="$2"
168 shift 2
169 ;;
170 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000171 LOGGING=true
172 shift 1
173 ;;
174 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
175 DEBUGGING=true
176 shift 1
177 ;;
178 -k|--keep|--kee|--ke|--k)
179 DISCARD_TEMPS=''
180 shift 1
181 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000182 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000183 QUIET=true
184 shift 1
185 ;;
Fred Drake88053541998-04-24 21:57:12 +0000186 --)
187 break
188 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000189 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000190 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000191 ;;
192 *)
193 break;;
194 esac
195done
196
197if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000198 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000199fi
200
201if [ $USE_DEFAULT_FORMAT = true ] ; then
202 eval "BUILD_$DEFAULT_FORMAT=true"
203fi
204
Fred Drakedbc879e1998-03-11 15:33:44 +0000205if [ "$DEBUGGING" ] ; then
206 set -x
207fi
208
Fred Drake664b36f1998-03-11 15:41:21 +0000209if [ "$QUIET" ] ; then
210 exec >/dev/null
211fi
212
Fred Drakee2e904f1998-03-10 23:23:05 +0000213for FILE in $@ ; do
214 FILE=${FILE%.tex}
215 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000216 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000217 fi
218 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000219 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000220 fi
221 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000222 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000223 fi
224 if [ "$BUILD_HTML" ] ; then
225 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
226 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000227 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000228 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000229 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000230 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000231 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000232 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000233 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000234 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000235 if [ "$LOGGING" ] ; then
236 cp $LOGFILE $FILE.how
237 fi
238 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000239done