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