Merge defines.h into int.h.
[libtasn1.git] / build-aux / gendocs.sh
blob480c1d481a6077492c53e018e7bb2274a9b3f4b3
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-01-13.10
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
126 html="$html --node-files";;
128 echo "$0: Unknown or ambiguous option \`$1'." >&2
129 echo "$0: Try \`--help' for more information." >&2
130 exit 1;;
132 if test -z "$PACKAGE"; then
133 PACKAGE=$1
134 elif test -z "$MANUAL_TITLE"; then
135 MANUAL_TITLE=$1
136 else
137 echo "$0: extra non-option argument \`$1'." >&2
138 exit 1
139 fi;;
140 esac
141 shift
142 done
144 if test -s "$srcdir/$PACKAGE.texinfo"; then
145 srcfile=$srcdir/$PACKAGE.texinfo
146 elif test -s "$srcdir/$PACKAGE.texi"; then
147 srcfile=$srcdir/$PACKAGE.texi
148 elif test -s "$srcdir/$PACKAGE.txi"; then
149 srcfile=$srcdir/$PACKAGE.txi
150 else
151 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
152 exit 1
155 if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
156 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
157 echo "$0: it is available from $templateurl." >&2
158 exit 1
161 echo Generating output formats for $srcfile
163 cmd="$SETLANG $MAKEINFO -o $PACKAGE.info \"$srcfile\""
164 echo "Generating info files... ($cmd)"
165 eval "$cmd"
166 mkdir -p $outdir/
167 tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
168 info_tgz_size=`calcsize $outdir/$PACKAGE.info.tar.gz`
169 # do not mv the info files, there's no point in having them available
170 # separately on the web.
172 cmd="${TEXI2DVI} \"$srcfile\""
173 echo "Generating dvi ... ($cmd)"
174 eval "$cmd"
176 # now, before we compress dvi:
177 echo Generating postscript...
178 ${DVIPS} $PACKAGE -o
179 gzip -f -9 $PACKAGE.ps
180 ps_gz_size=`calcsize $PACKAGE.ps.gz`
181 mv $PACKAGE.ps.gz $outdir/
183 # compress/finish dvi:
184 gzip -f -9 $PACKAGE.dvi
185 dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
186 mv $PACKAGE.dvi.gz $outdir/
188 cmd="${TEXI2DVI} --pdf \"$srcfile\""
189 echo "Generating pdf ... ($cmd)"
190 eval "$cmd"
191 pdf_size=`calcsize $PACKAGE.pdf`
192 mv $PACKAGE.pdf $outdir/
194 cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
195 echo "Generating ASCII... ($cmd)"
196 eval "$cmd"
197 ascii_size=`calcsize $PACKAGE.txt`
198 gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
199 ascii_gz_size=`calcsize $outdir/$PACKAGE.txt.gz`
200 mv $PACKAGE.txt $outdir/
202 html_split() {
203 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html --split=$1 $html \"$srcfile\""
204 echo "Generating html by $1... ($cmd)"
205 eval "$cmd"
206 split_html_dir=$PACKAGE.html
208 cd ${split_html_dir} || exit 1
209 ln -sf ${PACKAGE}.html index.html
210 tar -czf ../$outdir/${PACKAGE}.html_$1.tar.gz -- *.html
212 eval html_$1_tgz_size=`calcsize $outdir/${PACKAGE}.html_$1.tar.gz`
213 rm -f $outdir/html_$1/*.html
214 mkdir -p $outdir/html_$1/
215 mv ${split_html_dir}/*.html $outdir/html_$1/
216 rmdir ${split_html_dir}
219 if test -z "$use_texi2html"; then
220 cmd="$SETLANG $MAKEINFO --no-split --html -o $PACKAGE.html $html \"$srcfile\""
221 echo "Generating monolithic html... ($cmd)"
222 rm -rf $PACKAGE.html # in case a directory is left over
223 eval "$cmd"
224 html_mono_size=`calcsize $PACKAGE.html`
225 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
226 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
227 mv $PACKAGE.html $outdir/
229 cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $html \"$srcfile\""
230 echo "Generating html by node... ($cmd)"
231 eval "$cmd"
232 split_html_dir=$PACKAGE.html
234 cd ${split_html_dir} || exit 1
235 tar -czf ../$outdir/${PACKAGE}.html_node.tar.gz -- *.html
237 html_node_tgz_size=`calcsize $outdir/${PACKAGE}.html_node.tar.gz`
238 rm -f $outdir/html_node/*.html
239 mkdir -p $outdir/html_node/
240 mv ${split_html_dir}/*.html $outdir/html_node/
241 rmdir ${split_html_dir}
242 else
243 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $html \"$srcfile\""
244 echo "Generating monolithic html... ($cmd)"
245 rm -rf $PACKAGE.html # in case a directory is left over
246 eval "$cmd"
247 html_mono_size=`calcsize $PACKAGE.html`
248 gzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
249 html_mono_gz_size=`calcsize $outdir/$PACKAGE.html.gz`
250 mv $PACKAGE.html $outdir/
252 html_split node
253 html_split chapter
254 html_split section
257 echo Making .tar.gz for sources...
258 srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null`
259 tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
260 texi_tgz_size=`calcsize $outdir/$PACKAGE.texi.tar.gz`
262 if test -n "$docbook"; then
263 cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
264 echo "Generating docbook XML... $(cmd)"
265 eval "$cmd"
266 docbook_xml_size=`calcsize $PACKAGE-db.xml`
267 gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
268 docbook_xml_gz_size=`calcsize $outdir/$PACKAGE-db.xml.gz`
269 mv $PACKAGE-db.xml $outdir/
271 cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml"
272 echo "Generating docbook HTML... ($cmd)"
273 eval "$cmd"
274 split_html_db_dir=html_node_db
276 cd ${split_html_db_dir} || exit 1
277 tar -czf ../$outdir/${PACKAGE}.html_node_db.tar.gz -- *.html
279 html_node_db_tgz_size=`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`
280 rm -f $outdir/html_node_db/*.html
281 mkdir -p $outdir/html_node_db
282 mv ${split_html_db_dir}/*.html $outdir/html_node_db/
283 rmdir ${split_html_db_dir}
285 cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml"
286 echo "Generating docbook ASCII... ($cmd)"
287 eval "$cmd"
288 docbook_ascii_size=`calcsize $PACKAGE-db.txt`
289 mv $PACKAGE-db.txt $outdir/
291 cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml"
292 echo "Generating docbook PS... $(cmd)"
293 eval "$cmd"
294 gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
295 docbook_ps_gz_size=`calcsize $outdir/$PACKAGE-db.ps.gz`
296 mv $PACKAGE-db.ps $outdir/
298 cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml"
299 echo "Generating docbook PDF... ($cmd)"
300 eval "$cmd"
301 docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
302 mv $PACKAGE-db.pdf $outdir/
305 echo Writing index file...
306 if test -z "$use_texi2html"; then
307 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
308 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
309 else
310 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
312 curdate=`$SETLANG date '+%B %d, %Y'`
313 sed \
314 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
315 -e "s!%%DATE%%!$curdate!g" \
316 -e "s!%%PACKAGE%%!$PACKAGE!g" \
317 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
318 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
319 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
320 -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
321 -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
322 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
323 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
324 -e "s!%%PDF_SIZE%%!$pdf_size!g" \
325 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
326 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
327 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
328 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
329 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
330 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
331 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
332 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
333 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
334 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
335 -e "s,%%SCRIPTURL%%,$scripturl,g" \
336 -e "s!%%SCRIPTNAME%%!$prog!g" \
337 -e "$CONDS" \
338 $GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
340 echo "Done! See $outdir/ subdirectory for new files."
342 # Local variables:
343 # eval: (add-hook 'write-file-hooks 'time-stamp)
344 # time-stamp-start: "scriptversion="
345 # time-stamp-format: "%:y-%02m-%02d.%02H"
346 # time-stamp-end: "$"
347 # End: