Mention TLD.
[libidn.git] / doc / gendocs.sh
blob552d7f67b687d5acf17208ff30193d9b589aba86
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$
5 #
6 # Copyright (C) 2003, 2004 Free Software Foundation, Inc.
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.
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.
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.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
23 # Original author: Mohit Agarwal.
24 # Send bug reports and any other correspondence to bug-texinfo@gnu.org.
26 prog="`basename \"$0\"`"
27 srcdir=`pwd`
29 scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs.sh"
30 templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template"
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
42 rcs_revision='$Revision$'
43 rcs_version=`set - $rcs_revision; echo $2`
44 program=`echo $0 | sed -e 's!.*/!!'`
45 version="gendocs.sh $rcs_version
47 Copyright (C) 2003 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."
52 usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
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
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.
65 Simple example: $prog emacs \"GNU Emacs Manual\"
67 Typical sequence:
68 cd YOURPACKAGESOURCE/doc
69 wget \"$scripturl\"
70 wget \"$templateurl\"
71 $prog YOURMANUAL \"GNU YOURMANUAL - One-line description\"
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.
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.)
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.
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.
92 Email bug reports or enhancement requests to bug-texinfo@gnu.org.
95 calcsize()
97 size="`ls -ksl $1 | awk '{print $1}'`"
98 echo $size
101 outdir=manual
102 html=
103 PACKAGE=
104 MANUAL_TITLE=
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;;
114 echo "$0: Unknown or ambiguous option \`$1'." >&2
115 echo "$0: Try \`--help' for more information." >&2
116 exit 1;;
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
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
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
147 echo Generating output formats for $srcfile
149 echo Generating info files...
150 ${MAKEINFO} -o $PACKAGE.info $srcfile
151 mkdir -p $outdir/
152 tar czf $outdir/$PACKAGE-info.tar.gz $PACKAGE.info*
153 info_tgz_size="`calcsize $outdir/$PACKAGE-info.tar.gz`"
154 # do not mv the info files, there's no point in having them available
155 # separately on the web.
157 echo Generating dvi ...
158 ${TEXI2DVI} $srcfile
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/
167 # compress/finish dvi:
168 gzip -f -9 $PACKAGE.dvi
169 dvi_gz_size="`calcsize $PACKAGE.dvi.gz`"
170 mv $PACKAGE.dvi.gz $outdir/
172 echo Generating pdf ...
173 ${TEXI2DVI} --pdf $srcfile
174 pdf_size="`calcsize $PACKAGE.pdf`"
175 mv $PACKAGE.pdf $outdir/
177 echo Generating ASCII...
178 ${MAKEINFO} -o - --no-split --no-headers $srcfile > ${srcdir}/$PACKAGE.txt
179 ascii_size="`calcsize $PACKAGE.txt`"
180 gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
181 ascii_gz_size="`calcsize $outdir/$PACKAGE.txt.gz`"
182 mv $PACKAGE.txt $outdir/
184 echo Generating monolithic html...
185 rm -rf $PACKAGE.html # in case a directory is left over
186 ${MAKEINFO} --no-split --html $html $srcfile
187 html_mono_size="`calcsize $PACKAGE.html`"
188 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
189 html_mono_gz_size="`calcsize $outdir/$PACKAGE.html.gz`"
190 mv $PACKAGE.html $outdir/
192 echo Generating html by node...
193 ${MAKEINFO} --html $html $srcfile
194 if test -d $PACKAGE; then
195 split_html_dir=$PACKAGE
196 elif test -d $PACKAGE.html; then
197 split_html_dir=$PACKAGE.html
198 else
199 echo "$0: can't find split html dir for $srcfile." >&2
202 cd ${split_html_dir} || exit 1
203 tar -czf ../$outdir/${PACKAGE}_html_node.tar.gz -- *.html
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}
211 echo Making .tar.gz for sources...
212 srcfiles=`ls *.texinfo *.texi *.txi 2>/dev/null`
213 tar czfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
214 texi_tgz_size="`calcsize $outdir/$PACKAGE.texi.tar.gz`"
216 if test -n "$docbook"; then
217 echo Generating docbook XML...
218 ${MAKEINFO} -o - --docbook $srcfile > ${srcdir}/$PACKAGE-db.xml
219 docbook_xml_size="`calcsize $PACKAGE-db.xml`"
220 gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
221 docbook_xml_gz_size="`calcsize $outdir/$PACKAGE-db.xml.gz`"
222 mv $PACKAGE-db.xml $outdir/
224 echo Generating docbook HTML...
225 split_html_db_dir=html_node_db
226 ${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml
228 cd ${split_html_db_dir} || exit 1
229 tar -czf ../$outdir/${PACKAGE}_html_node_db.tar.gz -- *.html
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}
237 echo Generating docbook ASCII...
238 ${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml
239 docbook_ascii_size="`calcsize $PACKAGE-db.txt`"
240 mv $PACKAGE-db.txt $outdir/
242 echo Generating docbook PS...
243 ${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml
244 gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
245 docbook_ps_gz_size="`calcsize $outdir/$PACKAGE-db.ps.gz`"
246 mv $PACKAGE-db.ps $outdir/
248 echo Generating docbook PDF...
249 ${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml
250 docbook_pdf_size="`calcsize $PACKAGE-db.pdf`"
251 mv $PACKAGE-db.pdf $outdir/
254 echo Writing index file...
255 curdate="`date '+%B %d, %Y'`"
256 sed \
257 -e "s/%%TITLE%%/$MANUAL_TITLE/g" \
258 -e "s/%%DATE%%/$curdate/g" \
259 -e "s/%%PACKAGE%%/$PACKAGE/g" \
260 -e "s/%%HTML_MONO_SIZE%%/$html_mono_size/g" \
261 -e "s/%%HTML_MONO_GZ_SIZE%%/$html_mono_gz_size/g" \
262 -e "s/%%HTML_NODE_TGZ_SIZE%%/$html_node_tgz_size/g" \
263 -e "s/%%INFO_TGZ_SIZE%%/$info_tgz_size/g" \
264 -e "s/%%DVI_GZ_SIZE%%/$dvi_gz_size/g" \
265 -e "s/%%PDF_SIZE%%/$pdf_size/g" \
266 -e "s/%%PS_GZ_SIZE%%/$ps_gz_size/g" \
267 -e "s/%%ASCII_SIZE%%/$ascii_size/g" \
268 -e "s/%%ASCII_GZ_SIZE%%/$ascii_gz_size/g" \
269 -e "s/%%TEXI_TGZ_SIZE%%/$texi_tgz_size/g" \
270 -e "s/%%DOCBOOK_HTML_NODE_TGZ_SIZE%%/$html_node_db_tgz_size/g" \
271 -e "s/%%DOCBOOK_ASCII_SIZE%%/$docbook_ascii_size/g" \
272 -e "s/%%DOCBOOK_PS_GZ_SIZE%%/$docbook_ps_gz_size/g" \
273 -e "s/%%DOCBOOK_PDF_SIZE%%/$docbook_pdf_size/g" \
274 -e "s/%%DOCBOOK_XML_SIZE%%/$docbook_xml_size/g" \
275 -e "s/%%DOCBOOK_XML_GZ_SIZE%%/$docbook_xml_gz_size/g" \
276 -e "s,%%SCRIPTURL%%,$scripturl,g" \
277 -e "s/%%SCRIPTNAME%%/$prog/g" \
278 $GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
280 echo "Done! See $outdir/ subdirectory for new files."