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