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.
5 scriptversion=2010-11-27.07
7 # Copyright 2003-2010 Free Software Foundation, Inc.
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Original author: Mohit Agarwal.
23 # Send bug reports and any other correspondence to bug-texinfo@gnu.org.
25 # The latest version of this script, and the companion template, is
26 # available from Texinfo CVS:
27 # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs.sh
28 # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template
30 # An up-to-date copy is also maintained in Gnulib (gnu.org/software/gnulib).
35 scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh"
36 templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template"
38 : ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="}
39 : ${MAKEINFO="makeinfo"}
40 : ${TEXI2DVI="texi2dvi -t @finalout"}
42 : ${DOCBOOK2HTML="docbook2html"}
43 : ${DOCBOOK2PDF="docbook2pdf"}
44 : ${DOCBOOK2PS="docbook2ps"}
45 : ${DOCBOOK2TXT="docbook2txt"}
46 : ${GENDOCS_TEMPLATE_DIR="."}
47 : ${TEXI2HTML="texi2html"}
51 version="gendocs.sh $scriptversion
53 Copyright 2010 Free Software Foundation, Inc.
54 There is NO warranty. You may redistribute this software
55 under the terms of the GNU General Public License.
56 For more information about these matters, see the files named COPYING."
58 usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
60 Generate various output formats from PACKAGE.texinfo (or .texi or .txi) source.
61 See the GNU Maintainers document for a more extensive discussion:
62 http://www.gnu.org/prep/maintain_toc.html
65 -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi}
66 -o OUTDIR write files into OUTDIR, instead of manual/.
67 --email ADR use ADR as contact in generated web pages.
68 --docbook convert to DocBook too (xml, txt, html, pdf and ps).
69 --html ARG pass indicated ARG to makeinfo or texi2html for HTML targets.
70 --texi2html use texi2html to generate HTML targets.
71 --help display this help and exit successfully.
72 --version display version information and exit successfully.
74 Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
80 $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
82 Output will be in a new subdirectory \"manual\" (by default, use -o OUTDIR
83 to override). Move all the new files into your web CVS tree, as
84 explained in the Web Pages node of maintain.texi.
86 Please use the --email ADDRESS option to specify your bug-reporting
87 address in the generated HTML pages.
89 MANUAL-TITLE is included as part of the HTML <title> of the overall
90 manual/index.html file. It should include the name of the package being
91 documented. manual/index.html is created by substitution from the file
92 $GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
93 generic template for your own purposes.)
95 If you have several manuals, you'll need to run this script several
96 times with different MANUAL values, specifying a different output
97 directory with -o each time. Then write (by hand) an overall index.html
98 with links to them all.
100 If a manual's Texinfo sources are spread across several directories,
101 first copy or symlink all Texinfo sources into a single directory.
102 (Part of the script's work is to make a tar.gz of the sources.)
104 You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML, and
105 DVIPS to control the programs that get executed, and
106 GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is
107 looked for. With --docbook, the environment variables DOCBOOK2HTML,
108 DOCBOOK2PDF, DOCBOOK2PS, and DOCBOOK2TXT are also respected.
110 By default, makeinfo and texi2dvi are run in the default (English)
111 locale, since that's the language of most Texinfo manuals. If you
112 happen to have a non-English manual and non-English web site, see the
113 SETLANG setting in the source.
115 Email bug reports or enhancement requests to bug-texinfo@gnu.org.
120 size=`ls -ksl $1 | awk '{print $1}'`
126 EMAIL=webmasters@gnu.org # please override with --email
131 while test $# -gt 0; do
133 --email) shift; EMAIL=$1;;
134 --help) echo "$usage"; exit 0;;
135 --version) echo "$version"; exit 0;;
136 -s) shift; srcfile=$1;;
137 -o) shift; outdir=$1;;
138 --docbook) docbook=yes;;
139 --html) shift; htmlarg=$1;;
140 --texi2html) use_texi2html=1;;
142 echo "$0: Unknown option \`$1'." >&2
143 echo "$0: Try \`--help' for more information." >&2
146 if test -z "$PACKAGE"; then
148 elif test -z "$MANUAL_TITLE"; then
151 echo "$0: extra non-option argument \`$1'." >&2
158 # For most of the following, the base name is just $PACKAGE
161 if test -n "$srcfile"; then
162 # but here, we use the basename of $srcfile
163 base=`basename "$srcfile"`
165 *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;;
168 elif test -s "$srcdir/$PACKAGE.texinfo"; then
169 srcfile=$srcdir/$PACKAGE.texinfo
170 elif test -s "$srcdir/$PACKAGE.texi"; then
171 srcfile=$srcdir/$PACKAGE.texi
172 elif test -s "$srcdir/$PACKAGE.txi"; then
173 srcfile=$srcdir/$PACKAGE.txi
175 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
179 if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
180 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
181 echo "$0: it is available from $templateurl." >&2
186 /*) abs_outdir=$outdir;;
187 *) abs_outdir=$srcdir/$outdir;;
190 echo Generating output formats for $srcfile
192 cmd="$SETLANG $MAKEINFO -o $PACKAGE.info \"$srcfile\""
193 echo "Generating info files... ($cmd)"
196 tar czf "$outdir/$PACKAGE.info.tar.gz" $PACKAGE.info*
197 info_tgz_size=`calcsize "$outdir/$PACKAGE.info.tar.gz"`
198 # do not mv the info files, there's no point in having them available
199 # separately on the web.
201 cmd="$SETLANG ${TEXI2DVI} \"$srcfile\""
202 echo "Generating dvi ... ($cmd)"
205 # now, before we compress dvi:
206 echo Generating postscript...
208 gzip -f -9 $PACKAGE.ps
209 ps_gz_size=`calcsize $PACKAGE.ps.gz`
210 mv $PACKAGE.ps.gz "$outdir/"
212 # compress/finish dvi:
213 gzip -f -9 $PACKAGE.dvi
214 dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
215 mv $PACKAGE.dvi.gz "$outdir/"
217 cmd="$SETLANG ${TEXI2DVI} --pdf \"$srcfile\""
218 echo "Generating pdf ... ($cmd)"
220 pdf_size=`calcsize $PACKAGE.pdf`
221 mv $PACKAGE.pdf "$outdir/"
223 cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
224 echo "Generating ASCII... ($cmd)"
226 ascii_size=`calcsize $PACKAGE.txt`
227 gzip -f -9 -c $PACKAGE.txt >"$outdir/$PACKAGE.txt.gz"
228 ascii_gz_size=`calcsize "$outdir/$PACKAGE.txt.gz"`
229 mv $PACKAGE.txt "$outdir/"
233 opt="--split=$1 $htmlarg --node-files"
234 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
235 echo "Generating html by $1... ($cmd)"
237 split_html_dir=$PACKAGE.html
239 cd ${split_html_dir} || exit 1
240 ln -sf ${PACKAGE}.html index.html
241 tar -czf "$abs_outdir/${PACKAGE}.html_$1.tar.gz" -- *.html
243 eval html_$1_tgz_size=`calcsize "$outdir/${PACKAGE}.html_$1.tar.gz"`
244 rm -f "$outdir"/html_$1/*.html
245 mkdir -p "$outdir/html_$1/"
246 mv ${split_html_dir}/*.html "$outdir/html_$1/"
247 rmdir ${split_html_dir}
250 if test -z "$use_texi2html"; then
251 opt="--no-split --html -o $PACKAGE.html $htmlarg"
252 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
253 echo "Generating monolithic html... ($cmd)"
254 rm -rf $PACKAGE.html # in case a directory is left over
256 html_mono_size=`calcsize $PACKAGE.html`
257 gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
258 html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
259 mv $PACKAGE.html "$outdir/"
261 cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $htmlarg \"$srcfile\""
262 echo "Generating html by node... ($cmd)"
264 split_html_dir=$PACKAGE.html
266 cd ${split_html_dir} || exit 1
267 tar -czf "$abs_outdir/${PACKAGE}.html_node.tar.gz" -- *.html
269 html_node_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node.tar.gz"`
270 rm -f "$outdir"/html_node/*.html
271 mkdir -p "$outdir/html_node/"
272 mv ${split_html_dir}/*.html "$outdir/html_node/"
273 rmdir ${split_html_dir}
275 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $htmlarg \"$srcfile\""
276 echo "Generating monolithic html... ($cmd)"
277 rm -rf $PACKAGE.html # in case a directory is left over
279 html_mono_size=`calcsize $PACKAGE.html`
280 gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
281 html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
282 mv $PACKAGE.html "$outdir/"
289 echo Making .tar.gz for sources...
293 srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null` || true
294 tar cvzfh "$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles
296 texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"`
298 if test -n "$docbook"; then
299 cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
300 echo "Generating docbook XML... ($cmd)"
302 docbook_xml_size=`calcsize $PACKAGE-db.xml`
303 gzip -f -9 -c $PACKAGE-db.xml >"$outdir/$PACKAGE-db.xml.gz"
304 docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"`
305 mv $PACKAGE-db.xml "$outdir/"
307 cmd="${DOCBOOK2HTML} -o $split_html_db_dir \"${outdir}/$PACKAGE-db.xml\""
308 echo "Generating docbook HTML... ($cmd)"
310 split_html_db_dir=html_node_db
312 cd ${split_html_db_dir} || exit 1
313 tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html
315 html_node_db_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node_db.tar.gz"`
316 rm -f "$outdir"/html_node_db/*.html
317 mkdir -p "$outdir/html_node_db"
318 mv ${split_html_db_dir}/*.html "$outdir/html_node_db/"
319 rmdir ${split_html_db_dir}
321 cmd="${DOCBOOK2TXT} \"${outdir}/$PACKAGE-db.xml\""
322 echo "Generating docbook ASCII... ($cmd)"
324 docbook_ascii_size=`calcsize $PACKAGE-db.txt`
325 mv $PACKAGE-db.txt "$outdir/"
327 cmd="${DOCBOOK2PS} \"${outdir}/$PACKAGE-db.xml\""
328 echo "Generating docbook PS... ($cmd)"
330 gzip -f -9 -c $PACKAGE-db.ps >"$outdir/$PACKAGE-db.ps.gz"
331 docbook_ps_gz_size=`calcsize "$outdir/$PACKAGE-db.ps.gz"`
332 mv $PACKAGE-db.ps "$outdir/"
334 cmd="${DOCBOOK2PDF} \"${outdir}/$PACKAGE-db.xml\""
335 echo "Generating docbook PDF... ($cmd)"
337 docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
338 mv $PACKAGE-db.pdf "$outdir/"
341 echo "Writing index file..."
342 if test -z "$use_texi2html"; then
343 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
344 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
346 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
348 curdate=`$SETLANG date '+%B %d, %Y'`
350 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
351 -e "s!%%EMAIL%%!$EMAIL!g" \
352 -e "s!%%PACKAGE%%!$PACKAGE!g" \
353 -e "s!%%DATE%%!$curdate!g" \
354 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
355 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
356 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
357 -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
358 -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
359 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
360 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
361 -e "s!%%PDF_SIZE%%!$pdf_size!g" \
362 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
363 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
364 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
365 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
366 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
367 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
368 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
369 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
370 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
371 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
372 -e "s,%%SCRIPTURL%%,$scripturl,g" \
373 -e "s!%%SCRIPTNAME%%!$prog!g" \
375 $GENDOCS_TEMPLATE_DIR/gendocs_template >"$outdir/index.html"
377 echo "Done, see $outdir/ subdirectory for new files."
380 # eval: (add-hook 'write-file-hooks 'time-stamp)
381 # time-stamp-start: "scriptversion="
382 # time-stamp-format: "%:y-%02m-%02d.%02H"
383 # time-stamp-end: "$"