Update `THANKS'.
[bpt/guile.git] / build-aux / gendocs.sh
CommitLineData
61cd9dc9 1#!/bin/sh -e
c84bdaf6
LC
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
dde9c5a4 5scriptversion=2010-02-13.20
c84bdaf6 6
61cd9dc9 7# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
c84bdaf6
LC
8# Free Software Foundation, Inc.
9#
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.
14#
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.
19#
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/>.
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/~checkout~/texinfo/texinfo/util/gendocs.sh"
30templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template"
31
32: ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="}
33: ${MAKEINFO="makeinfo"}
34: ${TEXI2DVI="texi2dvi -t @finalout"}
35: ${DVIPS="dvips"}
36: ${DOCBOOK2HTML="docbook2html"}
37: ${DOCBOOK2PDF="docbook2pdf"}
38: ${DOCBOOK2PS="docbook2ps"}
39: ${DOCBOOK2TXT="docbook2txt"}
40: ${GENDOCS_TEMPLATE_DIR="."}
41: ${TEXI2HTML="texi2html"}
42unset CDPATH
43unset use_texi2html
44
45version="gendocs.sh $scriptversion
46
47Copyright 2009 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:
dde9c5a4 59 -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi}
c84bdaf6
LC
60 -o OUTDIR write files into OUTDIR, instead of manual/.
61 --email ADR use ADR as contact in generated web pages.
62 --docbook convert to DocBook too (xml, txt, html, pdf and ps).
63 --html ARG pass indicated ARG to makeinfo or texi2html for HTML targets.
64 --texi2html use texi2html to generate HTML targets.
65 --help display this help and exit successfully.
66 --version display version information and exit successfully.
67
68Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
69
70Typical sequence:
71 cd PACKAGESOURCE/doc
72 wget \"$scripturl\"
73 wget \"$templateurl\"
74 $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
75
76Output will be in a new subdirectory \"manual\" (by default, use -o OUTDIR
77to override). Move all the new files into your web CVS tree, as
78explained in the Web Pages node of maintain.texi.
79
80Please use the --email ADDRESS option to specify your bug-reporting
81address in the generated HTML pages.
82
83MANUAL-TITLE is included as part of the HTML <title> of the overall
84manual/index.html file. It should include the name of the package being
85documented. manual/index.html is created by substitution from the file
86$GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
87generic template for your own purposes.)
88
89If you have several manuals, you'll need to run this script several
90times with different MANUAL values, specifying a different output
91directory with -o each time. Then write (by hand) an overall index.html
92with links to them all.
93
94If a manual's Texinfo sources are spread across several directories,
95first copy or symlink all Texinfo sources into a single directory.
96(Part of the script's work is to make a tar.gz of the sources.)
97
98You can set the environment variables MAKEINFO, TEXI2DVI, and DVIPS to
99control the programs that get executed, and GENDOCS_TEMPLATE_DIR to
100control where the gendocs_template file is looked for. (With --docbook,
101the environment variables DOCBOOK2HTML, DOCBOOK2PDF, DOCBOOK2PS, and
102DOCBOOK2TXT are also respected.)
103
104By default, makeinfo is run in the default (English) locale, since
105that's the language of most Texinfo manuals. If you happen to have a
106non-English manual and non-English web site, see the SETLANG setting
107in the source.
108
109Email bug reports or enhancement requests to bug-texinfo@gnu.org.
110"
111
112calcsize()
113{
114 size=`ls -ksl $1 | awk '{print $1}'`
115 echo $size
116}
117
118MANUAL_TITLE=
119PACKAGE=
120EMAIL=webmasters@gnu.org # please override with --email
121htmlarg=
122outdir=manual
dde9c5a4 123srcfile=
c84bdaf6
LC
124
125while test $# -gt 0; do
126 case $1 in
127 --email) shift; EMAIL=$1;;
128 --help) echo "$usage"; exit 0;;
129 --version) echo "$version"; exit 0;;
dde9c5a4 130 -s) shift; srcfile=$1;;
c84bdaf6
LC
131 -o) shift; outdir=$1;;
132 --docbook) docbook=yes;;
133 --html) shift; htmlarg=$1;;
134 --texi2html) use_texi2html=1;;
135 -*)
136 echo "$0: Unknown option \`$1'." >&2
137 echo "$0: Try \`--help' for more information." >&2
138 exit 1;;
139 *)
140 if test -z "$PACKAGE"; then
141 PACKAGE=$1
142 elif test -z "$MANUAL_TITLE"; then
143 MANUAL_TITLE=$1
144 else
145 echo "$0: extra non-option argument \`$1'." >&2
146 exit 1
147 fi;;
148 esac
149 shift
150done
151
dde9c5a4
LC
152if test -n "$srcfile"; then
153 :
154elif test -s "$srcdir/$PACKAGE.texinfo"; then
c84bdaf6
LC
155 srcfile=$srcdir/$PACKAGE.texinfo
156elif test -s "$srcdir/$PACKAGE.texi"; then
157 srcfile=$srcdir/$PACKAGE.texi
158elif test -s "$srcdir/$PACKAGE.txi"; then
159 srcfile=$srcdir/$PACKAGE.txi
160else
161 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
162 exit 1
163fi
164
165if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
166 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
167 echo "$0: it is available from $templateurl." >&2
168 exit 1
169fi
170
171case $outdir in
172 /*) dotdot_outdir="$outdir";;
173 *) dotdot_outdir="../$outdir";;
174esac
175
176echo Generating output formats for $srcfile
177
178cmd="$SETLANG $MAKEINFO -o $PACKAGE.info \"$srcfile\""
179echo "Generating info files... ($cmd)"
180eval "$cmd"
181mkdir -p $outdir/
182tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
183info_tgz_size=`calcsize $outdir/$PACKAGE.info.tar.gz`
184# do not mv the info files, there's no point in having them available
185# separately on the web.
186
187cmd="${TEXI2DVI} \"$srcfile\""
188echo "Generating dvi ... ($cmd)"
189eval "$cmd"
190
191# now, before we compress dvi:
192echo Generating postscript...
193${DVIPS} $PACKAGE -o
194gzip -f -9 $PACKAGE.ps
195ps_gz_size=`calcsize $PACKAGE.ps.gz`
196mv $PACKAGE.ps.gz $outdir/
197
198# compress/finish dvi:
199gzip -f -9 $PACKAGE.dvi
200dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
201mv $PACKAGE.dvi.gz $outdir/
202
203cmd="${TEXI2DVI} --pdf \"$srcfile\""
204echo "Generating pdf ... ($cmd)"
205eval "$cmd"
206pdf_size=`calcsize $PACKAGE.pdf`
207mv $PACKAGE.pdf $outdir/
208
209cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
210echo "Generating ASCII... ($cmd)"
211eval "$cmd"
212ascii_size=`calcsize $PACKAGE.txt`
213gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
214ascii_gz_size=`calcsize $outdir/$PACKAGE.txt.gz`
215mv $PACKAGE.txt $outdir/
216
217html_split()
218{
219 opt="--split=$1 $htmlarg --node-files"
220 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
221 echo "Generating html by $1... ($cmd)"
222 eval "$cmd"
223 split_html_dir=$PACKAGE.html
224 (
225 cd ${split_html_dir} || exit 1
226 ln -sf ${PACKAGE}.html index.html
227 tar -czf $dotdot_outdir/${PACKAGE}.html_$1.tar.gz -- *.html
228 )
229 eval html_$1_tgz_size=`calcsize $outdir/${PACKAGE}.html_$1.tar.gz`
230 rm -f $outdir/html_$1/*.html
231 mkdir -p $outdir/html_$1/
232 mv ${split_html_dir}/*.html $outdir/html_$1/
233 rmdir ${split_html_dir}
234}
235
236if test -z "$use_texi2html"; then
237 opt="--no-split --html -o $PACKAGE.html $htmlarg"
238 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
239 echo "Generating monolithic html... ($cmd)"
240 rm -rf $PACKAGE.html # in case a directory is left over
241 eval "$cmd"
242 html_mono_size=`calcsize $PACKAGE.html`
243 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
244 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
245 mv $PACKAGE.html $outdir/
246
247 cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $htmlarg \"$srcfile\""
248 echo "Generating html by node... ($cmd)"
249 eval "$cmd"
250 split_html_dir=$PACKAGE.html
251 (
252 cd ${split_html_dir} || exit 1
253 tar -czf $dotdot_outdir/${PACKAGE}.html_node.tar.gz -- *.html
254 )
255 html_node_tgz_size=`calcsize $outdir/${PACKAGE}.html_node.tar.gz`
256 rm -f $outdir/html_node/*.html
257 mkdir -p $outdir/html_node/
258 mv ${split_html_dir}/*.html $outdir/html_node/
259 rmdir ${split_html_dir}
260else
261 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $htmlarg \"$srcfile\""
262 echo "Generating monolithic html... ($cmd)"
263 rm -rf $PACKAGE.html # in case a directory is left over
264 eval "$cmd"
265 html_mono_size=`calcsize $PACKAGE.html`
266 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
267 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
268 mv $PACKAGE.html $outdir/
269
270 html_split node
271 html_split chapter
272 html_split section
273fi
274
275echo Making .tar.gz for sources...
dde9c5a4
LC
276d=`dirname $srcfile`
277srcfiles=`ls $d/*.texinfo $d/*.texi $d/*.txi $d/*.eps 2>/dev/null` || true
c84bdaf6
LC
278tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
279texi_tgz_size=`calcsize $outdir/$PACKAGE.texi.tar.gz`
280
281if test -n "$docbook"; then
282 cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
dde9c5a4 283 echo "Generating docbook XML... ($cmd)"
c84bdaf6
LC
284 eval "$cmd"
285 docbook_xml_size=`calcsize $PACKAGE-db.xml`
286 gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
287 docbook_xml_gz_size=`calcsize $outdir/$PACKAGE-db.xml.gz`
288 mv $PACKAGE-db.xml $outdir/
289
290 cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml"
291 echo "Generating docbook HTML... ($cmd)"
292 eval "$cmd"
293 split_html_db_dir=html_node_db
294 (
295 cd ${split_html_db_dir} || exit 1
296 tar -czf $dotdot_outdir/${PACKAGE}.html_node_db.tar.gz -- *.html
297 )
298 html_node_db_tgz_size=`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`
299 rm -f $outdir/html_node_db/*.html
300 mkdir -p $outdir/html_node_db
301 mv ${split_html_db_dir}/*.html $outdir/html_node_db/
302 rmdir ${split_html_db_dir}
303
304 cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml"
305 echo "Generating docbook ASCII... ($cmd)"
306 eval "$cmd"
307 docbook_ascii_size=`calcsize $PACKAGE-db.txt`
308 mv $PACKAGE-db.txt $outdir/
309
310 cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml"
dde9c5a4 311 echo "Generating docbook PS... ($cmd)"
c84bdaf6
LC
312 eval "$cmd"
313 gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
314 docbook_ps_gz_size=`calcsize $outdir/$PACKAGE-db.ps.gz`
315 mv $PACKAGE-db.ps $outdir/
316
317 cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml"
318 echo "Generating docbook PDF... ($cmd)"
319 eval "$cmd"
320 docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
321 mv $PACKAGE-db.pdf $outdir/
322fi
323
324echo "Writing index file..."
325if test -z "$use_texi2html"; then
326 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
327 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
328else
329 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
330fi
331curdate=`$SETLANG date '+%B %d, %Y'`
332sed \
333 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
334 -e "s!%%EMAIL%%!$EMAIL!g" \
335 -e "s!%%PACKAGE%%!$PACKAGE!g" \
336 -e "s!%%DATE%%!$curdate!g" \
337 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
338 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
339 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
340 -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
341 -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
342 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
343 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
344 -e "s!%%PDF_SIZE%%!$pdf_size!g" \
345 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
346 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
347 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
348 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
349 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
350 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
351 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
352 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
353 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
354 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
355 -e "s,%%SCRIPTURL%%,$scripturl,g" \
356 -e "s!%%SCRIPTNAME%%!$prog!g" \
357 -e "$CONDS" \
358$GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
359
360echo "Done, see $outdir/ subdirectory for new files."
361
362# Local variables:
363# eval: (add-hook 'write-file-hooks 'time-stamp)
364# time-stamp-start: "scriptversion="
365# time-stamp-format: "%:y-%02m-%02d.%02H"
366# time-stamp-end: "$"
367# End: