source: trunk/essentials/sys-apps/texinfo/util/gendocs.sh

Last change on this file was 2617, checked in by bird, 19 years ago

GNU Texinfo 4.8

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