autoupdate
[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=2006-07-15.08
6
7 # Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, you can either send email to this
21 # program's maintainer or write to: The Free Software Foundation,
22 # Inc.; 51 Franklin Street, Fifth Floor; Boston, MA 02110-1301, USA.
23 #
24 # Original author: Mohit Agarwal.
25 # Send bug reports and any other correspondence to bug-texinfo@gnu.org.
26
27 prog=`basename "$0"`
28 srcdir=`pwd`
29
30 scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh"
31 templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template"
32
33 : ${MAKEINFO="makeinfo"}
34 : ${TEXI2DVI="texi2dvi -t @finalout"}
35 : ${DVIPS="dvips"}
36 : ${DOCBOOK2TXT="docbook2txt"}
37 : ${DOCBOOK2HTML="docbook2html"}
38 : ${DOCBOOK2PDF="docbook2pdf"}
39 : ${DOCBOOK2PS="docbook2ps"}
40 : ${GENDOCS_TEMPLATE_DIR="."}
41 unset CDPATH
42
43 version="gendocs.sh $scriptversion
44
45 Copyright (C) 2006 Free Software Foundation, Inc.
46 There is NO warranty.  You may redistribute this software
47 under the terms of the GNU General Public License.
48 For more information about these matters, see the files named COPYING."
49
50 usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
51
52 Generate various output formats from PACKAGE.texinfo (or .texi or .txi) source.
53 See the GNU Maintainers document for a more extensive discussion:
54   http://www.gnu.org/prep/maintain_toc.html
55
56 Options:
57   -o OUTDIR   write files into OUTDIR, instead of manual/.
58   --docbook   convert to DocBook too (xml, txt, html, pdf and ps).
59   --html ARG  pass indicated ARG to makeinfo for HTML targets.
60   --help      display this help and exit successfully.
61   --version   display version information and exit successfully.
62
63 Simple example: $prog emacs \"GNU Emacs Manual\"
64
65 Typical sequence:
66   cd YOURPACKAGESOURCE/doc
67   wget \"$scripturl\"
68   wget \"$templateurl\"
69   $prog YOURMANUAL \"GNU YOURMANUAL - One-line description\"
70
71 Output will be in a new subdirectory \"manual\" (by default, use -o OUTDIR
72 to override).  Move all the new files into your web CVS tree, as
73 explained in the Web Pages node of maintain.texi.
74
75 MANUAL-TITLE is included as part of the HTML <title> of the overall
76 manual/index.html file.  It should include the name of the package being
77 documented.  manual/index.html is created by substitution from the file
78 $GENDOCS_TEMPLATE_DIR/gendocs_template.  (Feel free to modify the
79 generic template for your own purposes.)
80
81 If you have several manuals, you'll need to run this script several
82 times with different YOURMANUAL values, specifying a different output
83 directory with -o each time.  Then write (by hand) an overall index.html
84 with links to them all.
85
86 You can set the environment variables MAKEINFO, TEXI2DVI, and DVIPS to
87 control the programs that get executed, and GENDOCS_TEMPLATE_DIR to
88 control where the gendocs_template file is looked for.
89
90 Email bug reports or enhancement requests to bug-texinfo@gnu.org.
91 "
92
93 calcsize()
94 {
95   size=`ls -ksl $1 | awk '{print $1}'`
96   echo $size
97 }
98
99 outdir=manual
100 html=
101 PACKAGE=
102 MANUAL_TITLE=
103
104 while test $# -gt 0; do
105   case $1 in
106     --help) echo "$usage"; exit 0;;
107     --version) echo "$version"; exit 0;;
108     -o) shift; outdir=$1;;
109     --docbook) docbook=yes;;
110     --html) shift; html=$1;;
111     -*)
112       echo "$0: Unknown or ambiguous option \`$1'." >&2
113       echo "$0: Try \`--help' for more information." >&2
114       exit 1;;
115     *)
116       if test -z "$PACKAGE"; then
117         PACKAGE=$1
118       elif test -z "$MANUAL_TITLE"; then
119         MANUAL_TITLE=$1
120       else
121         echo "$0: extra non-option argument \`$1'." >&2
122         exit 1
123       fi;;
124   esac
125   shift
126 done
127
128 if test -s "$srcdir/$PACKAGE.texinfo"; then
129   srcfile=$srcdir/$PACKAGE.texinfo
130 elif test -s "$srcdir/$PACKAGE.texi"; then
131   srcfile=$srcdir/$PACKAGE.texi
132 elif test -s "$srcdir/$PACKAGE.txi"; then
133   srcfile=$srcdir/$PACKAGE.txi
134 else
135   echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
136   exit 1
137 fi
138
139 if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
140   echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
141   echo "$0: it is available from $templateurl." >&2
142   exit 1
143 fi
144
145 echo Generating output formats for $srcfile
146
147 cmd="${MAKEINFO} -o $PACKAGE.info \"$srcfile\""
148 echo "Generating info files... ($cmd)"
149 eval "$cmd"
150 mkdir -p $outdir/
151 tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
152 info_tgz_size=`calcsize $outdir/$PACKAGE.info.tar.gz`
153 # do not mv the info files, there's no point in having them available
154 # separately on the web.
155
156 cmd="${TEXI2DVI} \"$srcfile\""
157 echo "Generating dvi ... ($cmd)"
158 eval "$cmd"
159
160 # now, before we compress dvi:
161 echo Generating postscript...
162 ${DVIPS} $PACKAGE -o
163 gzip -f -9 $PACKAGE.ps
164 ps_gz_size=`calcsize $PACKAGE.ps.gz`
165 mv $PACKAGE.ps.gz $outdir/
166
167 # compress/finish dvi:
168 gzip -f -9 $PACKAGE.dvi
169 dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
170 mv $PACKAGE.dvi.gz $outdir/
171
172 cmd="${TEXI2DVI} --pdf \"$srcfile\""
173 echo "Generating pdf ... ($cmd)"
174 eval "$cmd"
175 pdf_size=`calcsize $PACKAGE.pdf`
176 mv $PACKAGE.pdf $outdir/
177
178 cmd="${MAKEINFO} -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
179 echo "Generating ASCII... ($cmd)"
180 eval "$cmd"
181 ascii_size=`calcsize $PACKAGE.txt`
182 gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
183 ascii_gz_size=`calcsize $outdir/$PACKAGE.txt.gz`
184 mv $PACKAGE.txt $outdir/
185
186 cmd="${MAKEINFO} --no-split --html -o $PACKAGE.html $html \"$srcfile\""
187 echo "Generating monolithic html... ($cmd)"
188 rm -rf $PACKAGE.html  # in case a directory is left over
189 eval "$cmd"
190 html_mono_size=`calcsize $PACKAGE.html`
191 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
192 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
193 mv $PACKAGE.html $outdir/
194
195 cmd="${MAKEINFO} --html -o $PACKAGE.html $html \"$srcfile\""
196 echo "Generating html by node... ($cmd)"
197 eval "$cmd"
198 split_html_dir=$PACKAGE.html
199 (
200   cd ${split_html_dir} || exit 1
201   tar -czf ../$outdir/${PACKAGE}.html_node.tar.gz -- *.html
202 )
203 html_node_tgz_size=`calcsize $outdir/${PACKAGE}.html_node.tar.gz`
204 rm -f $outdir/html_node/*.html
205 mkdir -p $outdir/html_node/
206 mv ${split_html_dir}/*.html $outdir/html_node/
207 rmdir ${split_html_dir}
208
209 echo Making .tar.gz for sources...
210 srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null`
211 tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
212 texi_tgz_size=`calcsize $outdir/$PACKAGE.texi.tar.gz`
213
214 if test -n "$docbook"; then
215   cmd="${MAKEINFO} -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
216   echo "Generating docbook XML... $(cmd)"
217   eval "$cmd"
218   docbook_xml_size=`calcsize $PACKAGE-db.xml`
219   gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
220   docbook_xml_gz_size=`calcsize $outdir/$PACKAGE-db.xml.gz`
221   mv $PACKAGE-db.xml $outdir/
222
223   cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml"
224   echo "Generating docbook HTML... ($cmd)"
225   eval "$cmd"
226   split_html_db_dir=html_node_db
227   (
228     cd ${split_html_db_dir} || exit 1
229     tar -czf ../$outdir/${PACKAGE}.html_node_db.tar.gz -- *.html
230   )
231   html_node_db_tgz_size=`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`
232   rm -f $outdir/html_node_db/*.html
233   mkdir -p $outdir/html_node_db
234   mv ${split_html_db_dir}/*.html $outdir/html_node_db/
235   rmdir ${split_html_db_dir}
236
237   cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml"
238   echo "Generating docbook ASCII... ($cmd)"
239   eval "$cmd"
240   docbook_ascii_size=`calcsize $PACKAGE-db.txt`
241   mv $PACKAGE-db.txt $outdir/
242
243   cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml"
244   echo "Generating docbook PS... $(cmd)"
245   eval "$cmd"
246   gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
247   docbook_ps_gz_size=`calcsize $outdir/$PACKAGE-db.ps.gz`
248   mv $PACKAGE-db.ps $outdir/
249
250   cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml"
251   echo "Generating docbook PDF... ($cmd)"
252   eval "$cmd"
253   docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
254   mv $PACKAGE-db.pdf $outdir/
255 fi
256
257 echo Writing index file...
258 curdate=`date '+%B %d, %Y'`
259 sed \
260    -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
261    -e "s!%%DATE%%!$curdate!g" \
262    -e "s!%%PACKAGE%%!$PACKAGE!g" \
263    -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
264    -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
265    -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
266    -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
267    -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
268    -e "s!%%PDF_SIZE%%!$pdf_size!g" \
269    -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
270    -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
271    -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
272    -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
273    -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
274    -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
275    -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
276    -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
277    -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
278    -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
279    -e "s,%%SCRIPTURL%%,$scripturl,g" \
280    -e "s!%%SCRIPTNAME%%!$prog!g" \
281 $GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
282
283 echo "Done!  See $outdir/ subdirectory for new files."
284
285 # Local variables:
286 # eval: (add-hook 'write-file-hooks 'time-stamp)
287 # time-stamp-start: "scriptversion="
288 # time-stamp-format: "%:y-%02m-%02d.%02H"
289 # time-stamp-end: "$"
290 # End: