Init shell var properly in git-version-gen.
[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-05-04.09
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 # For most of the following, the base name is just $PACKAGE
153 base=$PACKAGE
154
155 if test -n "$srcfile"; then
156 # but here, we use the basename of $srcfile
157 base=`basename "$srcfile"`
158 case $base in
159 *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;;
160 esac
161 PACKAGE=$base
162 elif test -s "$srcdir/$PACKAGE.texinfo"; then
163 srcfile=$srcdir/$PACKAGE.texinfo
164 elif test -s "$srcdir/$PACKAGE.texi"; then
165 srcfile=$srcdir/$PACKAGE.texi
166 elif test -s "$srcdir/$PACKAGE.txi"; then
167 srcfile=$srcdir/$PACKAGE.txi
168 else
169 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
170 exit 1
171 fi
172
173 if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
174 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
175 echo "$0: it is available from $templateurl." >&2
176 exit 1
177 fi
178
179 case $outdir in
180 /*) dotdot_outdir="$outdir";;
181 *) dotdot_outdir="../$outdir";;
182 esac
183
184 echo Generating output formats for $srcfile
185
186 cmd="$SETLANG $MAKEINFO -o $PACKAGE.info \"$srcfile\""
187 echo "Generating info files... ($cmd)"
188 eval "$cmd"
189 mkdir -p $outdir/
190 tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
191 info_tgz_size=`calcsize $outdir/$PACKAGE.info.tar.gz`
192 # do not mv the info files, there's no point in having them available
193 # separately on the web.
194
195 cmd="${TEXI2DVI} \"$srcfile\""
196 echo "Generating dvi ... ($cmd)"
197 eval "$cmd"
198
199 # now, before we compress dvi:
200 echo Generating postscript...
201 ${DVIPS} $PACKAGE -o
202 gzip -f -9 $PACKAGE.ps
203 ps_gz_size=`calcsize $PACKAGE.ps.gz`
204 mv $PACKAGE.ps.gz $outdir/
205
206 # compress/finish dvi:
207 gzip -f -9 $PACKAGE.dvi
208 dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
209 mv $PACKAGE.dvi.gz $outdir/
210
211 cmd="${TEXI2DVI} --pdf \"$srcfile\""
212 echo "Generating pdf ... ($cmd)"
213 eval "$cmd"
214 pdf_size=`calcsize $PACKAGE.pdf`
215 mv $PACKAGE.pdf $outdir/
216
217 cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
218 echo "Generating ASCII... ($cmd)"
219 eval "$cmd"
220 ascii_size=`calcsize $PACKAGE.txt`
221 gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
222 ascii_gz_size=`calcsize $outdir/$PACKAGE.txt.gz`
223 mv $PACKAGE.txt $outdir/
224
225 html_split()
226 {
227 opt="--split=$1 $htmlarg --node-files"
228 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
229 echo "Generating html by $1... ($cmd)"
230 eval "$cmd"
231 split_html_dir=$PACKAGE.html
232 (
233 cd ${split_html_dir} || exit 1
234 ln -sf ${PACKAGE}.html index.html
235 tar -czf $dotdot_outdir/${PACKAGE}.html_$1.tar.gz -- *.html
236 )
237 eval html_$1_tgz_size=`calcsize $outdir/${PACKAGE}.html_$1.tar.gz`
238 rm -f $outdir/html_$1/*.html
239 mkdir -p $outdir/html_$1/
240 mv ${split_html_dir}/*.html $outdir/html_$1/
241 rmdir ${split_html_dir}
242 }
243
244 if test -z "$use_texi2html"; then
245 opt="--no-split --html -o $PACKAGE.html $htmlarg"
246 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
247 echo "Generating monolithic html... ($cmd)"
248 rm -rf $PACKAGE.html # in case a directory is left over
249 eval "$cmd"
250 html_mono_size=`calcsize $PACKAGE.html`
251 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
252 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
253 mv $PACKAGE.html $outdir/
254
255 cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $htmlarg \"$srcfile\""
256 echo "Generating html by node... ($cmd)"
257 eval "$cmd"
258 split_html_dir=$PACKAGE.html
259 (
260 cd ${split_html_dir} || exit 1
261 tar -czf $dotdot_outdir/${PACKAGE}.html_node.tar.gz -- *.html
262 )
263 html_node_tgz_size=`calcsize $outdir/${PACKAGE}.html_node.tar.gz`
264 rm -f $outdir/html_node/*.html
265 mkdir -p $outdir/html_node/
266 mv ${split_html_dir}/*.html $outdir/html_node/
267 rmdir ${split_html_dir}
268 else
269 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $htmlarg \"$srcfile\""
270 echo "Generating monolithic html... ($cmd)"
271 rm -rf $PACKAGE.html # in case a directory is left over
272 eval "$cmd"
273 html_mono_size=`calcsize $PACKAGE.html`
274 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
275 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
276 mv $PACKAGE.html $outdir/
277
278 html_split node
279 html_split chapter
280 html_split section
281 fi
282
283 echo Making .tar.gz for sources...
284 d=`dirname $srcfile`
285 srcfiles=`ls $d/*.texinfo $d/*.texi $d/*.txi $d/*.eps 2>/dev/null` || true
286 tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
287 texi_tgz_size=`calcsize $outdir/$PACKAGE.texi.tar.gz`
288
289 if test -n "$docbook"; then
290 cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
291 echo "Generating docbook XML... ($cmd)"
292 eval "$cmd"
293 docbook_xml_size=`calcsize $PACKAGE-db.xml`
294 gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
295 docbook_xml_gz_size=`calcsize $outdir/$PACKAGE-db.xml.gz`
296 mv $PACKAGE-db.xml $outdir/
297
298 cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml"
299 echo "Generating docbook HTML... ($cmd)"
300 eval "$cmd"
301 split_html_db_dir=html_node_db
302 (
303 cd ${split_html_db_dir} || exit 1
304 tar -czf $dotdot_outdir/${PACKAGE}.html_node_db.tar.gz -- *.html
305 )
306 html_node_db_tgz_size=`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`
307 rm -f $outdir/html_node_db/*.html
308 mkdir -p $outdir/html_node_db
309 mv ${split_html_db_dir}/*.html $outdir/html_node_db/
310 rmdir ${split_html_db_dir}
311
312 cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml"
313 echo "Generating docbook ASCII... ($cmd)"
314 eval "$cmd"
315 docbook_ascii_size=`calcsize $PACKAGE-db.txt`
316 mv $PACKAGE-db.txt $outdir/
317
318 cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml"
319 echo "Generating docbook PS... ($cmd)"
320 eval "$cmd"
321 gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
322 docbook_ps_gz_size=`calcsize $outdir/$PACKAGE-db.ps.gz`
323 mv $PACKAGE-db.ps $outdir/
324
325 cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml"
326 echo "Generating docbook PDF... ($cmd)"
327 eval "$cmd"
328 docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
329 mv $PACKAGE-db.pdf $outdir/
330 fi
331
332 echo "Writing index file..."
333 if test -z "$use_texi2html"; then
334 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
335 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
336 else
337 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
338 fi
339 curdate=`$SETLANG date '+%B %d, %Y'`
340 sed \
341 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
342 -e "s!%%EMAIL%%!$EMAIL!g" \
343 -e "s!%%PACKAGE%%!$PACKAGE!g" \
344 -e "s!%%DATE%%!$curdate!g" \
345 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
346 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
347 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
348 -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
349 -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
350 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
351 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
352 -e "s!%%PDF_SIZE%%!$pdf_size!g" \
353 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
354 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
355 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
356 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
357 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
358 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
359 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
360 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
361 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
362 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
363 -e "s,%%SCRIPTURL%%,$scripturl,g" \
364 -e "s!%%SCRIPTNAME%%!$prog!g" \
365 -e "$CONDS" \
366 $GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
367
368 echo "Done, see $outdir/ subdirectory for new files."
369
370 # Local variables:
371 # eval: (add-hook 'write-file-hooks 'time-stamp)
372 # time-stamp-start: "scriptversion="
373 # time-stamp-format: "%:y-%02m-%02d.%02H"
374 # time-stamp-end: "$"
375 # End: