Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 1 | #! /depot/gnu/plat/bin/bash |
| 2 | |
| 3 | MYDIR=`dirname $0` |
Fred Drake | f558e31 | 1998-03-24 17:48:20 +0000 | [diff] [blame] | 4 | WORKDIR=`pwd` |
| 5 | cd $MYDIR |
| 6 | MYDIR=`pwd` |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 7 | cd .. |
| 8 | TOPDIR=`pwd` |
Fred Drake | f558e31 | 1998-03-24 17:48:20 +0000 | [diff] [blame] | 9 | cd $WORKDIR |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 10 | |
| 11 | # DEFAULT_FORMAT must be upper case... |
| 12 | DEFAULT_FORMAT=PDF |
| 13 | USE_DEFAULT_FORMAT=true |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 14 | DISCARD_TEMPS=true |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 15 | |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 16 | HTML_SPLIT_LEVEL='' |
| 17 | L2H_INIT_FILE=$TOPDIR/perl/l2hinit.perl |
| 18 | |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 19 | # This is needed to support kpathsea based TeX installations. Others are |
| 20 | # not supported. ;-) |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 21 | TEXINPUTS=`dirname $MYDIR`/texinputs:$TEXINPUTS |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 22 | export TEXINPUTS |
| 23 | |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 24 | LOGFILE=/usr/tmp/mkhowto-$LOGNAME-$$.how |
| 25 | LOGGING='' |
| 26 | |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 27 | usage() { |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 28 | MYNAME=`basename $0` |
| 29 | echo "usage: $MYNAME [options...] file ..." |
| 30 | cat <<EOF |
| 31 | |
| 32 | Options 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 | |
| 40 | HTML options: |
| 41 | --address, -a Specify an address for page footers. |
| 42 | --split, -s Specify a section level for page splitting. |
| 43 | |
| 44 | Other 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 | |
| 52 | EOF |
| 53 | |
| 54 | exit $1 |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | build_html() { |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 58 | 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 Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 69 | else |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 70 | 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 Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 78 | fi |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 79 | if [ "$HTML_SPLIT_LEVEL" != 1 ] ; then |
| 80 | (cd $FILE; $MYDIR/node2label.pl *.html) || exit $? |
| 81 | fi |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | build_dvi() { |
| 85 | latex $1 || exit $? |
Fred Drake | 1125488 | 1998-03-18 22:06:13 +0000 | [diff] [blame] | 86 | latex $1 || exit $? |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 87 | if [ -f $1.idx ] ; then |
| 88 | `dirname $0`/fix_hack $1.idx || exit $? |
| 89 | makeindex $1.idx || exit $? |
| 90 | fi |
| 91 | latex $1 || exit $? |
| 92 | } |
| 93 | |
| 94 | build_ps() { |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 95 | # note weird sequence of redirects is used to get stderr to the old stdout |
| 96 | # and the new stdout goes to a file |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 97 | dvips -N0 -f $1 >$1.ps || exit $? |
| 98 | } |
| 99 | |
| 100 | build_pdf() { |
| 101 | # We really have to do it three times to get all the page numbers right, |
| 102 | # since the length of the ToC makes a real difference. |
| 103 | pdflatex $1 || exit $? |
| 104 | pdflatex $1 || exit $? |
| 105 | `dirname $0`/toc2bkm.py -c section $FILE || exit $? |
| 106 | if [ -f $1.idx ] ; then |
| 107 | `dirname $0`/fix_hack $1.idx || exit $? |
| 108 | makeindex $1.idx || exit $? |
| 109 | fi |
| 110 | pdflatex $1 || exit $? |
| 111 | } |
| 112 | |
| 113 | # figure out what our targets are: |
| 114 | while [ "$1" ] ; do |
| 115 | case "$1" in |
| 116 | --pdf|--pd) |
| 117 | BUILD_PDF=true |
| 118 | USE_DEFAULT_FORMAT=false |
| 119 | shift 1 |
| 120 | ;; |
| 121 | --ps) |
| 122 | BUILD_PS=true |
| 123 | USE_DEFAULT_FORMAT=false |
| 124 | shift 1 |
| 125 | ;; |
| 126 | --dvi|--dv|--d) |
| 127 | BUILD_DVI=true |
| 128 | USE_DEFAULT_FORMAT=false |
| 129 | shift 1 |
| 130 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 131 | --html|--htm|--ht) |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 132 | BUILD_HTML=true |
| 133 | USE_DEFAULT_FORMAT=false |
| 134 | shift 1 |
| 135 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 136 | -H|--help|--hel|--he) |
| 137 | usage 0 |
| 138 | ;; |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 139 | -a|--address|--addres|--addre|-addr|--add|--ad|--a) |
| 140 | ADDRESS="$2" |
| 141 | shift 2 |
| 142 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 143 | -s|--split|--spli|--spl|--sp|--s) |
| 144 | HTML_SPLIT_LEVEL="$2" |
| 145 | shift 2 |
| 146 | ;; |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 147 | -l|--logging|--loggin|--loggi|--logg|--log|--lo|--l) |
| 148 | LOGGING=true |
| 149 | shift 1 |
| 150 | ;; |
| 151 | -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de) |
| 152 | DEBUGGING=true |
| 153 | shift 1 |
| 154 | ;; |
| 155 | -k|--keep|--kee|--ke|--k) |
| 156 | DISCARD_TEMPS='' |
| 157 | shift 1 |
| 158 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 159 | -q|--quiet|--quie|--qui|--qu|--q) |
Fred Drake | 664b36f | 1998-03-11 15:41:21 +0000 | [diff] [blame] | 160 | QUIET=true |
| 161 | shift 1 |
| 162 | ;; |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 163 | -*) |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 164 | usage 2 |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 165 | ;; |
| 166 | *) |
| 167 | break;; |
| 168 | esac |
| 169 | done |
| 170 | |
| 171 | if [ $# = 0 ] ; then |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame^] | 172 | usage 2 |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 173 | fi |
| 174 | |
| 175 | if [ $USE_DEFAULT_FORMAT = true ] ; then |
| 176 | eval "BUILD_$DEFAULT_FORMAT=true" |
| 177 | fi |
| 178 | |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 179 | if [ "$DEBUGGING" ] ; then |
| 180 | set -x |
| 181 | fi |
| 182 | |
Fred Drake | 664b36f | 1998-03-11 15:41:21 +0000 | [diff] [blame] | 183 | if [ "$QUIET" ] ; then |
| 184 | exec >/dev/null |
| 185 | fi |
| 186 | |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 187 | for FILE in $@ ; do |
| 188 | FILE=${FILE%.tex} |
| 189 | if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 190 | build_dvi $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 191 | fi |
| 192 | if [ "$BUILD_PDF" ] ; then |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 193 | build_pdf $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 194 | fi |
| 195 | if [ "$BUILD_PS" ] ; then |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 196 | build_ps $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 197 | fi |
| 198 | if [ "$BUILD_HTML" ] ; then |
| 199 | if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then |
| 200 | # need to get aux file |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 201 | build_dvi $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 202 | fi |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 203 | build_html $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 204 | fi |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 205 | if [ "$DISCARD_TEMPS" ] ; then |
| 206 | rm -f $FILE.aux $FILE.log $FILE.out $FILE.toc $FILE.bkm 2>&1 \ |
| 207 | | tee -a $LOGFILE |
| 208 | if [ ! "$BUILD_DVI" ] ; then |
| 209 | rm -f $FILE.dvi 2>&1 | tee -a $LOGFILE |
| 210 | fi |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 211 | fi |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 212 | # the the logfile around |
| 213 | if [ "$LOGGING" ] ; then |
| 214 | cp $LOGFILE $FILE.how |
| 215 | fi |
| 216 | rm -f $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 217 | done |