blob: 0541c85bbd9e97a3a7d430b55ee9ba54ecee6bec [file] [log] [blame]
Fred Drakee2e904f1998-03-10 23:23:05 +00001#! /depot/gnu/plat/bin/bash
2
3MYDIR=`dirname $0`
4
5# DEFAULT_FORMAT must be upper case...
6DEFAULT_FORMAT=PDF
7USE_DEFAULT_FORMAT=true
Fred Drakedbc879e1998-03-11 15:33:44 +00008DISCARD_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +00009
10# This is needed to support kpathsea based TeX installations. Others are
11# not supported. ;-)
Fred Drakedbc879e1998-03-11 15:33:44 +000012TEXINPUTS=`dirname $MYDIR`/texinputs:$TEXINPUTS
Fred Drakee2e904f1998-03-10 23:23:05 +000013export TEXINPUTS
14
Fred Drakedbc879e1998-03-11 15:33:44 +000015LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
16LOGGING=''
17
Fred Drakee2e904f1998-03-10 23:23:05 +000018usage() {
19 echo "usage: $0 [options...] file ..."
20 exit 2
21}
22
23build_html() {
24 # This doesn't work; l2hinit.perl uses the current directory, not it's own
25 # location. Need a workaround for this.
26 if [ "$ADDRESS" ] ; then
27 latex2html -init_file $MYDIR/../perl/l2hinit.perl -address "$ADDRESS" \
28 $1 || exit $?
29 else
30 latex2html -init_file $MYDIR/../perl/l2hinit.perl $1 || exit $?
31 fi
32 (cd $FILE; $MYDIR/node2label.pl *.html) || exit $?
33}
34
35build_dvi() {
36 latex $1 || exit $?
37 if [ -f $1.idx ] ; then
38 `dirname $0`/fix_hack $1.idx || exit $?
39 makeindex $1.idx || exit $?
40 fi
41 latex $1 || exit $?
42}
43
44build_ps() {
Fred Drakedbc879e1998-03-11 15:33:44 +000045 # note weird sequence of redirects is used to get stderr to the old stdout
46 # and the new stdout goes to a file
Fred Drakee2e904f1998-03-10 23:23:05 +000047 dvips -N0 -f $1 >$1.ps || exit $?
48}
49
50build_pdf() {
51 # We really have to do it three times to get all the page numbers right,
52 # since the length of the ToC makes a real difference.
53 pdflatex $1 || exit $?
54 pdflatex $1 || exit $?
55 `dirname $0`/toc2bkm.py -c section $FILE || exit $?
56 if [ -f $1.idx ] ; then
57 `dirname $0`/fix_hack $1.idx || exit $?
58 makeindex $1.idx || exit $?
59 fi
60 pdflatex $1 || exit $?
61}
62
63# figure out what our targets are:
64while [ "$1" ] ; do
65 case "$1" in
66 --pdf|--pd)
67 BUILD_PDF=true
68 USE_DEFAULT_FORMAT=false
69 shift 1
70 ;;
71 --ps)
72 BUILD_PS=true
73 USE_DEFAULT_FORMAT=false
74 shift 1
75 ;;
76 --dvi|--dv|--d)
77 BUILD_DVI=true
78 USE_DEFAULT_FORMAT=false
79 shift 1
80 ;;
81 --html|--htm|--ht|--h)
82 BUILD_HTML=true
83 USE_DEFAULT_FORMAT=false
84 shift 1
85 ;;
86 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
87 ADDRESS="$2"
88 shift 2
89 ;;
Fred Drakedbc879e1998-03-11 15:33:44 +000090 -l|--logging|--loggin|--loggi|--logg|--log|--lo|--l)
91 LOGGING=true
92 shift 1
93 ;;
94 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
95 DEBUGGING=true
96 shift 1
97 ;;
98 -k|--keep|--kee|--ke|--k)
99 DISCARD_TEMPS=''
100 shift 1
101 ;;
Fred Drake664b36f1998-03-11 15:41:21 +0000102 -q|--quiet|__quie|--qui|--qu|--q)
103 QUIET=true
104 shift 1
105 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000106 -*)
107 usage
108 ;;
109 *)
110 break;;
111 esac
112done
113
114if [ $# = 0 ] ; then
115 usage
116fi
117
118if [ $USE_DEFAULT_FORMAT = true ] ; then
119 eval "BUILD_$DEFAULT_FORMAT=true"
120fi
121
Fred Drakedbc879e1998-03-11 15:33:44 +0000122if [ "$DEBUGGING" ] ; then
123 set -x
124fi
125
Fred Drake664b36f1998-03-11 15:41:21 +0000126if [ "$QUIET" ] ; then
127 exec >/dev/null
128fi
129
Fred Drakee2e904f1998-03-10 23:23:05 +0000130for FILE in $@ ; do
131 FILE=${FILE%.tex}
132 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000133 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000134 fi
135 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000136 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000137 fi
138 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000139 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000140 fi
141 if [ "$BUILD_HTML" ] ; then
142 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
143 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000144 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000145 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000146 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000147 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000148 if [ "$DISCARD_TEMPS" ] ; then
149 rm -f $FILE.aux $FILE.log $FILE.out $FILE.toc $FILE.bkm 2>&1 \
150 | tee -a $LOGFILE
151 if [ ! "$BUILD_DVI" ] ; then
152 rm -f $FILE.dvi 2>&1 | tee -a $LOGFILE
153 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000154 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000155 # the the logfile around
156 if [ "$LOGGING" ] ; then
157 cp $LOGFILE $FILE.how
158 fi
159 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000160done