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 | |
Fred Drake | 12f842e | 1998-04-17 02:52:12 +0000 | [diff] [blame] | 84 | use_latex() { |
| 85 | # two args: <file> <latextype> |
| 86 | MYFILE=$1 |
| 87 | MYLATEX=$2 |
| 88 | # |
| 89 | # We really have to do it three times to get all the page numbers right, |
| 90 | # since the length of the ToC makes a real difference. |
| 91 | # |
| 92 | $MYDIR/newind.py >$MYFILE.ind |
| 93 | $MYDIR/newind.py modindex >mod$MYFILE.ind |
| 94 | $MYLATEX $MYFILE || exit $? |
| 95 | if [ -f mod$MYFILE.idx ] ; then |
| 96 | makeindex mod$MYFILE.idx |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 97 | fi |
Fred Drake | 12f842e | 1998-04-17 02:52:12 +0000 | [diff] [blame] | 98 | if [ -f $MYFILE.idx ] ; then |
| 99 | $MYDIR/fix_hack $MYFILE.idx |
| 100 | makeindex $MYFILE.idx |
| 101 | $MYDIR/indfix.py $MYFILE.ind |
| 102 | fi |
| 103 | $MYLATEX $MYFILE || exit $? |
| 104 | if [ -f mod$MYFILE.idx ] ; then |
| 105 | makeindex mod$MYFILE.idx |
| 106 | fi |
| 107 | if [ -f $MYFILE.idx ] ; then |
| 108 | $MYDIR/fix_hack $MYFILE.idx || exit $? |
| 109 | makeindex -s $TOPDIR/texinputs/myindex.ist $MYFILE.idx || exit $? |
| 110 | fi |
| 111 | if [ -f $MYFILE.toc ] ; then |
| 112 | $MYDIR/toc2bkm.py -c section $MYFILE |
| 113 | fi |
| 114 | $MYLATEX $MYFILE || exit $? |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Fred Drake | 12f842e | 1998-04-17 02:52:12 +0000 | [diff] [blame] | 117 | build_dvi() { |
| 118 | use_latex $1 latex |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | build_pdf() { |
Fred Drake | 12f842e | 1998-04-17 02:52:12 +0000 | [diff] [blame] | 122 | use_latex $1 pdflatex |
| 123 | } |
| 124 | |
| 125 | build_ps() { |
| 126 | dvips -N0 -o $1.ps -f $1 || exit $? |
| 127 | } |
| 128 | |
| 129 | cleanup() { |
| 130 | rm -f $1.aux $1.log $1.out $1.toc $1.bkm $1.idx $1.ind |
| 131 | if [ ! "$BUILD_DVI" ] ; then |
| 132 | rm -f $FILE.dvi |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 133 | fi |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | # figure out what our targets are: |
| 137 | while [ "$1" ] ; do |
| 138 | case "$1" in |
| 139 | --pdf|--pd) |
| 140 | BUILD_PDF=true |
| 141 | USE_DEFAULT_FORMAT=false |
| 142 | shift 1 |
| 143 | ;; |
| 144 | --ps) |
| 145 | BUILD_PS=true |
| 146 | USE_DEFAULT_FORMAT=false |
| 147 | shift 1 |
| 148 | ;; |
| 149 | --dvi|--dv|--d) |
| 150 | BUILD_DVI=true |
| 151 | USE_DEFAULT_FORMAT=false |
| 152 | shift 1 |
| 153 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame] | 154 | --html|--htm|--ht) |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 155 | BUILD_HTML=true |
| 156 | USE_DEFAULT_FORMAT=false |
| 157 | shift 1 |
| 158 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame] | 159 | -H|--help|--hel|--he) |
| 160 | usage 0 |
| 161 | ;; |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 162 | -a|--address|--addres|--addre|-addr|--add|--ad|--a) |
| 163 | ADDRESS="$2" |
| 164 | shift 2 |
| 165 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame] | 166 | -s|--split|--spli|--spl|--sp|--s) |
| 167 | HTML_SPLIT_LEVEL="$2" |
| 168 | shift 2 |
| 169 | ;; |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 170 | -l|--logging|--loggin|--loggi|--logg|--log|--lo|--l) |
| 171 | LOGGING=true |
| 172 | shift 1 |
| 173 | ;; |
| 174 | -D|--debugging|--debuggin|--debuggi|--debugg|--debug|--debu|--deb|--de) |
| 175 | DEBUGGING=true |
| 176 | shift 1 |
| 177 | ;; |
| 178 | -k|--keep|--kee|--ke|--k) |
| 179 | DISCARD_TEMPS='' |
| 180 | shift 1 |
| 181 | ;; |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame] | 182 | -q|--quiet|--quie|--qui|--qu|--q) |
Fred Drake | 664b36f | 1998-03-11 15:41:21 +0000 | [diff] [blame] | 183 | QUIET=true |
| 184 | shift 1 |
| 185 | ;; |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 186 | -*) |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame] | 187 | usage 2 |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 188 | ;; |
| 189 | *) |
| 190 | break;; |
| 191 | esac |
| 192 | done |
| 193 | |
| 194 | if [ $# = 0 ] ; then |
Fred Drake | ac8f91a | 1998-04-02 15:37:13 +0000 | [diff] [blame] | 195 | usage 2 |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 196 | fi |
| 197 | |
| 198 | if [ $USE_DEFAULT_FORMAT = true ] ; then |
| 199 | eval "BUILD_$DEFAULT_FORMAT=true" |
| 200 | fi |
| 201 | |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 202 | if [ "$DEBUGGING" ] ; then |
| 203 | set -x |
| 204 | fi |
| 205 | |
Fred Drake | 664b36f | 1998-03-11 15:41:21 +0000 | [diff] [blame] | 206 | if [ "$QUIET" ] ; then |
| 207 | exec >/dev/null |
| 208 | fi |
| 209 | |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 210 | for FILE in $@ ; do |
| 211 | FILE=${FILE%.tex} |
| 212 | if [ "$BUILD_DVI" -o "$BUILD_PS" ] ; then |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 213 | build_dvi $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 214 | fi |
| 215 | if [ "$BUILD_PDF" ] ; then |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 216 | build_pdf $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 217 | fi |
| 218 | if [ "$BUILD_PS" ] ; then |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 219 | build_ps $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 220 | fi |
| 221 | if [ "$BUILD_HTML" ] ; then |
| 222 | if [ ! "$BUILD_DVI" -o ! "$BUILD_PDF" ] ; then |
| 223 | # need to get aux file |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 224 | build_dvi $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 225 | fi |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 226 | build_html $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 227 | fi |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 228 | if [ "$DISCARD_TEMPS" ] ; then |
Fred Drake | 12f842e | 1998-04-17 02:52:12 +0000 | [diff] [blame] | 229 | cleanup $FILE 2>&1 | tee -a $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 230 | fi |
Fred Drake | 12f842e | 1998-04-17 02:52:12 +0000 | [diff] [blame] | 231 | # keep the logfile around |
Fred Drake | dbc879e | 1998-03-11 15:33:44 +0000 | [diff] [blame] | 232 | if [ "$LOGGING" ] ; then |
| 233 | cp $LOGFILE $FILE.how |
| 234 | fi |
| 235 | rm -f $LOGFILE |
Fred Drake | e2e904f | 1998-03-10 23:23:05 +0000 | [diff] [blame] | 236 | done |