Merge branch 'master' into wip-manual-2
[bpt/guile.git] / build-aux / gendocs.sh
1 #!/bin/sh -e
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
5 scriptversion=2010-02-13.20
6
7 # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
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
26 prog=`basename "$0"`
27 srcdir=`pwd`
28
29 scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh"
30 templateurl="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"}
42 unset CDPATH
43 unset use_texi2html
44
45 version="gendocs.sh $scriptversion
46
47 Copyright 2009 Free Software Foundation, Inc.
48 There is NO warranty. You may redistribute this software
49 under the terms of the GNU General Public License.
50 For more information about these matters, see the files named COPYING."
51
52 usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
53
54 Generate various output formats from PACKAGE.texinfo (or .texi or .txi) source.
55 See the GNU Maintainers document for a more extensive discussion:
56 http://www.gnu.org/prep/maintain_toc.html
57
58 Options:
59 -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi}
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
68 Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
69
70 Typical sequence:
71 cd PACKAGESOURCE/doc
72 wget \"$scripturl\"
73 wget \"$templateurl\"
74 $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
75
76 Output will be in a new subdirectory \"manual\" (by default, use -o OUTDIR
77 to override). Move all the new files into your web CVS tree, as
78 explained in the Web Pages node of maintain.texi.
79
80 Please use the --email ADDRESS option to specify your bug-reporting
81 address in the generated HTML pages.
82
83 MANUAL-TITLE is included as part of the HTML <title> of the overall
84 manual/index.html file. It should include the name of the package being
85 documented. manual/index.html is created by substitution from the file
86 $GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
87 generic template for your own purposes.)
88
89 If you have several manuals, you'll need to run this script several
90 times with different MANUAL values, specifying a different output
91 directory with -o each time. Then write (by hand) an overall index.html
92 with links to them all.
93
94 If a manual's Texinfo sources are spread across several directories,
95 first 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
98 You can set the environment variables MAKEINFO, TEXI2DVI, and DVIPS to
99 control the programs that get executed, and GENDOCS_TEMPLATE_DIR to
100 control where the gendocs_template file is looked for. (With --docbook,
101 the environment variables DOCBOOK2HTML, DOCBOOK2PDF, DOCBOOK2PS, and
102 DOCBOOK2TXT are also respected.)
103
104 By default, makeinfo is run in the default (English) locale, since
105 that's the language of most Texinfo manuals. If you happen to have a
106 non-English manual and non-English web site, see the SETLANG setting
107 in the source.
108
109 Email bug reports or enhancement requests to bug-texinfo@gnu.org.
110 "
111
112 calcsize()
113 {
114 size=`ls -ksl $1 | awk '{print $1}'`
115 echo $size
116 }
117
118 MANUAL_TITLE=
119 PACKAGE=
120 EMAIL=webmasters@gnu.org # please override with --email
121 htmlarg=
122 outdir=manual
123 srcfile=
124
125 while 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;;
130 -s) shift; srcfile=$1;;
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
150 done
151
152 if test -n "$srcfile"; then
153 :
154 elif test -s "$srcdir/$PACKAGE.texinfo"; then
155 srcfile=$srcdir/$PACKAGE.texinfo
156 elif test -s "$srcdir/$PACKAGE.texi"; then
157 srcfile=$srcdir/$PACKAGE.texi
158 elif test -s "$srcdir/$PACKAGE.txi"; then
159 srcfile=$srcdir/$PACKAGE.txi
160 else
161 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
162 exit 1
163 fi
164
165 if 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
169 fi
170
171 case $outdir in
172 /*) dotdot_outdir="$outdir";;
173 *) dotdot_outdir="../$outdir";;
174 esac
175
176 echo Generating output formats for $srcfile
177
178 cmd="$SETLANG $MAKEINFO -o $PACKAGE.info \"$srcfile\""
179 echo "Generating info files... ($cmd)"
180 eval "$cmd"
181 mkdir -p $outdir/
182 tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
183 info_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
187 cmd="${TEXI2DVI} \"$srcfile\""
188 echo "Generating dvi ... ($cmd)"
189 eval "$cmd"
190
191 # now, before we compress dvi:
192 echo Generating postscript...
193 ${DVIPS} $PACKAGE -o
194 gzip -f -9 $PACKAGE.ps
195 ps_gz_size=`calcsize $PACKAGE.ps.gz`
196 mv $PACKAGE.ps.gz $outdir/
197
198 # compress/finish dvi:
199 gzip -f -9 $PACKAGE.dvi
200 dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
201 mv $PACKAGE.dvi.gz $outdir/
202
203 cmd="${TEXI2DVI} --pdf \"$srcfile\""
204 echo "Generating pdf ... ($cmd)"
205 eval "$cmd"
206 pdf_size=`calcsize $PACKAGE.pdf`
207 mv $PACKAGE.pdf $outdir/
208
209 cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
210 echo "Generating ASCII... ($cmd)"
211 eval "$cmd"
212 ascii_size=`calcsize $PACKAGE.txt`
213 gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
214 ascii_gz_size=`calcsize $outdir/$PACKAGE.txt.gz`
215 mv $PACKAGE.txt $outdir/
216
217 html_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
236 if 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}
260 else
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
273 fi
274
275 echo Making .tar.gz for sources...
276 d=`dirname $srcfile`
277 srcfiles=`ls $d/*.texinfo $d/*.texi $d/*.txi $d/*.eps 2>/dev/null` || true
278 tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
279 texi_tgz_size=`calcsize $outdir/$PACKAGE.texi.tar.gz`
280
281 if test -n "$docbook"; then
282 cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
283 echo "Generating docbook XML... ($cmd)"
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"
311 echo "Generating docbook PS... ($cmd)"
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/
322 fi
323
324 echo "Writing index file..."
325 if test -z "$use_texi2html"; then
326 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
327 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
328 else
329 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
330 fi
331 curdate=`$SETLANG date '+%B %d, %Y'`
332 sed \
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
360 echo "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: