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