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