gendocs.sh (13615B)
1 #!/bin/sh -e 2 # gendocs.sh -- generate a GNU manual in many formats. This script is 3 # mentioned in maintain.texi. See the help message below for usage details. 4 5 scriptversion=2012-09-02.17 6 7 # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 8 # Free Software Foundation, Inc. 9 # 10 # This program is free software: you can redistribute it and/or modify 11 # it under the terms of the GNU General Public License as published by 12 # the Free Software Foundation; either version 3 of the License, or 13 # (at your option) any later version. 14 # 15 # This program is distributed in the hope that it will be useful, 16 # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 # GNU General Public License for more details. 19 # 20 # You should have received a copy of the GNU General Public License 21 # along with this program. If not, see <http://www.gnu.org/licenses/>. 22 # 23 # Original author: Mohit Agarwal. 24 # Send bug reports and any other correspondence to bug-texinfo@gnu.org. 25 # 26 # The latest version of this script, and the companion template, is 27 # available from Texinfo CVS: 28 # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs.sh 29 # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template 30 # 31 # An up-to-date copy is also maintained in Gnulib (gnu.org/software/gnulib). 32 33 prog=`basename "$0"` 34 srcdir=`pwd` 35 36 scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh" 37 templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template" 38 39 : ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="} 40 : ${MAKEINFO="makeinfo"} 41 : ${TEXI2DVI="texi2dvi -t @finalout"} 42 : ${DVIPS="dvips"} 43 : ${DOCBOOK2HTML="docbook2html"} 44 : ${DOCBOOK2PDF="docbook2pdf"} 45 : ${DOCBOOK2PS="docbook2ps"} 46 : ${DOCBOOK2TXT="docbook2txt"} 47 : ${GENDOCS_TEMPLATE_DIR="."} 48 : ${TEXI2HTML="texi2html"} 49 unset CDPATH 50 unset use_texi2html 51 52 version="gendocs.sh $scriptversion 53 54 Copyright 2012 Free Software Foundation, Inc. 55 There is NO warranty. You may redistribute this software 56 under the terms of the GNU General Public License. 57 For more information about these matters, see the files named COPYING." 58 59 usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE 60 61 Generate output in various formats from PACKAGE.texinfo (or .texi or 62 .txi) source. See the GNU Maintainers document for a more extensive 63 discussion: 64 http://www.gnu.org/prep/maintain_toc.html 65 66 Options: 67 -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi} 68 -o OUTDIR write files into OUTDIR, instead of manual/. 69 --email ADR use ADR as contact in generated web pages. 70 --docbook convert to DocBook too (xml, txt, html, pdf and ps). 71 --html ARG pass indicated ARG to makeinfo or texi2html for HTML targets. 72 --info ARG pass indicated ARG to makeinfo for Info, instead of --no-split. 73 --texi2html use texi2html to generate HTML targets. 74 --help display this help and exit successfully. 75 --version display version information and exit successfully. 76 77 Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\" 78 79 Typical sequence: 80 cd PACKAGESOURCE/doc 81 wget \"$scripturl\" 82 wget \"$templateurl\" 83 $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\" 84 85 Output will be in a new subdirectory \"manual\" (by default; 86 use -o OUTDIR to override). Move all the new files into your web CVS 87 tree, as explained in the Web Pages node of maintain.texi. 88 89 Please do use the --email ADDRESS option to specify your bug-reporting 90 address in the generated HTML pages. 91 92 MANUAL-TITLE is included as part of the HTML <title> of the overall 93 manual/index.html file. It should include the name of the package being 94 documented. manual/index.html is created by substitution from the file 95 $GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the 96 generic template for your own purposes.) 97 98 If you have several manuals, you'll need to run this script several 99 times with different MANUAL values, specifying a different output 100 directory with -o each time. Then write (by hand) an overall index.html 101 with links to them all. 102 103 If a manual's Texinfo sources are spread across several directories, 104 first copy or symlink all Texinfo sources into a single directory. 105 (Part of the script's work is to make a tar.gz of the sources.) 106 107 As implied above, by default monolithic Info files are generated. 108 If you want split Info, or other Info options, use --info to override. 109 110 You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML, and 111 DVIPS to control the programs that get executed, and 112 GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is 113 looked for. With --docbook, the environment variables DOCBOOK2HTML, 114 DOCBOOK2PDF, DOCBOOK2PS, and DOCBOOK2TXT are also respected. 115 116 By default, makeinfo and texi2dvi are run in the default (English) 117 locale, since that's the language of most Texinfo manuals. If you 118 happen to have a non-English manual and non-English web site, see the 119 SETLANG setting in the source. 120 121 Email bug reports or enhancement requests to bug-texinfo@gnu.org. 122 " 123 124 calcsize() 125 { 126 size=`ls -ksl $1 | awk '{print $1}'` 127 echo $size 128 } 129 130 MANUAL_TITLE= 131 PACKAGE= 132 EMAIL=webmasters@gnu.org # please override with --email 133 htmlarg= 134 infoarg=--no-split 135 outdir=manual 136 srcfile= 137 138 while test $# -gt 0; do 139 case $1 in 140 --email) shift; EMAIL=$1;; 141 --help) echo "$usage"; exit 0;; 142 --version) echo "$version"; exit 0;; 143 -s) shift; srcfile=$1;; 144 -o) shift; outdir=$1;; 145 --docbook) docbook=yes;; 146 --html) shift; htmlarg=$1;; 147 --info) shift; infoarg=$1;; 148 --texi2html) use_texi2html=1;; 149 -*) 150 echo "$0: Unknown option \`$1'." >&2 151 echo "$0: Try \`--help' for more information." >&2 152 exit 1;; 153 *) 154 if test -z "$PACKAGE"; then 155 PACKAGE=$1 156 elif test -z "$MANUAL_TITLE"; then 157 MANUAL_TITLE=$1 158 else 159 echo "$0: extra non-option argument \`$1'." >&2 160 exit 1 161 fi;; 162 esac 163 shift 164 done 165 166 # For most of the following, the base name is just $PACKAGE 167 base=$PACKAGE 168 169 if test -n "$srcfile"; then 170 # but here, we use the basename of $srcfile 171 base=`basename "$srcfile"` 172 case $base in 173 *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;; 174 esac 175 PACKAGE=$base 176 elif test -s "$srcdir/$PACKAGE.texinfo"; then 177 srcfile=$srcdir/$PACKAGE.texinfo 178 elif test -s "$srcdir/$PACKAGE.texi"; then 179 srcfile=$srcdir/$PACKAGE.texi 180 elif test -s "$srcdir/$PACKAGE.txi"; then 181 srcfile=$srcdir/$PACKAGE.txi 182 else 183 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2 184 exit 1 185 fi 186 187 if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then 188 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2 189 echo "$0: it is available from $templateurl." >&2 190 exit 1 191 fi 192 193 case $outdir in 194 /*) abs_outdir=$outdir;; 195 *) abs_outdir=$srcdir/$outdir;; 196 esac 197 198 echo "Generating output formats for $srcfile" 199 200 cmd="$SETLANG $MAKEINFO -o $PACKAGE.info $infoarg \"$srcfile\"" 201 echo "Generating info file(s)... ($cmd)" 202 eval "$cmd" 203 mkdir -p "$outdir/" 204 tar czf "$outdir/$PACKAGE.info.tar.gz" $PACKAGE.info* 205 info_tgz_size=`calcsize "$outdir/$PACKAGE.info.tar.gz"` 206 # do not mv the info files, there's no point in having them available 207 # separately on the web. 208 209 cmd="$SETLANG ${TEXI2DVI} \"$srcfile\"" 210 echo "Generating dvi ... ($cmd)" 211 eval "$cmd" 212 213 # now, before we compress dvi: 214 echo "Generating postscript..." 215 ${DVIPS} $PACKAGE -o 216 gzip -f -9 $PACKAGE.ps 217 ps_gz_size=`calcsize $PACKAGE.ps.gz` 218 mv $PACKAGE.ps.gz "$outdir/" 219 220 # compress/finish dvi: 221 gzip -f -9 $PACKAGE.dvi 222 dvi_gz_size=`calcsize $PACKAGE.dvi.gz` 223 mv $PACKAGE.dvi.gz "$outdir/" 224 225 cmd="$SETLANG ${TEXI2DVI} --pdf \"$srcfile\"" 226 echo "Generating pdf ... ($cmd)" 227 eval "$cmd" 228 pdf_size=`calcsize $PACKAGE.pdf` 229 mv $PACKAGE.pdf "$outdir/" 230 231 cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\"" 232 echo "Generating ASCII... ($cmd)" 233 eval "$cmd" 234 ascii_size=`calcsize $PACKAGE.txt` 235 gzip -f -9 -c $PACKAGE.txt >"$outdir/$PACKAGE.txt.gz" 236 ascii_gz_size=`calcsize "$outdir/$PACKAGE.txt.gz"` 237 mv $PACKAGE.txt "$outdir/" 238 239 html_split() 240 { 241 opt="--split=$1 $htmlarg --node-files" 242 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\"" 243 echo "Generating html by $1... ($cmd)" 244 eval "$cmd" 245 split_html_dir=$PACKAGE.html 246 ( 247 cd ${split_html_dir} || exit 1 248 ln -sf ${PACKAGE}.html index.html 249 tar -czf "$abs_outdir/${PACKAGE}.html_$1.tar.gz" -- *.html 250 ) 251 eval html_$1_tgz_size=`calcsize "$outdir/${PACKAGE}.html_$1.tar.gz"` 252 rm -f "$outdir"/html_$1/*.html 253 mkdir -p "$outdir/html_$1/" 254 mv ${split_html_dir}/*.html "$outdir/html_$1/" 255 rmdir ${split_html_dir} 256 } 257 258 if test -z "$use_texi2html"; then 259 opt="--no-split --html -o $PACKAGE.html $htmlarg" 260 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\"" 261 echo "Generating monolithic html... ($cmd)" 262 rm -rf $PACKAGE.html # in case a directory is left over 263 eval "$cmd" 264 html_mono_size=`calcsize $PACKAGE.html` 265 gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz" 266 html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"` 267 mv $PACKAGE.html "$outdir/" 268 269 cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $htmlarg \"$srcfile\"" 270 echo "Generating html by node... ($cmd)" 271 eval "$cmd" 272 split_html_dir=$PACKAGE.html 273 ( 274 cd ${split_html_dir} || exit 1 275 tar -czf "$abs_outdir/${PACKAGE}.html_node.tar.gz" -- *.html 276 ) 277 html_node_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node.tar.gz"` 278 rm -f "$outdir"/html_node/*.html 279 mkdir -p "$outdir/html_node/" 280 mv ${split_html_dir}/*.html "$outdir/html_node/" 281 rmdir ${split_html_dir} 282 else 283 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $htmlarg \"$srcfile\"" 284 echo "Generating monolithic html... ($cmd)" 285 rm -rf $PACKAGE.html # in case a directory is left over 286 eval "$cmd" 287 html_mono_size=`calcsize $PACKAGE.html` 288 gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz" 289 html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"` 290 mv $PACKAGE.html "$outdir/" 291 292 html_split node 293 html_split chapter 294 html_split section 295 fi 296 297 echo Making .tar.gz for sources... 298 d=`dirname $srcfile` 299 ( 300 cd "$d" 301 srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null` || true 302 tar cvzfh "$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles 303 ) 304 texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"` 305 306 if test -n "$docbook"; then 307 cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml" 308 echo "Generating docbook XML... ($cmd)" 309 eval "$cmd" 310 docbook_xml_size=`calcsize $PACKAGE-db.xml` 311 gzip -f -9 -c $PACKAGE-db.xml >"$outdir/$PACKAGE-db.xml.gz" 312 docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"` 313 mv $PACKAGE-db.xml "$outdir/" 314 315 split_html_db_dir=html_node_db 316 cmd="${DOCBOOK2HTML} -o $split_html_db_dir \"${outdir}/$PACKAGE-db.xml\"" 317 echo "Generating docbook HTML... ($cmd)" 318 eval "$cmd" 319 ( 320 cd ${split_html_db_dir} || exit 1 321 tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html 322 ) 323 html_node_db_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node_db.tar.gz"` 324 rm -f "$outdir"/html_node_db/*.html 325 mkdir -p "$outdir/html_node_db" 326 mv ${split_html_db_dir}/*.html "$outdir/html_node_db/" 327 rmdir ${split_html_db_dir} 328 329 cmd="${DOCBOOK2TXT} \"${outdir}/$PACKAGE-db.xml\"" 330 echo "Generating docbook ASCII... ($cmd)" 331 eval "$cmd" 332 docbook_ascii_size=`calcsize $PACKAGE-db.txt` 333 mv $PACKAGE-db.txt "$outdir/" 334 335 cmd="${DOCBOOK2PS} \"${outdir}/$PACKAGE-db.xml\"" 336 echo "Generating docbook PS... ($cmd)" 337 eval "$cmd" 338 gzip -f -9 -c $PACKAGE-db.ps >"$outdir/$PACKAGE-db.ps.gz" 339 docbook_ps_gz_size=`calcsize "$outdir/$PACKAGE-db.ps.gz"` 340 mv $PACKAGE-db.ps "$outdir/" 341 342 cmd="${DOCBOOK2PDF} \"${outdir}/$PACKAGE-db.xml\"" 343 echo "Generating docbook PDF... ($cmd)" 344 eval "$cmd" 345 docbook_pdf_size=`calcsize $PACKAGE-db.pdf` 346 mv $PACKAGE-db.pdf "$outdir/" 347 fi 348 349 echo "Writing index file..." 350 if test -z "$use_texi2html"; then 351 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\ 352 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d" 353 else 354 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d" 355 fi 356 curdate=`$SETLANG date '+%B %d, %Y'` 357 sed \ 358 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \ 359 -e "s!%%EMAIL%%!$EMAIL!g" \ 360 -e "s!%%PACKAGE%%!$PACKAGE!g" \ 361 -e "s!%%DATE%%!$curdate!g" \ 362 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \ 363 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \ 364 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \ 365 -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \ 366 -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \ 367 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \ 368 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \ 369 -e "s!%%PDF_SIZE%%!$pdf_size!g" \ 370 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \ 371 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \ 372 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \ 373 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \ 374 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \ 375 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \ 376 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \ 377 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \ 378 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \ 379 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \ 380 -e "s,%%SCRIPTURL%%,$scripturl,g" \ 381 -e "s!%%SCRIPTNAME%%!$prog!g" \ 382 -e "$CONDS" \ 383 $GENDOCS_TEMPLATE_DIR/gendocs_template >"$outdir/index.html" 384 385 echo "Done, see $outdir/ subdirectory for new files." 386 387 # Local variables: 388 # eval: (add-hook 'write-file-hooks 'time-stamp) 389 # time-stamp-start: "scriptversion=" 390 # time-stamp-format: "%:y-%02m-%02d.%02H" 391 # time-stamp-end: "$" 392 # End: