Add credits.
[libtasn1.git] / build-aux / gendocs.sh
blobaded2c4d7fe1f9dfc47502e2276c4b0b61f3fea2
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=2008-03-05.14
7 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
8 # Free Software Foundation, Inc.
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.
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.
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/>.
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/~checkout~/texinfo/texinfo/util/gendocs.sh"
30 templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template"
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
45 version="gendocs.sh $scriptversion
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."
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 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.
66 Simple example: $prog emacs \"GNU Emacs Manual\"
68 Typical sequence:
69 cd YOURPACKAGESOURCE/doc
70 wget \"$scripturl\"
71 wget \"$templateurl\"
72 $prog YOURMANUAL \"GNU YOURMANUAL - One-line description\"
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.
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.)
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.
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.)
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.)
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.
104 Email bug reports or enhancement requests to bug-texinfo@gnu.org.
107 calcsize()
109 size=`ls -ksl $1 | awk '{print $1}'`
110 echo $size
113 outdir=manual
114 html=
115 PACKAGE=
116 MANUAL_TITLE=
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;;
127 echo "$0: Unknown or ambiguous option \`$1'." >&2
128 echo "$0: Try \`--help' for more information." >&2
129 exit 1;;
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
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
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
160 case $outdir in
161 /*) dotdot_outdir="$outdir";;
162 *) dotdot_outdir="../$outdir";;
163 esac
165 echo Generating output formats for $srcfile
167 cmd="$SETLANG $MAKEINFO -o $PACKAGE.info \"$srcfile\""
168 echo "Generating info files... ($cmd)"
169 eval "$cmd"
170 mkdir -p $outdir/
171 tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
172 info_tgz_size=`calcsize $outdir/$PACKAGE.info.tar.gz`
173 # do not mv the info files, there's no point in having them available
174 # separately on the web.
176 cmd="${TEXI2DVI} \"$srcfile\""
177 echo "Generating dvi ... ($cmd)"
178 eval "$cmd"
180 # now, before we compress dvi:
181 echo Generating postscript...
182 ${DVIPS} $PACKAGE -o
183 gzip -f -9 $PACKAGE.ps
184 ps_gz_size=`calcsize $PACKAGE.ps.gz`
185 mv $PACKAGE.ps.gz $outdir/
187 # compress/finish dvi:
188 gzip -f -9 $PACKAGE.dvi
189 dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
190 mv $PACKAGE.dvi.gz $outdir/
192 cmd="${TEXI2DVI} --pdf \"$srcfile\""
193 echo "Generating pdf ... ($cmd)"
194 eval "$cmd"
195 pdf_size=`calcsize $PACKAGE.pdf`
196 mv $PACKAGE.pdf $outdir/
198 cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
199 echo "Generating ASCII... ($cmd)"
200 eval "$cmd"
201 ascii_size=`calcsize $PACKAGE.txt`
202 gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
203 ascii_gz_size=`calcsize $outdir/$PACKAGE.txt.gz`
204 mv $PACKAGE.txt $outdir/
206 html_split() {
207 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html --split=$1 $html --node-files \"$srcfile\""
208 echo "Generating html by $1... ($cmd)"
209 eval "$cmd"
210 split_html_dir=$PACKAGE.html
212 cd ${split_html_dir} || exit 1
213 ln -sf ${PACKAGE}.html index.html
214 tar -czf $dotdot_outdir/${PACKAGE}.html_$1.tar.gz -- *.html
216 eval html_$1_tgz_size=`calcsize $outdir/${PACKAGE}.html_$1.tar.gz`
217 rm -f $outdir/html_$1/*.html
218 mkdir -p $outdir/html_$1/
219 mv ${split_html_dir}/*.html $outdir/html_$1/
220 rmdir ${split_html_dir}
223 if test -z "$use_texi2html"; then
224 cmd="$SETLANG $MAKEINFO --no-split --html -o $PACKAGE.html $html \"$srcfile\""
225 echo "Generating monolithic html... ($cmd)"
226 rm -rf $PACKAGE.html # in case a directory is left over
227 eval "$cmd"
228 html_mono_size=`calcsize $PACKAGE.html`
229 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
230 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
231 mv $PACKAGE.html $outdir/
233 cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $html \"$srcfile\""
234 echo "Generating html by node... ($cmd)"
235 eval "$cmd"
236 split_html_dir=$PACKAGE.html
238 cd ${split_html_dir} || exit 1
239 tar -czf $dotdot_outdir/${PACKAGE}.html_node.tar.gz -- *.html
241 html_node_tgz_size=`calcsize $outdir/${PACKAGE}.html_node.tar.gz`
242 rm -f $outdir/html_node/*.html
243 mkdir -p $outdir/html_node/
244 mv ${split_html_dir}/*.html $outdir/html_node/
245 rmdir ${split_html_dir}
246 else
247 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $html \"$srcfile\""
248 echo "Generating monolithic html... ($cmd)"
249 rm -rf $PACKAGE.html # in case a directory is left over
250 eval "$cmd"
251 html_mono_size=`calcsize $PACKAGE.html`
252 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
253 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
254 mv $PACKAGE.html $outdir/
256 html_split node
257 html_split chapter
258 html_split section
261 echo Making .tar.gz for sources...
262 srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null`
263 tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
264 texi_tgz_size=`calcsize $outdir/$PACKAGE.texi.tar.gz`
266 if test -n "$docbook"; then
267 cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
268 echo "Generating docbook XML... $(cmd)"
269 eval "$cmd"
270 docbook_xml_size=`calcsize $PACKAGE-db.xml`
271 gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
272 docbook_xml_gz_size=`calcsize $outdir/$PACKAGE-db.xml.gz`
273 mv $PACKAGE-db.xml $outdir/
275 cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml"
276 echo "Generating docbook HTML... ($cmd)"
277 eval "$cmd"
278 split_html_db_dir=html_node_db
280 cd ${split_html_db_dir} || exit 1
281 tar -czf $dotdot_outdir/${PACKAGE}.html_node_db.tar.gz -- *.html
283 html_node_db_tgz_size=`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`
284 rm -f $outdir/html_node_db/*.html
285 mkdir -p $outdir/html_node_db
286 mv ${split_html_db_dir}/*.html $outdir/html_node_db/
287 rmdir ${split_html_db_dir}
289 cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml"
290 echo "Generating docbook ASCII... ($cmd)"
291 eval "$cmd"
292 docbook_ascii_size=`calcsize $PACKAGE-db.txt`
293 mv $PACKAGE-db.txt $outdir/
295 cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml"
296 echo "Generating docbook PS... $(cmd)"
297 eval "$cmd"
298 gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
299 docbook_ps_gz_size=`calcsize $outdir/$PACKAGE-db.ps.gz`
300 mv $PACKAGE-db.ps $outdir/
302 cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml"
303 echo "Generating docbook PDF... ($cmd)"
304 eval "$cmd"
305 docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
306 mv $PACKAGE-db.pdf $outdir/
309 echo Writing index file...
310 if test -z "$use_texi2html"; then
311 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
312 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
313 else
314 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
316 curdate=`$SETLANG date '+%B %d, %Y'`
317 sed \
318 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
319 -e "s!%%DATE%%!$curdate!g" \
320 -e "s!%%PACKAGE%%!$PACKAGE!g" \
321 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
322 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
323 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
324 -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
325 -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
326 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
327 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
328 -e "s!%%PDF_SIZE%%!$pdf_size!g" \
329 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
330 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
331 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
332 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
333 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
334 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
335 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
336 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
337 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
338 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
339 -e "s,%%SCRIPTURL%%,$scripturl,g" \
340 -e "s!%%SCRIPTNAME%%!$prog!g" \
341 -e "$CONDS" \
342 $GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
344 echo "Done! See $outdir/ subdirectory for new files."
346 # Local variables:
347 # eval: (add-hook 'write-file-hooks 'time-stamp)
348 # time-stamp-start: "scriptversion="
349 # time-stamp-format: "%:y-%02m-%02d.%02H"
350 # time-stamp-end: "$"
351 # End: