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