blob: 417ba323abe97fe1b66f06f77ceadf7e1feb5fb8 [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 +000016HTML_SPLIT_LEVEL=''
17L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
18
Fred Drakee2e904f1998-03-10 23:23:05 +000019# This is needed to support kpathsea based TeX installations. Others are
20# not supported. ;-)
Fred Drakedbc879e1998-03-11 15:33:44 +000021TEXINPUTS=`dirname $MYDIR`/texinputs:$TEXINPUTS
Fred Drakee2e904f1998-03-10 23:23:05 +000022export TEXINPUTS
23
Fred Drakedbc879e1998-03-11 15:33:44 +000024LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
25LOGGING=''
26
Fred Drakee2e904f1998-03-10 23:23:05 +000027usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000028 MYNAME=`basename $0`
29 echo "usage: $MYNAME [options...] file ..."
30 cat <<EOF
31
32Options specifying formats to build:
33 --html HyperText Markup Language
34 --pdf Portable Document Format (default)
35 --ps PostScript
36 --dvi "DeVice Indepentent" format from TeX
37
38 More than one output format may be specified.
39
40HTML options:
41 --address, -a Specify an address for page footers.
42 --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
57build_html() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000058 if [ "$HTML_SPLIT_LEVEL" ] ; then
59 if [ "$ADDRESS" ] ; then
60 latex2html -init_file $L2H_INIT_FILE \
61 -address "$ADDRESS" \
62 -split $HTML_SPLIT_LEVEL \
63 $1 || exit $?
64 else
65 latex2html -init_file $L2H_INIT_FILE \
66 -split $HTML_SPLIT_LEVEL \
67 $1 || exit $?
68 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000069 else
Fred Drakeac8f91a1998-04-02 15:37:13 +000070 if [ "$ADDRESS" ] ; then
71 latex2html -init_file $L2H_INIT_FILE \
72 -address "$ADDRESS" \
73 $1 || exit $?
74 else
75 latex2html -init_file $L2H_INIT_FILE \
76 $1 || exit $?
77 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000078 fi
Fred Drakeac8f91a1998-04-02 15:37:13 +000079 if [ "$HTML_SPLIT_LEVEL" != 1 ] ; then
80 (cd $FILE; $MYDIR/node2label.pl *.html) || exit $?
81 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000082}
83
84build_dvi() {
85 latex $1 || exit $?
Fred Drake11254881998-03-18 22:06:13 +000086 latex $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000087 if [ -f $1.idx ] ; then
88 `dirname $0`/fix_hack $1.idx || exit $?
89 makeindex $1.idx || exit $?
90 fi
91 latex $1 || exit $?
92}
93
94build_ps() {
Fred Drakedbc879e1998-03-11 15:33:44 +000095 # note weird sequence of redirects is used to get stderr to the old stdout
96 # and the new stdout goes to a file
Fred Drakee2e904f1998-03-10 23:23:05 +000097 dvips -N0 -f $1 >$1.ps || exit $?
98}
99
100build_pdf() {
101 # We really have to do it three times to get all the page numbers right,
102 # since the length of the ToC makes a real difference.
103 pdflatex $1 || exit $?
104 pdflatex $1 || exit $?
105 `dirname $0`/toc2bkm.py -c section $FILE || exit $?
106 if [ -f $1.idx ] ; then
107 `dirname $0`/fix_hack $1.idx || exit $?
108 makeindex $1.idx || exit $?
109 fi
110 pdflatex $1 || exit $?
111}
112
113# figure out what our targets are:
114while [ "$1" ] ; do
115 case "$1" in
116 --pdf|--pd)
117 BUILD_PDF=true
118 USE_DEFAULT_FORMAT=false
119 shift 1
120 ;;
121 --ps)
122 BUILD_PS=true
123 USE_DEFAULT_FORMAT=false
124 shift 1
125 ;;
126 --dvi|--dv|--d)
127 BUILD_DVI=true
128 USE_DEFAULT_FORMAT=false
129 shift 1
130 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000131 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000132 BUILD_HTML=true
133 USE_DEFAULT_FORMAT=false
134 shift 1
135 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000136 -H|--help|--hel|--he)
137 usage 0
138 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000139 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
140 ADDRESS="$2"
141 shift 2
142 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000143 -s|--split|--spli|--spl|--sp|--s)
144 HTML_SPLIT_LEVEL="$2"
145 shift 2
146 ;;
Fred Drakedbc879e1998-03-11 15:33:44 +0000147 -l|--logging|--loggin|--loggi|--logg|--log|--lo|--l)
148 LOGGING=true
149 shift 1
150 ;;
151 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
152 DEBUGGING=true
153 shift 1
154 ;;
155 -k|--keep|--kee|--ke|--k)
156 DISCARD_TEMPS=''
157 shift 1
158 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000159 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000160 QUIET=true
161 shift 1
162 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000163 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000164 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000165 ;;
166 *)
167 break;;
168 esac
169done
170
171if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000172 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000173fi
174
175if [ $USE_DEFAULT_FORMAT = true ] ; then
176 eval "BUILD_$DEFAULT_FORMAT=true"
177fi
178
Fred Drakedbc879e1998-03-11 15:33:44 +0000179if [ "$DEBUGGING" ] ; then
180 set -x
181fi
182
Fred Drake664b36f1998-03-11 15:41:21 +0000183if [ "$QUIET" ] ; then
184 exec >/dev/null
185fi
186
Fred Drakee2e904f1998-03-10 23:23:05 +0000187for FILE in $@ ; do
188 FILE=${FILE%.tex}
189 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000190 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000191 fi
192 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000193 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000194 fi
195 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000196 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000197 fi
198 if [ "$BUILD_HTML" ] ; then
199 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
200 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000201 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000202 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000203 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000204 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000205 if [ "$DISCARD_TEMPS" ] ; then
206 rm -f $FILE.aux $FILE.log $FILE.out $FILE.toc $FILE.bkm 2>&1 \
207 | tee -a $LOGFILE
208 if [ ! "$BUILD_DVI" ] ; then
209 rm -f $FILE.dvi 2>&1 | tee -a $LOGFILE
210 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000211 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000212 # the the logfile around
213 if [ "$LOGGING" ] ; then
214 cp $LOGFILE $FILE.how
215 fi
216 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000217done