diff options
Diffstat (limited to 'doc/gendocs.sh')
-rwxr-xr-x | doc/gendocs.sh | 490 |
1 files changed, 490 insertions, 0 deletions
diff --git a/doc/gendocs.sh b/doc/gendocs.sh new file mode 100755 index 0000000..8ac3a06 --- /dev/null +++ b/doc/gendocs.sh | |||
@@ -0,0 +1,490 @@ | |||
1 | #!/bin/sh -e | ||
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 | |||
5 | scriptversion=2015-02-28.17 | ||
6 | |||
7 | # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 | ||
8 | # Free Software Foundation, Inc. | ||
9 | # | ||
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, or | ||
13 | # (at your option) any later version. | ||
14 | # | ||
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. | ||
19 | # | ||
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/>. | ||
22 | # | ||
23 | # Original author: Mohit Agarwal. | ||
24 | # Send bug reports and any other correspondence to bug-texinfo@gnu.org. | ||
25 | # | ||
26 | # The latest version of this script, and the companion template, is | ||
27 | # available from Texinfo CVS: | ||
28 | # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs.sh | ||
29 | # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template | ||
30 | # | ||
31 | # An up-to-date copy is also maintained in Gnulib (gnu.org/software/gnulib). | ||
32 | |||
33 | # TODO: | ||
34 | # - image importation was only implemented for HTML generated by | ||
35 | # makeinfo. But it should be simple enough to adjust. | ||
36 | # - images are not imported in the source tarball. All the needed | ||
37 | # formats (PDF, PNG, etc.) should be included. | ||
38 | |||
39 | prog=`basename "$0"` | ||
40 | srcdir=`pwd` | ||
41 | |||
42 | scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh" | ||
43 | templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template" | ||
44 | |||
45 | : ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="} | ||
46 | : ${MAKEINFO="makeinfo"} | ||
47 | : ${TEXI2DVI="texi2dvi -t @finalout"} | ||
48 | : ${DOCBOOK2HTML="docbook2html"} | ||
49 | : ${DOCBOOK2PDF="docbook2pdf"} | ||
50 | : ${DOCBOOK2TXT="docbook2txt"} | ||
51 | : ${GENDOCS_TEMPLATE_DIR="."} | ||
52 | : ${PERL='perl'} | ||
53 | : ${TEXI2HTML="texi2html"} | ||
54 | unset CDPATH | ||
55 | unset use_texi2html | ||
56 | |||
57 | version="gendocs.sh $scriptversion | ||
58 | |||
59 | Copyright 2013 Free Software Foundation, Inc. | ||
60 | There is NO warranty. You may redistribute this software | ||
61 | under the terms of the GNU General Public License. | ||
62 | For more information about these matters, see the files named COPYING." | ||
63 | |||
64 | usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE | ||
65 | |||
66 | Generate output in various formats from PACKAGE.texinfo (or .texi or | ||
67 | .txi) source. See the GNU Maintainers document for a more extensive | ||
68 | discussion: | ||
69 | http://www.gnu.org/prep/maintain_toc.html | ||
70 | |||
71 | Options: | ||
72 | --email ADR use ADR as contact in generated web pages; always give this. | ||
73 | |||
74 | -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi} | ||
75 | -o OUTDIR write files into OUTDIR, instead of manual/. | ||
76 | -I DIR append DIR to the Texinfo search path. | ||
77 | --common ARG pass ARG in all invocations. | ||
78 | --html ARG pass ARG to makeinfo or texi2html for HTML targets. | ||
79 | --info ARG pass ARG to makeinfo for Info, instead of --no-split. | ||
80 | --no-ascii skip generating the plain text output. | ||
81 | --no-copy-images | ||
82 | don't try to copy images referenced by img HTML tags, | ||
83 | --source ARG include ARG in tar archive of sources. | ||
84 | --split HOW make split HTML by node, section, chapter; default node. | ||
85 | |||
86 | --texi2html use texi2html to make HTML target, with all split versions. | ||
87 | --docbook convert through DocBook too (xml, txt, html, pdf). | ||
88 | |||
89 | --help display this help and exit successfully. | ||
90 | --version display version information and exit successfully. | ||
91 | |||
92 | Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\" | ||
93 | |||
94 | Typical sequence: | ||
95 | cd PACKAGESOURCE/doc | ||
96 | wget \"$scripturl\" | ||
97 | wget \"$templateurl\" | ||
98 | $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\" | ||
99 | |||
100 | Output will be in a new subdirectory \"manual\" (by default; | ||
101 | use -o OUTDIR to override). Move all the new files into your web CVS | ||
102 | tree, as explained in the Web Pages node of maintain.texi. | ||
103 | |||
104 | Please use the --email ADDRESS option so your own bug-reporting | ||
105 | address will be used in the generated HTML pages. | ||
106 | |||
107 | MANUAL-TITLE is included as part of the HTML <title> of the overall | ||
108 | manual/index.html file. It should include the name of the package being | ||
109 | documented. manual/index.html is created by substitution from the file | ||
110 | $GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the | ||
111 | generic template for your own purposes.) | ||
112 | |||
113 | If you have several manuals, you'll need to run this script several | ||
114 | times with different MANUAL values, specifying a different output | ||
115 | directory with -o each time. Then write (by hand) an overall index.html | ||
116 | with links to them all. | ||
117 | |||
118 | If a manual's Texinfo sources are spread across several directories, | ||
119 | first copy or symlink all Texinfo sources into a single directory. | ||
120 | (Part of the script's work is to make a tar.gz of the sources.) | ||
121 | |||
122 | As implied above, by default monolithic Info files are generated. | ||
123 | If you want split Info, or other Info options, use --info to override. | ||
124 | |||
125 | You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML, | ||
126 | and PERL to control the programs that get executed, and | ||
127 | GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is | ||
128 | looked for. With --docbook, the environment variables DOCBOOK2HTML, | ||
129 | DOCBOOK2PDF, and DOCBOOK2TXT are also consulted. | ||
130 | |||
131 | By default, makeinfo and texi2dvi are run in the default (English) | ||
132 | locale, since that's the language of most Texinfo manuals. If you | ||
133 | happen to have a non-English manual and non-English web site, see the | ||
134 | SETLANG setting in the source. | ||
135 | |||
136 | Email bug reports or enhancement requests to bug-texinfo@gnu.org. | ||
137 | " | ||
138 | |||
139 | MANUAL_TITLE= | ||
140 | PACKAGE= | ||
141 | EMAIL=webmasters@gnu.org # please override with --email | ||
142 | commonarg= # passed to all makeinfo/texi2html invcations. | ||
143 | dirargs= # passed to all tools (-I dir). | ||
144 | dirs= # -I's directories. | ||
145 | htmlarg= | ||
146 | infoarg=--no-split | ||
147 | generate_ascii=true | ||
148 | outdir=manual | ||
149 | source_extra= | ||
150 | split=default | ||
151 | srcfile= | ||
152 | no_copy_images= | ||
153 | |||
154 | while test $# -gt 0; do | ||
155 | case $1 in | ||
156 | -s) shift; srcfile=$1;; | ||
157 | -o) shift; outdir=$1;; | ||
158 | -I) shift; dirargs="$dirargs -I '$1'"; dirs="$dirs $1";; | ||
159 | --common) shift; commonarg=$1;; | ||
160 | --docbook) docbook=yes;; | ||
161 | --email) shift; EMAIL=$1;; | ||
162 | --html) shift; htmlarg=$1;; | ||
163 | --info) shift; infoarg=$1;; | ||
164 | --no-ascii) generate_ascii=false;; | ||
165 | --source) shift; source_extra=$1;; | ||
166 | --split) shift; split=$1;; | ||
167 | --texi2html) use_texi2html=1;; | ||
168 | --no-copy-images) no_copy_images=1;; | ||
169 | --help) echo "$usage"; exit 0;; | ||
170 | --version) echo "$version"; exit 0;; | ||
171 | -*) | ||
172 | echo "$0: Unknown option \`$1'." >&2 | ||
173 | echo "$0: Try \`--help' for more information." >&2 | ||
174 | exit 1;; | ||
175 | *) | ||
176 | if test -z "$PACKAGE"; then | ||
177 | PACKAGE=$1 | ||
178 | elif test -z "$MANUAL_TITLE"; then | ||
179 | MANUAL_TITLE=$1 | ||
180 | else | ||
181 | echo "$0: extra non-option argument \`$1'." >&2 | ||
182 | exit 1 | ||
183 | fi;; | ||
184 | esac | ||
185 | shift | ||
186 | done | ||
187 | |||
188 | # makeinfo uses the dirargs, but texi2dvi doesn't. | ||
189 | commonarg=" $dirargs $commonarg" | ||
190 | |||
191 | # For most of the following, the base name is just $PACKAGE | ||
192 | base=$PACKAGE | ||
193 | |||
194 | if test -n "$srcfile"; then | ||
195 | # but here, we use the basename of $srcfile | ||
196 | base=`basename "$srcfile"` | ||
197 | case $base in | ||
198 | *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;; | ||
199 | esac | ||
200 | PACKAGE=$base | ||
201 | elif test -s "$srcdir/$PACKAGE.texinfo"; then | ||
202 | srcfile=$srcdir/$PACKAGE.texinfo | ||
203 | elif test -s "$srcdir/$PACKAGE.texi"; then | ||
204 | srcfile=$srcdir/$PACKAGE.texi | ||
205 | elif test -s "$srcdir/$PACKAGE.txi"; then | ||
206 | srcfile=$srcdir/$PACKAGE.txi | ||
207 | else | ||
208 | echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2 | ||
209 | exit 1 | ||
210 | fi | ||
211 | |||
212 | if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then | ||
213 | echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2 | ||
214 | echo "$0: it is available from $templateurl." >&2 | ||
215 | exit 1 | ||
216 | fi | ||
217 | |||
218 | # Function to return size of $1 in something resembling kilobytes. | ||
219 | calcsize() | ||
220 | { | ||
221 | size=`ls -ksl $1 | awk '{print $1}'` | ||
222 | echo $size | ||
223 | } | ||
224 | |||
225 | # copy_images OUTDIR HTML-FILE... | ||
226 | # ------------------------------- | ||
227 | # Copy all the images needed by the HTML-FILEs into OUTDIR. Look | ||
228 | # for them in the -I directories. | ||
229 | copy_images() | ||
230 | { | ||
231 | test -n "$no_copy_images" && return | ||
232 | local odir | ||
233 | odir=$1 | ||
234 | shift | ||
235 | $PERL -n -e " | ||
236 | BEGIN { | ||
237 | \$me = '$prog'; | ||
238 | \$odir = '$odir'; | ||
239 | @dirs = qw($dirs); | ||
240 | } | ||
241 | " -e ' | ||