aboutsummaryrefslogtreecommitdiff
path: root/doc/handbook/gendocs.sh
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-08-02 17:25:41 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2022-08-02 17:25:41 +0200
commit4fe567d9d94b9159254a2f2cce64855a794d9699 (patch)
treeb286f5a454472ec92ff88376b297e411e64c5843 /doc/handbook/gendocs.sh
parente8b7707f833739851227d4865e6c6064865f19ec (diff)
downloadgnunet-4fe567d9d94b9159254a2f2cce64855a794d9699.tar.gz
gnunet-4fe567d9d94b9159254a2f2cce64855a794d9699.zip
DOC: Move from texinfo to sphinx
Diffstat (limited to 'doc/handbook/gendocs.sh')
-rwxr-xr-xdoc/handbook/gendocs.sh506
1 files changed, 0 insertions, 506 deletions
diff --git a/doc/handbook/gendocs.sh b/doc/handbook/gendocs.sh
deleted file mode 100755
index 79c92c9ad..000000000
--- a/doc/handbook/gendocs.sh
+++ /dev/null
@@ -1,506 +0,0 @@
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
5scriptversion=2016-12-31.18
6
7# Copyright 2003-2017 Free Software Foundation, Inc.
8#
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, or
12# (at your option) any later version.
13#
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.
18#
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/>.
21#
22# SPDX-License-Identifier: GPL3.0-or-later
23#
24# Original author: Mohit Agarwal.
25# Send bug reports and any other correspondence to bug-gnulib@gnu.org.
26#
27# The latest version of this script, and the companion template, is
28# available from the Gnulib repository:
29#
30# http://git.savannah.gnu.org/cgit/gnulib.git/tree/build-aux/gendocs.sh
31# http://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/gendocs_template
32
33# TODO:
34# - image importing 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
39prog=`basename "$0"`
40srcdir=`pwd`
41
42scripturl="http://git.savannah.gnu.org/cgit/gnulib.git/plain/build-aux/gendocs.sh"
43templateurl="http://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/gendocs_template"
44
45: ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="}
46: ${MAKEINFO="makeinfo"}
47: ${TEXI2DVI="texi2dvi"}
48: ${DOCBOOK2HTML="docbook2html"}
49: ${DOCBOOK2PDF="docbook2pdf"}
50: ${DOCBOOK2TXT="docbook2txt"}
51: ${GENDOCS_TEMPLATE_DIR="."}
52: ${PERL='perl'}
53: ${TEXI2HTML="texi2html"}
54unset CDPATH
55unset use_texi2html
56
57MANUAL_TITLE=
58PACKAGE=
59EMAIL=webmasters@gnu.org # please override with --email
60commonarg= # passed to all makeinfo/texi2html invcations.
61dirargs= # passed to all tools (-I dir).
62dirs= # -I directories.
63htmlarg="--css-ref=/software/gnulib/manual.css -c TOP_NODE_UP_URL=/manual"
64infoarg=--no-split
65generate_ascii=true
66generate_html=true
67generate_info=true
68generate_tex=true
69outdir=manual
70source_extra=
71split=node
72srcfile=
73texarg="-t @finalout"
74
75version="gendocs.sh $scriptversion
76
77Copyright 2017 Free Software Foundation, Inc.
78There is NO warranty. You may redistribute this software
79under the terms of the GNU General Public License.
80For more information about these matters, see the files named COPYING."
81
82usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
83
84Generate output in various formats from PACKAGE.texinfo (or .texi or
85.txi) source. See the GNU Maintainers document for a more extensive
86discussion:
87 http://www.gnu.org/prep/maintain_toc.html
88
89Options:
90 --email ADR use ADR as contact in generated web pages; always give this.
91
92 -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi}
93 -o OUTDIR write files into OUTDIR, instead of manual/.
94 -I DIR append DIR to the Texinfo search path.
95 --common ARG pass ARG in all invocations.
96 --html ARG pass ARG to makeinfo or texi2html for HTML targets,
97 instead of '$htmlarg'.
98 --info ARG pass ARG to makeinfo for Info, instead of --no-split.
99 --no-ascii skip generating the plain text output.
100 --no-html skip generating the html output.
101 --no-info skip generating the info output.
102 --no-tex skip generating the dvi and pdf output.
103 --source ARG include ARG in tar archive of sources.
104 --split HOW make split HTML by node, section, chapter; default node.
105 --tex ARG pass ARG to texi2dvi for DVI and PDF, instead of -t @finalout.
106
107 --texi2html use texi2html to make HTML target, with all split versions.
108 --docbook convert through DocBook too (xml, txt, html, pdf).
109
110 --help display this help and exit successfully.
111 --version display version information and exit successfully.
112
113Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
114
115Typical sequence:
116 cd PACKAGESOURCE/doc
117 wget \"$scripturl\"
118 wget \"$templateurl\"
119 $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
120
121Output will be in a new subdirectory \"manual\" (by default;
122use -o OUTDIR to override). Move all the new files into your web CVS
123tree, as explained in the Web Pages node of maintain.texi.
124
125Please use the --email ADDRESS option so your own bug-reporting
126address will be used in the generated HTML pages.
127
128MANUAL-TITLE is included as part of the HTML <title> of the overall
129manual/index.html file. It should include the name of the package being
130documented. manual/index.html is created by substitution from the file
131$GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
132generic template for your own purposes.)
133
134If you have several manuals, you'll need to run this script several
135times with different MANUAL values, specifying a different output
136directory with -o each time. Then write (by hand) an overall index.html
137with links to them all.
138
139If a manual's Texinfo sources are spread across several directories,
140first copy or symlink all Texinfo sources into a single directory.
141(Part of the script's work is to make a tar.gz of the sources.)
142
143As implied above, by default monolithic Info files are generated.
144If you want split Info, or other Info options, use --info to override.
145
146You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML,
147and PERL to control the programs that get executed, and
148GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is
149looked for. With --docbook, the environment variables DOCBOOK2HTML,
150DOCBOOK2PDF, and DOCBOOK2TXT are also consulted.
151
152By default, makeinfo and texi2dvi are run in the default (English)
153locale, since that's the language of most Texinfo manuals. If you
154happen to have a non-English manual and non-English web site, see the
155SETLANG setting in the source.
156
157Email bug reports or enhancement requests to bug-gnulib@gnu.org.
158"
159
160while test $# -gt 0; do
161 case $1 in
162 -s) shift; srcfile=$1;;
163 -o) shift; outdir=$1;;
164 -I) shift; dirargs="$dirargs -I '$1'"; dirs="$dirs $1";;
165 --common) shift; commonarg=$1;;
166 --docbook) docbook=yes;;
167 --email) shift; EMAIL=$1;;
168 --html) shift; htmlarg=$1;;
169 --info) shift; infoarg=$1;;
170 --no-ascii) generate_ascii=false;;
171 --no-html) generate_ascii=false;;
172 --no-info) generate_info=false;;
173 --no-tex) generate_tex=false;;
174 --source) shift; source_extra=$1;;
175 --split) shift; split=$1;;
176 --tex) shift; texarg=$1;;
177 --texi2html) use_texi2html=1;;
178
179 --help) echo "$usage"; exit 0;;
180 --version) echo "$version"; exit 0;;
181 -*)
182 echo "$0: Unknown option \`$1'." >&2
183 echo "$0: Try \`--help' for more information." >&2
184 exit 1;;
185 *)
186 if test -z "$PACKAGE"; then
187 PACKAGE=$1
188 elif test -z "$MANUAL_TITLE"; then
189 MANUAL_TITLE=$1
190 else
191 echo "$0: extra non-option argument \`$1'." >&2
192 exit 1
193 fi;;
194 esac
195 shift
196done
197
198# makeinfo uses the dirargs, but texi2dvi doesn't.
199commonarg=" $dirargs $commonarg"
200
201# For most of the following, the base name is just $PACKAGE
202base=$PACKAGE
203
204if test -n "$srcfile"; then
205 # but here, we use the basename of $srcfile
206 base=`basename "$srcfile"`
207 case $base in
208 *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;;
209 esac
210 PACKAGE=$base
211elif test -s "$srcdir/$PACKAGE.texinfo"; then
212 srcfile=$srcdir/$PACKAGE.texinfo
213elif test -s "$srcdir/$PACKAGE.texi"; then
214 srcfile=$srcdir/$PACKAGE.texi
215elif test -s "$srcdir/$PACKAGE.txi"; then
216 srcfile=$srcdir/$PACKAGE.txi
217else
218 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
219 exit 1
220fi
221
222if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
223 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
224 echo "$0: it is available from $templateurl." >&2
225 exit 1
226fi
227
228# Function to return size of $1 in something resembling kilobytes.
229calcsize()
230{
231 size=`ls -ksl $1 | awk '{print $1}'`
232 echo $size
233}
234
235# copy_images OUTDIR HTML-FILE...
236# -------------------------------
237# Copy all the images needed by the HTML-FILEs into OUTDIR.
238# Look for them in . and the -I directories; this is simpler than what
239# makeinfo supports with -I, but hopefully it will suffice.
240copy_images()
241{
242 local odir
243 odir=$1
244 shift
245 $PERL -n -e "
246BEGIN {
247 \$me = '$prog';
248 \$odir = '$odir';
249 @dirs = qw(. $dirs);
250}
251" -e '
252/<img src="(.*?)"/g && ++$need{$1};
253
254END {
255 #print "$me: @{[keys %need]}\n"; # for debugging, show images found.
256 FILE: for my $f (keys %need) {
257 for my $d (@dirs) {
258 if (-f "$d/$f") {
259 use File::Basename;
260 my $dest = dirname ("$odir/$f");
261 #
262 use File::Path;
263 -d $dest || mkpath ($dest)
264 || die "$me: cannot mkdir $dest: $!\n";
265 #
266 use File::Copy;
267 copy ("$d/$f", $dest)
268 || die "$me: cannot copy $d/$f to $dest: $!\n";
269 next FILE;
270 }
271 }
272 die "$me: $ARGV: cannot find image $f\n";
273 }
274}
275' -- "$@" || exit 1
276}
277
278case $outdir in
279 /*) abs_outdir=$outdir;;
280 *) abs_outdir=$srcdir/$outdir;;
281esac
282
283echo "Making output for $srcfile"
284echo " in `pwd`"
285mkdir -p "$outdir/"
286
287#
288if $generate_info; then
289 cmd="$SETLANG $MAKEINFO -o $PACKAGE.info $commonarg $infoarg \"$srcfile\""
290 echo "Generating info... ($cmd)"
291 rm -f $PACKAGE.info* # get rid of any strays
292 eval "$cmd"
293 tar czf "$outdir/$PACKAGE.info.tar.gz" $PACKAGE.info*
294 ls -l "$outdir/$PACKAGE.info.tar.gz"
295 info_tgz_size=`calcsize "$outdir/$PACKAGE.info.tar.gz"`
296 # do not mv the info files, there's no point in having them available
297 # separately on the web.
298fi # end info
299
300#
301if $generate_tex; then
302 cmd="$SETLANG $TEXI2DVI $dirargs $texarg \"$srcfile\""
303 printf "\nGenerating dvi... ($cmd)\n"
304 eval "$cmd"
305 # compress/finish dvi:
306 gzip -f -9 $PACKAGE.dvi
307 dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
308 mv $PACKAGE.dvi.gz "$outdir/"
309 ls -l "$outdir/$PACKAGE.dvi.gz"
310
311 cmd="$SETLANG $TEXI2DVI --pdf $dirargs $texarg \"$srcfile\""
312 printf "\nGenerating pdf... ($cmd)\n"
313 eval "$cmd"
314 pdf_size=`calcsize $PACKAGE.pdf`
315 mv $PACKAGE.pdf "$outdir/"
316 ls -l "$outdir/$PACKAGE.pdf"
317fi # end tex (dvi + pdf)
318
319#
320if $generate_ascii; then
321 opt="-o $PACKAGE.txt --no-split --no-headers $commonarg"
322 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
323 printf "\nGenerating ascii... ($cmd)\n"
324 eval "$cmd"
325 ascii_size=`calcsize $PACKAGE.txt`
326 gzip -f -9 -c $PACKAGE.txt >"$outdir/$PACKAGE.txt.gz"
327 ascii_gz_size=`calcsize "$outdir/$PACKAGE.txt.gz"`
328 mv $PACKAGE.txt "$outdir/"
329 ls -l "$outdir/$PACKAGE.txt" "$outdir/$PACKAGE.txt.gz"
330fi
331
332#
333
334if $generate_html; then
335# Split HTML at level $1. Used for texi2html.
336html_split()
337{
338 opt="--split=$1 --node-files $commonarg $htmlarg"
339 cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
340 printf "\nGenerating html by $1... ($cmd)\n"
341 eval "$cmd"
342 split_html_dir=$PACKAGE.html
343 (
344 cd ${split_html_dir} || exit 1
345 ln -sf ${PACKAGE}.html index.html
346 tar -czf "$abs_outdir/${PACKAGE}.html_$1.tar.gz" -- *.html
347 )
348 eval html_$1_tgz_size=`calcsize "$outdir/${PACKAGE}.html_$1.tar.gz"`
349 rm -f "$outdir"/html_$1/*.html
350 mkdir -p "$outdir/html_$1/"
351 mv ${split_html_dir}/*.html "$outdir/html_$1/"
352 rmdir ${split_html_dir}
353}
354
355if test -z "$use_texi2html"; then
356 opt="--no-split --html -o $PACKAGE.html $commonarg $htmlarg"
357 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
358 printf "\nGenerating monolithic html... ($cmd)\n"
359 rm -rf $PACKAGE.html # in case a directory is left over
360 eval "$cmd"
361 html_mono_size=`calcsize $PACKAGE.html`
362 gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
363 html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
364 copy_images "$outdir/" $PACKAGE.html
365 mv $PACKAGE.html "$outdir/"
366 ls -l "$outdir/$PACKAGE.html" "$outdir/$PACKAGE.html.gz"
367
368 # Before Texinfo 5.0, makeinfo did not accept a --split=HOW option,
369 # it just always split by node. So if we're splitting by node anyway,
370 # leave it out.
371 if test "x$split" = xnode; then
372 split_arg=
373 else
374 split_arg=--split=$split
375 fi
376 #
377 opt="--html -o $PACKAGE.html $split_arg $commonarg $htmlarg"
378 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
379 printf "\nGenerating html by $split... ($cmd)\n"
380 eval "$cmd"
381 split_html_dir=$PACKAGE.html
382 copy_images $split_html_dir/ $split_html_dir/*.html
383 (
384 cd $split_html_dir || exit 1
385 tar -czf "$abs_outdir/$PACKAGE.html_$split.tar.gz" -- *
386 )
387 eval \
388 html_${split}_tgz_size=`calcsize "$outdir/$PACKAGE.html_$split.tar.gz"`
389 rm -rf "$outdir/html_$split/"
390 mv $split_html_dir "$outdir/html_$split/"
391 du -s "$outdir/html_$split/"
392 ls -l "$outdir/$PACKAGE.html_$split.tar.gz"
393
394else # use texi2html:
395 opt="--output $PACKAGE.html $commonarg $htmlarg"
396 cmd="$SETLANG $TEXI2HTML $opt \"$srcfile\""
397 printf "\nGenerating monolithic html with texi2html... ($cmd)\n"
398 rm -rf $PACKAGE.html # in case a directory is left over
399 eval "$cmd"
400 html_mono_size=`calcsize $PACKAGE.html`
401 gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
402 html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
403 mv $PACKAGE.html "$outdir/"
404
405 html_split node
406 html_split chapter
407 html_split section
408fi
409fi # end html
410
411#
412printf "\nMaking .tar.gz for sources...\n"
413d=`dirname $srcfile`
414(
415 cd "$d"
416 srcfiles=`ls -d *.texinfo *.texi *.txi *.eps $source_extra 2>/dev/null` || true
417 tar czfh "$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles
418 ls -l "$abs_outdir/$PACKAGE.texi.tar.gz"
419)
420texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"`
421
422#
423# Do everything again through docbook.
424if test -n "$docbook"; then
425 opt="-o - --docbook $commonarg"
426 cmd="$SETLANG $MAKEINFO $opt \"$srcfile\" >${srcdir}/$PACKAGE-db.xml"
427 printf "\nGenerating docbook XML... ($cmd)\n"
428 eval "$cmd"
429 docbook_xml_size=`calcsize $PACKAGE-db.xml`
430 gzip -f -9 -c $PACKAGE-db.xml >"$outdir/$PACKAGE-db.xml.gz"
431 docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"`
432 mv $PACKAGE-db.xml "$outdir/"
433
434 split_html_db_dir=html_node_db
435 opt="$commonarg -o $split_html_db_dir"
436 cmd="$DOCBOOK2HTML $opt \"${outdir}/$PACKAGE-db.xml\""
437 printf "\nGenerating docbook HTML... ($cmd)\n"
438 eval "$cmd"
439 (
440 cd ${split_html_db_dir} || exit 1
441 tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html
442 )
443 html_node_db_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node_db.tar.gz"`
444 rm -f "$outdir"/html_node_db/*.html
445 mkdir -p "$outdir/html_node_db"
446 mv ${split_html_db_dir}/*.html "$outdir/html_node_db/"
447 rmdir ${split_html_db_dir}
448
449 cmd="$DOCBOOK2TXT \"${outdir}/$PACKAGE-db.xml\""
450 printf "\nGenerating docbook ASCII... ($cmd)\n"
451 eval "$cmd"
452 docbook_ascii_size=`calcsize $PACKAGE-db.txt`
453 mv $PACKAGE-db.txt "$outdir/"
454
455 cmd="$DOCBOOK2PDF \"${outdir}/$PACKAGE-db.xml\""
456 printf "\nGenerating docbook PDF... ($cmd)\n"
457 eval "$cmd"
458 docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
459 mv $PACKAGE-db.pdf "$outdir/"
460fi
461
462#
463printf "\nMaking index.html for $PACKAGE...\n"
464if test -z "$use_texi2html"; then
465 CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
466 /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
467else
468 # should take account of --split here.
469 CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
470fi
471
472curdate=`$SETLANG date '+%B %d, %Y'`
473sed \
474 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
475 -e "s!%%EMAIL%%!$EMAIL!g" \
476 -e "s!%%PACKAGE%%!$PACKAGE!g" \
477 -e "s!%%DATE%%!$curdate!g" \
478 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
479 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
480 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
481 -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
482 -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
483 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
484 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
485 -e "s!%%PDF_SIZE%%!$pdf_size!g" \
486 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
487 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
488 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
489 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
490 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
491 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
492 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
493 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
494 -e "s,%%SCRIPTURL%%,$scripturl,g" \
495 -e "s!%%SCRIPTNAME%%!$prog!g" \
496 -e "$CONDS" \
497$GENDOCS_TEMPLATE_DIR/gendocs_template >"$outdir/index.html"
498
499echo "Done, see $outdir/ subdirectory for new files."
500
501# Local variables:
502# eval: (add-hook 'write-file-hooks 'time-stamp)
503# time-stamp-start: "scriptversion="
504# time-stamp-format: "%:y-%02m-%02d.%02H"
505# time-stamp-end: "$"
506# End: