blob: 9013b2fc9688e0db6f70c3afd6aee5b54a06a0b7 [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
Fred Drake12f842e1998-04-17 02:52:12 +000084use_latex() {
85 # two args: <file> <latextype>
86 MYFILE=$1
87 MYLATEX=$2
88 #
89 # We really have to do it three times to get all the page numbers right,
90 # since the length of the ToC makes a real difference.
91 #
92 $MYDIR/newind.py >$MYFILE.ind
93 $MYDIR/newind.py modindex >mod$MYFILE.ind
94 $MYLATEX $MYFILE || exit $?
95 if [ -f mod$MYFILE.idx ] ; then
96 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +000097 fi
Fred Drake12f842e1998-04-17 02:52:12 +000098 if [ -f $MYFILE.idx ] ; then
99 $MYDIR/fix_hack $MYFILE.idx
100 makeindex $MYFILE.idx
101 $MYDIR/indfix.py $MYFILE.ind
102 fi
103 $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
111 if [ -f $MYFILE.toc ] ; then
112 $MYDIR/toc2bkm.py -c section $MYFILE
113 fi
114 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000115}
116
Fred Drake12f842e1998-04-17 02:52:12 +0000117build_dvi() {
118 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000119}
120
121build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000122 use_latex $1 pdflatex
123}
124
125build_ps() {
126 dvips -N0 -o $1.ps -f $1 || exit $?
127}
128
129cleanup() {
130 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ind
131 if [ ! "$BUILD_DVI" ] ; then
132 rm -f $FILE.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000133 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000134}
135
136# figure out what our targets are:
137while [ "$1" ] ; do
138 case "$1" in
139 --pdf|--pd)
140 BUILD_PDF=true
141 USE_DEFAULT_FORMAT=false
142 shift 1
143 ;;
144 --ps)
145 BUILD_PS=true
146 USE_DEFAULT_FORMAT=false
147 shift 1
148 ;;
149 --dvi|--dv|--d)
150 BUILD_DVI=true
151 USE_DEFAULT_FORMAT=false
152 shift 1
153 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000154 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000155 BUILD_HTML=true
156 USE_DEFAULT_FORMAT=false
157 shift 1
158 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000159 -H|--help|--hel|--he)
160 usage 0
161 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000162 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
163 ADDRESS="$2"
164 shift 2
165 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000166 -s|--split|--spli|--spl|--sp|--s)
167 HTML_SPLIT_LEVEL="$2"
168 shift 2
169 ;;
Fred Drakedbc879e1998-03-11 15:33:44 +0000170 -l|--logging|--loggin|--loggi|--logg|--log|--lo|--l)
171 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 Drakee2e904f1998-03-10 23:23:05 +0000186 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000187 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000188 ;;
189 *)
190 break;;
191 esac
192done
193
194if [ $# = 0 ] ; then
Fred Drakeac8f91a1998-04-02 15:37:13 +0000195 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000196fi
197
198if [ $USE_DEFAULT_FORMAT = true ] ; then
199 eval "BUILD_$DEFAULT_FORMAT=true"
200fi
201
Fred Drakedbc879e1998-03-11 15:33:44 +0000202if [ "$DEBUGGING" ] ; then
203 set -x
204fi
205
Fred Drake664b36f1998-03-11 15:41:21 +0000206if [ "$QUIET" ] ; then
207 exec >/dev/null
208fi
209
Fred Drakee2e904f1998-03-10 23:23:05 +0000210for FILE in $@ ; do
211 FILE=${FILE%.tex}
212 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000213 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000214 fi
215 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000216 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000217 fi
218 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000219 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000220 fi
221 if [ "$BUILD_HTML" ] ; then
222 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
223 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000224 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000225 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000226 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000227 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000228 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000229 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000230 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000231 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000232 if [ "$LOGGING" ] ; then
233 cp $LOGFILE $FILE.how
234 fi
235 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000236done