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