blob: e3a0b7f4cf88610949bd941d07c8bd1dabb6b4fd [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`
7cd $WORKDIR
Fred Drakee2e904f1998-03-10 23:23:05 +00008
9# DEFAULT_FORMAT must be upper case...
10DEFAULT_FORMAT=PDF
11USE_DEFAULT_FORMAT=true
Fred Drakedbc879e1998-03-11 15:33:44 +000012DISCARD_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +000013
14# This is needed to support kpathsea based TeX installations. Others are
15# not supported. ;-)
Fred Drakedbc879e1998-03-11 15:33:44 +000016TEXINPUTS=`dirname $MYDIR`/texinputs:$TEXINPUTS
Fred Drakee2e904f1998-03-10 23:23:05 +000017export TEXINPUTS
18
Fred Drakedbc879e1998-03-11 15:33:44 +000019LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
20LOGGING=''
21
Fred Drakee2e904f1998-03-10 23:23:05 +000022usage() {
23 echo "usage: $0 [options...] file ..."
24 exit 2
25}
26
27build_html() {
28 # This doesn't work; l2hinit.perl uses the current directory, not it's own
29 # location. Need a workaround for this.
30 if [ "$ADDRESS" ] ; then
31 latex2html -init_file $MYDIR/../perl/l2hinit.perl -address "$ADDRESS" \
32 $1 || exit $?
33 else
34 latex2html -init_file $MYDIR/../perl/l2hinit.perl $1 || exit $?
35 fi
36 (cd $FILE; $MYDIR/node2label.pl *.html) || exit $?
37}
38
39build_dvi() {
40 latex $1 || exit $?
Fred Drake11254881998-03-18 22:06:13 +000041 latex $1 || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +000042 if [ -f $1.idx ] ; then
43 `dirname $0`/fix_hack $1.idx || exit $?
44 makeindex $1.idx || exit $?
45 fi
46 latex $1 || exit $?
47}
48
49build_ps() {
Fred Drakedbc879e1998-03-11 15:33:44 +000050 # note weird sequence of redirects is used to get stderr to the old stdout
51 # and the new stdout goes to a file
Fred Drakee2e904f1998-03-10 23:23:05 +000052 dvips -N0 -f $1 >$1.ps || exit $?
53}
54
55build_pdf() {
56 # We really have to do it three times to get all the page numbers right,
57 # since the length of the ToC makes a real difference.
58 pdflatex $1 || exit $?
59 pdflatex $1 || exit $?
60 `dirname $0`/toc2bkm.py -c section $FILE || exit $?
61 if [ -f $1.idx ] ; then
62 `dirname $0`/fix_hack $1.idx || exit $?
63 makeindex $1.idx || exit $?
64 fi
65 pdflatex $1 || exit $?
66}
67
68# figure out what our targets are:
69while [ "$1" ] ; do
70 case "$1" in
71 --pdf|--pd)
72 BUILD_PDF=true
73 USE_DEFAULT_FORMAT=false
74 shift 1
75 ;;
76 --ps)
77 BUILD_PS=true
78 USE_DEFAULT_FORMAT=false
79 shift 1
80 ;;
81 --dvi|--dv|--d)
82 BUILD_DVI=true
83 USE_DEFAULT_FORMAT=false
84 shift 1
85 ;;
86 --html|--htm|--ht|--h)
87 BUILD_HTML=true
88 USE_DEFAULT_FORMAT=false
89 shift 1
90 ;;
91 -a|--address|--addres|--addre|-addr|--add|--ad|--a)
92 ADDRESS="$2"
93 shift 2
94 ;;
Fred Drakedbc879e1998-03-11 15:33:44 +000095 -l|--logging|--loggin|--loggi|--logg|--log|--lo|--l)
96 LOGGING=true
97 shift 1
98 ;;
99 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
100 DEBUGGING=true
101 shift 1
102 ;;
103 -k|--keep|--kee|--ke|--k)
104 DISCARD_TEMPS=''
105 shift 1
106 ;;
Fred Drake664b36f1998-03-11 15:41:21 +0000107 -q|--quiet|__quie|--qui|--qu|--q)
108 QUIET=true
109 shift 1
110 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000111 -*)
112 usage
113 ;;
114 *)
115 break;;
116 esac
117done
118
119if [ $# = 0 ] ; then
120 usage
121fi
122
123if [ $USE_DEFAULT_FORMAT = true ] ; then
124 eval "BUILD_$DEFAULT_FORMAT=true"
125fi
126
Fred Drakedbc879e1998-03-11 15:33:44 +0000127if [ "$DEBUGGING" ] ; then
128 set -x
129fi
130
Fred Drake664b36f1998-03-11 15:41:21 +0000131if [ "$QUIET" ] ; then
132 exec >/dev/null
133fi
134
Fred Drakee2e904f1998-03-10 23:23:05 +0000135for FILE in $@ ; do
136 FILE=${FILE%.tex}
137 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000138 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000139 fi
140 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000141 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000142 fi
143 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000144 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000145 fi
146 if [ "$BUILD_HTML" ] ; then
147 if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then
148 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000149 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000150 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000151 build_html $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000152 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000153 if [ "$DISCARD_TEMPS" ] ; then
154 rm -f $FILE.aux $FILE.log $FILE.out $FILE.toc $FILE.bkm 2>&1 \
155 | tee -a $LOGFILE
156 if [ ! "$BUILD_DVI" ] ; then
157 rm -f $FILE.dvi 2>&1 | tee -a $LOGFILE
158 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000159 fi
Fred Drakedbc879e1998-03-11 15:33:44 +0000160 # the the logfile around
161 if [ "$LOGGING" ] ; then
162 cp $LOGFILE $FILE.how
163 fi
164 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000165done