blob: 69b9b4df55daeb9dc7b0132f869daf0cfd40c1ea [file] [log] [blame]
Fred Drake11300cc1998-08-05 04:48:18 +00001#! /usr/bin/env bash
Fred Drakee2e904f1998-03-10 23:23:05 +00002
Fred Drakec794c381998-08-12 17:50:07 +00003# This script may be invoked by naming it directly or via a shell alias,
4# but NOT through a symbolic link. Perhaps a future version will allow
5# the use of a symbolic link.
6#
7# Using a symbolic link will cause the script to not be able to locate
8# its support files.
9
Fred Drakee2e904f1998-03-10 23:23:05 +000010MYDIR=`dirname $0`
Fred Drakef558e311998-03-24 17:48:20 +000011WORKDIR=`pwd`
12cd $MYDIR
13MYDIR=`pwd`
Fred Drakeac8f91a1998-04-02 15:37:13 +000014cd ..
15TOPDIR=`pwd`
Fred Drakef558e311998-03-24 17:48:20 +000016cd $WORKDIR
Fred Drakee2e904f1998-03-10 23:23:05 +000017
18# DEFAULT_FORMAT must be upper case...
19DEFAULT_FORMAT=PDF
20USE_DEFAULT_FORMAT=true
Fred Drakedbc879e1998-03-11 15:33:44 +000021DISCARD_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +000022
Fred Drake11300cc1998-08-05 04:48:18 +000023ICONSERVER=''
24
Fred Drakeac8f91a1998-04-02 15:37:13 +000025L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl
Fred Drake11300cc1998-08-05 04:48:18 +000026L2H_AUX_INIT_FILE=/usr/tmp/mkhowto-$LOGNAME-$$.perl
Fred Drakeac8f91a1998-04-02 15:37:13 +000027
Fred Drakedbc879e1998-03-11 15:33:44 +000028LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how
29LOGGING=''
30
Fred Drakee2e904f1998-03-10 23:23:05 +000031usage() {
Fred Drakeac8f91a1998-04-02 15:37:13 +000032 MYNAME=`basename $0`
33 echo "usage: $MYNAME [options...] file ..."
34 cat <<EOF
35
36Options specifying formats to build:
37 --html HyperText Markup Language
38 --pdf Portable Document Format (default)
39 --ps PostScript
40 --dvi "DeVice Indepentent" format from TeX
Fred Drake78b8c3d1998-08-12 17:52:16 +000041 --text ASCII text
Fred Drakeac8f91a1998-04-02 15:37:13 +000042
Fred Drake9f6f0da1998-08-12 18:07:51 +000043 More than one output format may be specified, or --all.
Fred Drakeac8f91a1998-04-02 15:37:13 +000044
45HTML options:
46 --address, -a Specify an address for page footers.
Fred Drake88053541998-04-24 21:57:12 +000047 --link Specify the number of levels to include on each page.
Fred Drakeac8f91a1998-04-02 15:37:13 +000048 --split, -s Specify a section level for page splitting.
Fred Drake11300cc1998-08-05 04:48:18 +000049 --iconserver, -i Specify location of icons (default: ../).
Fred Drakeac8f91a1998-04-02 15:37:13 +000050
51Other options:
Fred Drake1a3541c1998-05-11 19:04:56 +000052 --a4 Format for A4 paper.
Fred Draked5d473f1998-05-11 20:40:24 +000053 --letter Format for US letter paper (the default).
Fred Drakeac8f91a1998-04-02 15:37:13 +000054 --help, -H Show this text.
55 --logging, -l Log stdout and stderr to a file (*.how).
56 --debugging, -D Echo commands as they are executed.
57 --keep, -k Keep temporary files around.
58 --quiet, -q Do not print command output to stdout.
59 (stderr is also lost, sorry; see *.how for errors)
60
61EOF
Fred Drake9f6f0da1998-08-12 18:07:51 +000062 if [ "$2" ] ; then
63 echo "$2"
64 echo
65 fi
Fred Drake11300cc1998-08-05 04:48:18 +000066
Fred Drakeac8f91a1998-04-02 15:37:13 +000067 exit $1
Fred Drakee2e904f1998-03-10 23:23:05 +000068}
69
Fred Drake88053541998-04-24 21:57:12 +000070# These are LaTeX2HTML controls; they reflect l2h variables of the same name.
71# The values here are the defaults after modification by perl/l2hinit.perl.
72#
73ADDRESS=''
74MAX_LINK_DEPTH=3
75MAX_SPLIT_DEPTH=8
76
Fred Drakee2e904f1998-03-10 23:23:05 +000077build_html() {
Fred Drake19c7c841998-05-07 21:20:39 +000078 TEXFILE=`kpsewhich $1.tex`
Fred Drake9940bd71998-08-06 20:15:20 +000079 BUILDDIR=${2:-$1}
Fred Drake11300cc1998-08-05 04:48:18 +000080 latex2html \
81 -init_file $L2H_INIT_FILE \
82 -init_file $L2H_AUX_INIT_FILE \
Fred Drake9940bd71998-08-06 20:15:20 +000083 -dir $BUILDDIR $TEXFILE || exit $?
Fred Drake88053541998-04-24 21:57:12 +000084 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +000085 (cd $BUILDDIR; $MYDIR/node2label.pl *.html) || exit $?
Fred Drakeac8f91a1998-04-02 15:37:13 +000086 fi
Fred Drakee2e904f1998-03-10 23:23:05 +000087}
88
Fred Drake12f842e1998-04-17 02:52:12 +000089use_latex() {
90 # two args: <file> <latextype>
91 MYFILE=$1
92 MYLATEX=$2
93 #
94 # We really have to do it three times to get all the page numbers right,
95 # since the length of the ToC makes a real difference.
96 #
97 $MYDIR/newind.py >$MYFILE.ind
98 $MYDIR/newind.py modindex >mod$MYFILE.ind
99 $MYLATEX $MYFILE || exit $?
100 if [ -f mod$MYFILE.idx ] ; then
101 makeindex mod$MYFILE.idx
Fred Drakee2e904f1998-03-10 23:23:05 +0000102 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000103 if [ -f $MYFILE.idx ] ; then
104 $MYDIR/fix_hack $MYFILE.idx
105 makeindex $MYFILE.idx
106 $MYDIR/indfix.py $MYFILE.ind
107 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000108 if [ -f $MYFILE.syn ] ; then
109 # This hack is due to a bug with the module synopsis support that
110 # causes the last module synopsis to be written out twice in
111 # howto documents (not present for manuals). Repeated below.
112 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
113 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000114 $MYLATEX $MYFILE || exit $?
115 if [ -f mod$MYFILE.idx ] ; then
116 makeindex mod$MYFILE.idx
117 fi
118 if [ -f $MYFILE.idx ] ; then
119 $MYDIR/fix_hack $MYFILE.idx || exit $?
120 makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $?
121 fi
Fred Drakef4fc4761998-05-14 20:03:14 +0000122 if [ -f $MYFILE.toc -a $MYLATEX = pdflatex ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000123 $MYDIR/toc2bkm.py -c section $MYFILE
124 fi
Fred Drake8cab5491998-07-23 19:13:52 +0000125 if [ -f $MYFILE.syn ] ; then
126 uniq $MYFILE.syn >TEMP.syn && mv TEMP.syn $MYFILE.syn || exit $?
127 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000128 $MYLATEX $MYFILE || exit $?
Fred Drakee2e904f1998-03-10 23:23:05 +0000129}
130
Fred Drake12f842e1998-04-17 02:52:12 +0000131build_dvi() {
132 use_latex $1 latex
Fred Drakee2e904f1998-03-10 23:23:05 +0000133}
134
135build_pdf() {
Fred Drake12f842e1998-04-17 02:52:12 +0000136 use_latex $1 pdflatex
137}
138
139build_ps() {
Fred Drake79842561998-04-17 20:06:16 +0000140 dvips -N0 -o $1.ps $1 || exit $?
Fred Drake12f842e1998-04-17 02:52:12 +0000141}
142
Fred Drake9940bd71998-08-06 20:15:20 +0000143build_text() {
144 lynx -nolist -dump $2/index.html >$1.txt
145}
146
Fred Drake11300cc1998-08-05 04:48:18 +0000147l2hoption() {
148 if [ "$2" ] ; then
149 echo "\$$1 = \"$2\";" >>$L2H_AUX_INIT_FILE
150 fi
151}
152
Fred Drake12f842e1998-04-17 02:52:12 +0000153cleanup() {
Fred Drake8cab5491998-07-23 19:13:52 +0000154 rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ilg $1.ind $1.syn
Fred Drakec9b8a571998-04-29 21:28:25 +0000155 rm -f mod$1.idx mod$1.ilg mod$1.ind
Fred Drake12f842e1998-04-17 02:52:12 +0000156 if [ ! "$BUILD_DVI" ] ; then
Fred Drake19c7c841998-05-07 21:20:39 +0000157 rm -f $1.dvi
Fred Drakee2e904f1998-03-10 23:23:05 +0000158 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000159 rm -rf $1.temp-html
Fred Drake8dbf46a1998-05-15 17:13:08 +0000160 rm -f $1/IMG* $1/*.pl $1/WARNINGS $1/index.dat $1/modindex.dat
Fred Drakee2e904f1998-03-10 23:23:05 +0000161}
162
163# figure out what our targets are:
164while [ "$1" ] ; do
165 case "$1" in
Fred Drake9f6f0da1998-08-12 18:07:51 +0000166 --all|--al)
167 BUILD_PDF=true
168 BUILD_PS=true
169 BUILD_DVI=true
170 BUILD_HTML=true
171 BUILD_TEXT=true
172 USE_DEFAULT_FORMAT=false
173 shift 1
174 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000175 --pdf|--pd)
176 BUILD_PDF=true
177 USE_DEFAULT_FORMAT=false
178 shift 1
179 ;;
Fred Drake88053541998-04-24 21:57:12 +0000180 --ps|--postscript|--postscrip|--postscri|--postscr|--postsc|--posts|--post|--pos|--po)
Fred Drakee2e904f1998-03-10 23:23:05 +0000181 BUILD_PS=true
182 USE_DEFAULT_FORMAT=false
183 shift 1
184 ;;
185 --dvi|--dv|--d)
186 BUILD_DVI=true
187 USE_DEFAULT_FORMAT=false
188 shift 1
189 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000190 --html|--htm|--ht)
Fred Drakee2e904f1998-03-10 23:23:05 +0000191 BUILD_HTML=true
192 USE_DEFAULT_FORMAT=false
193 shift 1
194 ;;
Fred Drake9940bd71998-08-06 20:15:20 +0000195 --text|--tex|--te|--t)
196 BUILD_TEXT=true
197 USE_DEFAULT_FORMAT=false
198 shift 1
199 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000200 -H|--help|--hel|--he)
201 usage 0
202 ;;
Fred Drake11300cc1998-08-05 04:48:18 +0000203 -i|--iconserver|--iconserve|--iconserv|--iconser|--iconse|--icons|--icon|--ico|--ic|--i)
204 ICONSERVER="$2"
205 shift 2
206 ;;
Fred Drake35049521998-05-11 19:04:06 +0000207 -a|--address|--addres|--addre|-addr|--add|--ad)
Fred Drakee2e904f1998-03-10 23:23:05 +0000208 ADDRESS="$2"
209 shift 2
210 ;;
Fred Drake35049521998-05-11 19:04:06 +0000211 --a4)
212 TEXINPUTS=$TOPDIR/paper-a4:$TEXINPUTS
213 shift 1
214 ;;
Fred Draked5d473f1998-05-11 20:40:24 +0000215 --letter|--lette|--lett|--let|--le)
216 shift 1
217 ;;
Fred Drake88053541998-04-24 21:57:12 +0000218 --link|--lin|--li)
219 LINK="$2"
Fred Drakeac8f91a1998-04-02 15:37:13 +0000220 shift 2
221 ;;
Fred Drake88053541998-04-24 21:57:12 +0000222 -s|--split|--spli|--spl|--sp|--s)
223 MAX_SPLIT_DEPTH="$2"
224 shift 2
225 ;;
226 -l|--logging|--loggin|--loggi|--logg|--log|--lo)
Fred Drakedbc879e1998-03-11 15:33:44 +0000227 LOGGING=true
228 shift 1
229 ;;
230 -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de)
231 DEBUGGING=true
232 shift 1
233 ;;
234 -k|--keep|--kee|--ke|--k)
235 DISCARD_TEMPS=''
236 shift 1
237 ;;
Fred Drakeac8f91a1998-04-02 15:37:13 +0000238 -q|--quiet|--quie|--qui|--qu|--q)
Fred Drake664b36f1998-03-11 15:41:21 +0000239 QUIET=true
240 shift 1
241 ;;
Fred Drake88053541998-04-24 21:57:12 +0000242 --)
Fred Drakec9b8a571998-04-29 21:28:25 +0000243 shift 1
Fred Drake88053541998-04-24 21:57:12 +0000244 break
245 ;;
Fred Drakee2e904f1998-03-10 23:23:05 +0000246 -*)
Fred Drakeac8f91a1998-04-02 15:37:13 +0000247 usage 2
Fred Drakee2e904f1998-03-10 23:23:05 +0000248 ;;
249 *)
250 break;;
251 esac
252done
253
254if [ $# = 0 ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000255 # check for a single .tex file in .
256 COUNT=`ls -1 *.tex | wc -l | sed 's/[ ]//g'`
257 if [ "$COUNT" -eq 1 ] ; then
258 set -- `ls -1 *.tex`
Fred Drake9f6f0da1998-08-12 18:07:51 +0000259 elif [ "$COUNT" -gt 1 ] ; then
260 usage 2 "Could not deduce which file(s) to process as HOWTO documents."
Fred Drake9940bd71998-08-06 20:15:20 +0000261 else
Fred Drake9f6f0da1998-08-12 18:07:51 +0000262 usage 2 "No file to process."
Fred Drake9940bd71998-08-06 20:15:20 +0000263 fi
Fred Drakee2e904f1998-03-10 23:23:05 +0000264fi
265
266if [ $USE_DEFAULT_FORMAT = true ] ; then
267 eval "BUILD_$DEFAULT_FORMAT=true"
268fi
269
Fred Drake664b36f1998-03-11 15:41:21 +0000270if [ "$QUIET" ] ; then
271 exec >/dev/null
272fi
273
Fred Drake9940bd71998-08-06 20:15:20 +0000274if [ "$DEBUGGING" ] ; then
275 set -x
276fi
277
Fred Drake11300cc1998-08-05 04:48:18 +0000278echo '# auxillary init file for latex2html' >$L2H_AUX_INIT_FILE
279echo '# generated by mkhowto.sh -- do no edit' >>$L2H_AUX_INIT_FILE
280l2hoption ICONSERVER "$ICONSERVER"
281l2hoption ADDRESS "$ADDRESS"
282l2hoption MAX_LINK_DEPTH "$MAX_LINK_DEPTH"
283l2hoption MAX_SPLIT_DEPTH "$MAX_SPLIT_DEPTH"
284echo '1;' >>$L2H_AUX_INIT_FILE
Fred Drakef4fc4761998-05-14 20:03:14 +0000285
Fred Drakee2e904f1998-03-10 23:23:05 +0000286for FILE in $@ ; do
Fred Drakedf825a11998-05-14 20:36:49 +0000287 FILEDIR=`dirname $FILE`
Fred Drake19c7c841998-05-07 21:20:39 +0000288 FILE=`basename ${FILE%.tex}`
Fred Drakef4fc4761998-05-14 20:03:14 +0000289 #
290 # Put the directory the .tex file is in is also the first directory in
291 # TEXINPUTS, to allow files there to override files in the common area.
292 #
Fred Drake11300cc1998-08-05 04:48:18 +0000293 TEXINPUTS=$FILEDIR:$TOPDIR/texinputs:$TEXINPUTS
Fred Drakef4fc4761998-05-14 20:03:14 +0000294 export TEXINPUTS
295 #
Fred Drakee2e904f1998-03-10 23:23:05 +0000296 if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000297 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000298 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000299 fi
300 if [ "$BUILD_PDF" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000301 build_pdf $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000302 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000303 fi
304 if [ "$BUILD_PS" ] ; then
Fred Drakedbc879e1998-03-11 15:33:44 +0000305 build_ps $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000306 fi
307 if [ "$BUILD_HTML" ] ; then
Fred Drake9940bd71998-08-06 20:15:20 +0000308 if [ ! "$HAVE_TEMPS" ] ; then
Fred Drakee2e904f1998-03-10 23:23:05 +0000309 # need to get aux file
Fred Drakedbc879e1998-03-11 15:33:44 +0000310 build_dvi $FILE 2>&1 | tee -a $LOGFILE
Fred Drake9940bd71998-08-06 20:15:20 +0000311 HAVE_TEMPS=true
Fred Drakee2e904f1998-03-10 23:23:05 +0000312 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000313 build_html $FILE $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000314 fi
Fred Drake9940bd71998-08-06 20:15:20 +0000315 if [ "$BUILD_TEXT" ] ; then
316 if [ ! "$HAVE_TEMPS" ] ; then
317 # need to get aux file
318 build_dvi $FILE 2>&1 | tee -a $LOGFILE
319 HAVE_TEMPS=true
320 fi
321 # this is why building text really has to be last:
322 if [ "$MAX_SPLIT_DEPTH" -ne 1 ] ; then
323 echo '# re-hack this file for --text:' >>$L2H_AUX_INIT_FILE
324 l2hoption MAX_SPLIT_DEPTH 1
325 echo '1;' >>$L2H_AUX_INIT_FILE
326 TEMPDIR=$FILE.temp-html
327 build_html $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
328 else
329 TEMPDIR=$FILE
330 fi
331 build_text $FILE $TEMPDIR 2>&1 | tee -a $LOGFILE
332 fi
333
Fred Drakedbc879e1998-03-11 15:33:44 +0000334 if [ "$DISCARD_TEMPS" ] ; then
Fred Drake12f842e1998-04-17 02:52:12 +0000335 cleanup $FILE 2>&1 | tee -a $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000336 fi
Fred Drake12f842e1998-04-17 02:52:12 +0000337 # keep the logfile around
Fred Drakedbc879e1998-03-11 15:33:44 +0000338 if [ "$LOGGING" ] ; then
339 cp $LOGFILE $FILE.how
340 fi
341 rm -f $LOGFILE
Fred Drakee2e904f1998-03-10 23:23:05 +0000342done
Fred Drake11300cc1998-08-05 04:48:18 +0000343
344rm -f $L2H_AUX_INIT_FILE