blob: 6b6bb962c61471e6fd5b5f8ae060ea197405ed4d [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 $?
Fred Drake11254881998-03-18 22:06:13 +000037 latex $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000038 if [ -f $1.idx ] ; then
39 `dirname $0`/fix_hack $1.idx || exit $?
40 makeindex $1.idx || exit $?
41 fi
42 latex $1 || exit $?
43}
44
45build_ps() {
Fred Drakedbc879e1998-03-11 15:33:44 +000046 # note weird sequence of redirects is used to get stderr to the old stdout
47 # and the new stdout goes to a file
Fred Drakee2e904f1998-03-10 23:23:05 +000048 dvips -N0 -f $1 >$1.ps || exit $?
49}
50
51build_pdf() {
52 # We really have to do it three times to get all the page numbers right,
53 # since the length of the ToC makes a real difference.
54 pdflatex $1 || exit $?
55 pdflatex $1 || exit $?
56 `dirname $0`/toc2bkm.py -c section $FILE || exit $?
57 if [ -f $1.idx ] ; then
58 `dirname $0`/fix_hack $1.idx || exit $?
59 makeindex $1.idx || exit $?
60 fi
61 pdflatex $1 || exit $?
62}
63
64# figure out what our targets are:
65while [ "$1" ] ; do
66 case "$1" in
67 --pdf|--pd)
68 BUILD_PDF=true
69 USE_DEFAULT_FORMAT=false
70 shift 1
71 ;;
72 --ps)
73 BUILD_PS=true
74 USE_DEFAULT_FORMAT=false
75 shift 1
76 ;;
77 --dvi|--dv|--d)
78 BUILD_DVI=true
79 USE_DEFAULT_FORMAT=false
80 shift 1
81 ;;
82 --html|--htm|--ht|--h)
83 BUILD_HTML=true
84 USE_DEFAULT_FORMAT=false
85 shift 1
86 ;;
87 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
88 ADDRESS="$2"
89 shift 2
90 ;;
Fred Drakedbc879e1998-03-11 15:33:44 +000091 -l|--logging|--loggin|--loggi|--logg|--log|--lo|--l)
92 LOGGING=true
93 shift 1
94 ;;
95 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
96 DEBUGGING=true
97 shift 1
98 ;;
99 -k|--keep|--kee|--ke|--k)
100 DISCARD_TEMPS=''
101 shift 1
102 ;;
Fred Drake664b36f1998-03-11 15:41:21 +0000103 -q|--quiet|__quie|--qui|--qu|--q)
104 QUIET=true
105 shift 1
106 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000107 -*)
108 usage
109 ;;
110 *)
111 break;;
112 esac
113done
114
115if [ $# = 0 ] ; then
116 usage
117fi
118
119if [ $USE_DEFAULT_FORMAT = true ] ; then
120 eval "BUILD_$DEFAULT_FORMAT=true"
121fi
122
Fred Drakedbc879e1998-03-11 15:33:44 +0000123if [ "$DEBUGGING" ] ; then
124 set -x
125fi
126
Fred Drake664b36f1998-03-11 15:41:21 +0000127if [ "$QUIET" ] ; then
128 exec >/dev/null
129fi
130
Fred Drakee2e904f1998-03-10 23:23:05 +0000131for FILE in $@ ; do
132 FILE=${FILE%.tex}
133 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000134 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000135 fi
136 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000137 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000138 fi
139 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000140 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000141 fi
142 if [ "$BUILD_HTML" ] ; then
143 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
144 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000145 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000146 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000147 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000148 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000149 if [ "$DISCARD_TEMPS" ] ; then
150 rm -f $FILE.aux $FILE.log $FILE.out $FILE.toc $FILE.bkm 2>&1 \
151 | tee -a $LOGFILE
152 if [ ! "$BUILD_DVI" ] ; then
153 rm -f $FILE.dvi 2>&1 | tee -a $LOGFILE
154 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000155 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000156 # the the logfile around
157 if [ "$LOGGING" ] ; then
158 cp $LOGFILE $FILE.how
159 fi
160 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000161done