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
=2012-09-02.17
7 # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
8 # Free Software Foundation, Inc.
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.
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.
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/>.
23 # Original author: Mohit Agarwal.
24 # Send bug reports and any other correspondence to bug-texinfo@gnu.org.
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
31 # An up-to-date copy is also maintained in Gnulib (gnu.org/software/gnulib).
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"
39 : ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="}
40 : ${MAKEINFO="makeinfo"}
41 : ${TEXI2DVI="texi2dvi -t @finalout"}
43 : ${DOCBOOK2HTML="docbook2html"}
44 : ${DOCBOOK2PDF="docbook2pdf"}
45 : ${DOCBOOK2PS="docbook2ps"}
46 : ${DOCBOOK2TXT="docbook2txt"}
47 : ${GENDOCS_TEMPLATE_DIR="."}
48 : ${TEXI2HTML="texi2html"}
52 version
="gendocs.sh $scriptversion
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."
59 usage
="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
61 Generate output in various formats from PACKAGE.texinfo (or .texi or
62 .txi) source. See the GNU Maintainers document for a more extensive
64 http://www.gnu.org/prep/maintain_toc.html
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.
77 Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
83 $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
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.
89 Please do use the --email ADDRESS option to specify your bug-reporting
90 address in the generated HTML pages.
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.)
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.
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.)
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.
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.
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.
121 Email bug reports or enhancement requests to bug-texinfo@gnu.org.
126 size
=`ls -ksl $1 | awk '{print $1}'`
132 EMAIL
=webmasters@gnu.org
# please override with --email
138 while test $# -gt 0; do
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;;
150 echo "$0: Unknown option \`$1'." >&2
151 echo "$0: Try \`--help' for more information." >&2
154 if test -z "$PACKAGE"; then
156 elif test -z "$MANUAL_TITLE"; then
159 echo "$0: extra non-option argument \`$1'." >&2
166 # For most of the following, the base name is just $PACKAGE
169 if test -n "$srcfile"; then
170 # but here, we use the basename of $srcfile
171 base
=`basename "$srcfile"`
173 *.txi|
*.texi|
*.texinfo
) base
=`echo "$base"|sed 's/\.[texinfo]*$//'`;;
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
183 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
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
194 /*) abs_outdir
=$outdir;;
195 *) abs_outdir
=$srcdir/$outdir;;
198 echo "Generating output formats for $srcfile"
200 cmd
="$SETLANG $MAKEINFO -o $PACKAGE.info $infoarg \"$srcfile\""
201 echo "Generating info file(s)... ($cmd)"
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.
209 cmd
="$SETLANG ${TEXI2DVI} \"$srcfile\""
210 echo "Generating dvi ... ($cmd)"
213 # now, before we compress dvi:
214 echo "Generating postscript..."
216 gzip -f -9 $PACKAGE.ps
217 ps_gz_size
=`calcsize $PACKAGE.ps.gz`
218 mv $PACKAGE.ps.gz
"$outdir/"
220 # compress/finish dvi:
221 gzip -f -9 $PACKAGE.dvi
222 dvi_gz_size
=`calcsize $PACKAGE.dvi.gz`
223 mv $PACKAGE.dvi.gz
"$outdir/"
225 cmd
="$SETLANG ${TEXI2DVI} --pdf \"$srcfile\""
226 echo "Generating pdf ... ($cmd)"
228 pdf_size
=`calcsize $PACKAGE.pdf`
229 mv $PACKAGE.pdf
"$outdir/"
231 cmd
="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
232 echo "Generating ASCII... ($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/"
241 opt
="--split=$1 $htmlarg --node-files"
242 cmd
="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
243 echo "Generating html by $1... ($cmd)"
245 split_html_dir
=$PACKAGE.html
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
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}
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
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/"
269 cmd
="$SETLANG $MAKEINFO --html -o $PACKAGE.html $htmlarg \"$srcfile\""
270 echo "Generating html by node... ($cmd)"
272 split_html_dir
=$PACKAGE.html
274 cd ${split_html_dir} ||
exit 1
275 tar -czf "$abs_outdir/${PACKAGE}.html_node.tar.gz" -- *.html
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}
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
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/"
297 echo Making .
tar.gz
for sources...
301 srcfiles
=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null` || true
302 tar cvzfh
"$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles
304 texi_tgz_size
=`calcsize "$outdir/$PACKAGE.texi.tar.gz"`
306 if test -n "$docbook"; then
307 cmd
="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
308 echo "Generating docbook XML... ($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/"
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)"
320 cd ${split_html_db_dir} ||
exit 1
321 tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html
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}
329 cmd
="${DOCBOOK2TXT} \"${outdir}/$PACKAGE-db.xml\""
330 echo "Generating docbook ASCII... ($cmd)"
332 docbook_ascii_size
=`calcsize $PACKAGE-db.txt`
333 mv $PACKAGE-db.txt
"$outdir/"
335 cmd
="${DOCBOOK2PS} \"${outdir}/$PACKAGE-db.xml\""
336 echo "Generating docbook PS... ($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/"
342 cmd
="${DOCBOOK2PDF} \"${outdir}/$PACKAGE-db.xml\""
343 echo "Generating docbook PDF... ($cmd)"
345 docbook_pdf_size
=`calcsize $PACKAGE-db.pdf`
346 mv $PACKAGE-db.pdf
"$outdir/"
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"
354 CONDS
="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
356 curdate
=`$SETLANG date '+%B %d, %Y'`
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" \
383 $GENDOCS_TEMPLATE_DIR/gendocs_template
>"$outdir/index.html"
385 echo "Done, see $outdir/ subdirectory for new files."
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: "$"