source: vendor/m4/1.4.8/gendocs.sh@ 3442

Last change on this file since 3442 was 3090, checked in by bird, 18 years ago

m4 1.4.8

File size: 9.6 KB
Line 
1#!/bin/sh
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=2006-07-15.08
6
7# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
8#
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 2, or (at your option)
12# any later version.
13#
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.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, you can either send email to this
21# program's maintainer or write to: The Free Software Foundation,
22# Inc.; 51 Franklin Street, Fifth Floor; Boston, MA 02110-1301, USA.
23#
24# Original author: Mohit Agarwal.
25# Send bug reports and any other correspondence to bug-texinfo@gnu.org.
26
27prog=`basename "$0"`
28srcdir=`pwd`
29
30scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh"
31templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template"
32
33: ${MAKEINFO="makeinfo"}
34: ${TEXI2DVI="texi2dvi -t @finalout"}
35: ${DVIPS="dvips"}
36: ${DOCBOOK2TXT="docbook2txt"}
37: ${DOCBOOK2HTML="docbook2html"}
38: ${DOCBOOK2PDF="docbook2pdf"}
39: ${DOCBOOK2PS="docbook2ps"}
40: ${GENDOCS_TEMPLATE_DIR="."}
41unset CDPATH
42
43version="gendocs.sh $scriptversion
44
45Copyright (C) 2006 Free Software Foundation, Inc.
46There is NO warranty. You may redistribute this software
47under the terms of the GNU General Public License.
48For more information about these matters, see the files named COPYING."
49
50usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
51
52Generate various output formats from PACKAGE.texinfo (or .texi or .txi) source.
53See the GNU Maintainers document for a more extensive discussion:
54 http://www.gnu.org/prep/maintain_toc.html
55
56Options:
57 -o OUTDIR write files into OUTDIR, instead of manual/.
58 --docbook convert to DocBook too (xml, txt, html, pdf and ps).
59 --html ARG pass indicated ARG to makeinfo for HTML targets.
60 --help display this help and exit successfully.
61 --version display version information and exit successfully.
62
63Simple example: $prog emacs \"GNU Emacs Manual\"
64
65Typical sequence:
66 cd YOURPACKAGESOURCE/doc
67 wget \"$scripturl\"
68 wget \"$templateurl\"
69 $prog YOURMANUAL \"GNU YOURMANUAL - One-line description\"
70
71Output will be in a new subdirectory \"manual\" (by default, use -o OUTDIR
72to override). Move all the new files into your web CVS tree, as
73explained in the Web Pages node of maintain.texi.
74
75MANUAL-TITLE is included as part of the HTML <title> of the overall
76manual/index.html file. It should include the name of the package being
77documented. manual/index.html is created by substitution from the file
78$GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
79generic template for your own purposes.)
80
81If you have several manuals, you'll need to run this script several
82times with different YOURMANUAL values, specifying a different output
83directory with -o each time. Then write (by hand) an overall index.html
84with links to them all.
85
86You can set the environment variables MAKEINFO, TEXI2DVI, and DVIPS to
87control the programs that get executed, and GENDOCS_TEMPLATE_DIR to
88control where the gendocs_template file is looked for.
89
90Email bug reports or enhancement requests to bug-texinfo@gnu.org.
91"
92
93calcsize()
94{
95 size=`ls -ksl $1 | awk '{print $1}'`
96 echo $size
97}
98
99outdir=manual
100html=
101PACKAGE=
102MANUAL_TITLE=
103
104while test $# -gt 0; do
105 case $1 in
106 --help) echo "$usage"; exit 0;;
107 --version) echo "$version"; exit 0;;
108 -o) shift; outdir=$1;;
109 --docbook) docbook=yes;;
110 --html) shift; html=$1;;
111 -*)
112 echo "$0: Unknown or ambiguous option \`$1'." >&2
113 echo "$0: Try \`--help' for more information." >&2
114 exit 1;;
115 *)
116 if test -z "$PACKAGE"; then
117 PACKAGE=$1
118 elif test -z "$MANUAL_TITLE"; then
119 MANUAL_TITLE=$1
120 else
121 echo "$0: extra non-option argument \`$1'." >&2
122 exit 1
123 fi;;
124 esac
125 shift
126done
127
128if test -s "$srcdir/$PACKAGE.texinfo"; then
129 srcfile=$srcdir/$PACKAGE.texinfo
130elif test -s "$srcdir/$PACKAGE.texi"; then
131 srcfile=$srcdir/$PACKAGE.texi
132elif test -s "$srcdir/$PACKAGE.txi"; then
133 srcfile=$srcdir/$PACKAGE.txi
134else
135 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
136 exit 1
137fi
138
139if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
140 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
141 echo "$0: it is available from $templateurl." >&2
142 exit 1
143fi
144
145echo Generating output formats for $srcfile
146
147cmd="${MAKEINFO} -o $PACKAGE.info \"$srcfile\""
148echo "Generating info files... ($cmd)"
149eval "$cmd"
150mkdir -p $outdir/
151tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
152info_tgz_size=`calcsize $outdir/$PACKAGE.info.tar.gz`
153# do not mv the info files, there's no point in having them available
154# separately on the web.
155
156cmd="${TEXI2DVI} \"$srcfile\""
157echo "Generating dvi ... ($cmd)"
158eval "$cmd"
159
160# now, before we compress dvi:
161echo Generating postscript...
162${DVIPS} $PACKAGE -o
163gzip -f -9 $PACKAGE.ps
164ps_gz_size=`calcsize $PACKAGE.ps.gz`
165mv $PACKAGE.ps.gz $outdir/
166
167# compress/finish dvi:
168gzip -f -9 $PACKAGE.dvi
169dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
170mv $PACKAGE.dvi.gz $outdir/
171
172cmd="${TEXI2DVI} --pdf \"$srcfile\""
173echo "Generating pdf ... ($cmd)"
174eval "$cmd"
175pdf_size=`calcsize $PACKAGE.pdf`
176mv $PACKAGE.pdf $outdir/
177
178cmd="${MAKEINFO} -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
179echo "Generating ASCII... ($cmd)"
180eval "$cmd"
181ascii_size=`calcsize $PACKAGE.txt`
182gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
183ascii_gz_size=`calcsize $outdir/$PACKAGE.txt.gz`
184mv $PACKAGE.txt $outdir/
185
186cmd="${MAKEINFO} --no-split --html -o $PACKAGE.html $html \"$srcfile\""
187echo "Generating monolithic html... ($cmd)"
188rm -rf $PACKAGE.html # in case a directory is left over
189eval "$cmd"
190html_mono_size=`calcsize $PACKAGE.html`
191gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
192html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
193mv $PACKAGE.html $outdir/
194
195cmd="${MAKEINFO} --html -o $PACKAGE.html $html \"$srcfile\""
196echo "Generating html by node... ($cmd)"
197eval "$cmd"
198split_html_dir=$PACKAGE.html
199(
200 cd ${split_html_dir} || exit 1
201 tar -czf ../$outdir/${PACKAGE}.html_node.tar.gz -- *.html
202)
203html_node_tgz_size=`calcsize $outdir/${PACKAGE}.html_node.tar.gz`
204rm -f $outdir/html_node/*.html
205mkdir -p $outdir/html_node/
206mv ${split_html_dir}/*.html $outdir/html_node/
207rmdir ${split_html_dir}
208
209echo Making .tar.gz for sources...
210srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null`
211tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
212texi_tgz_size=`calcsize $outdir/$PACKAGE.texi.tar.gz`
213
214if test -n "$docbook"; then
215 cmd="${MAKEINFO} -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
216 echo "Generating docbook XML... $(cmd)"
217 eval "$cmd"
218 docbook_xml_size=`calcsize $PACKAGE-db.xml`
219 gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
220 docbook_xml_gz_size=`calcsize $outdir/$PACKAGE-db.xml.gz`
221 mv $PACKAGE-db.xml $outdir/
222
223 cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml"
224 echo "Generating docbook HTML... ($cmd)"
225 eval "$cmd"
226 split_html_db_dir=html_node_db
227 (
228 cd ${split_html_db_dir} || exit 1
229 tar -czf ../$outdir/${PACKAGE}.html_node_db.tar.gz -- *.html
230 )
231 html_node_db_tgz_size=`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`
232 rm -f $outdir/html_node_db/*.html
233 mkdir -p $outdir/html_node_db
234 mv ${split_html_db_dir}/*.html $outdir/html_node_db/
235 rmdir ${split_html_db_dir}
236
237 cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml"
238 echo "Generating docbook ASCII... ($cmd)"
239 eval "$cmd"
240 docbook_ascii_size=`calcsize $PACKAGE-db.txt`
241 mv $PACKAGE-db.txt $outdir/
242
243 cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml"
244 echo "Generating docbook PS... $(cmd)"
245 eval "$cmd"
246 gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
247 docbook_ps_gz_size=`calcsize $outdir/$PACKAGE-db.ps.gz`
248 mv $PACKAGE-db.ps $outdir/
249
250 cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml"
251 echo "Generating docbook PDF... ($cmd)"
252 eval "$cmd"
253 docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
254 mv $PACKAGE-db.pdf $outdir/
255fi
256
257echo Writing index file...
258curdate=`date '+%B %d, %Y'`
259sed \
260 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
261 -e "s!%%DATE%%!$curdate!g" \
262 -e "s!%%PACKAGE%%!$PACKAGE!g" \
263 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
264 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
265 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
266 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
267 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
268 -e "s!%%PDF_SIZE%%!$pdf_size!g" \
269 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
270 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
271 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
272 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
273 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
274 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
275 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
276 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
277 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
278 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
279 -e "s,%%SCRIPTURL%%,$scripturl,g" \
280 -e "s!%%SCRIPTNAME%%!$prog!g" \
281$GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
282
283echo "Done! See $outdir/ subdirectory for new files."
284
285# Local variables:
286# eval: (add-hook 'write-file-hooks 'time-stamp)
287# time-stamp-start: "scriptversion="
288# time-stamp-format: "%:y-%02m-%02d.%02H"
289# time-stamp-end: "$"
290# End:
Note: See TracBrowser for help on using the repository browser.