xref: /openbsd-src/gnu/usr.bin/texinfo/util/gendocs.sh (revision a1acfa9b69ad64eb720639240c8438f11107dc85)
1*a1acfa9bSespie#!/bin/sh
2*a1acfa9bSespie# gendocs.sh -- generate a GNU manual in many formats.  This script is
3*a1acfa9bSespie#   mentioned in maintain.texi.  See the help message below for usage details.
4*a1acfa9bSespie# $Id: gendocs.sh,v 1.1.1.1 2006/07/17 16:03:50 espie Exp $
5*a1acfa9bSespie#
6*a1acfa9bSespie# Copyright (C) 2003, 2004 Free Software Foundation, Inc.
7*a1acfa9bSespie#
8*a1acfa9bSespie# This program is free software; you can redistribute it and/or modify
9*a1acfa9bSespie# it under the terms of the GNU General Public License as published by
10*a1acfa9bSespie# the Free Software Foundation; either version 2, or (at your option)
11*a1acfa9bSespie# any later version.
12*a1acfa9bSespie#
13*a1acfa9bSespie# This program is distributed in the hope that it will be useful,
14*a1acfa9bSespie# but WITHOUT ANY WARRANTY; without even the implied warranty of
15*a1acfa9bSespie# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*a1acfa9bSespie# GNU General Public License for more details.
17*a1acfa9bSespie#
18*a1acfa9bSespie# You should have received a copy of the GNU General Public License
19*a1acfa9bSespie# along with this program; if not, you can either send email to this
20*a1acfa9bSespie# program's maintainer or write to: The Free Software Foundation,
21*a1acfa9bSespie# Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
22*a1acfa9bSespie#
23*a1acfa9bSespie# Original author: Mohit Agarwal.
24*a1acfa9bSespie# Send bug reports and any other correspondence to bug-texinfo@gnu.org.
25*a1acfa9bSespie
26*a1acfa9bSespieprog="`basename \"$0\"`"
27*a1acfa9bSespiesrcdir=`pwd`
28*a1acfa9bSespie
29*a1acfa9bSespiescripturl="http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs.sh"
30*a1acfa9bSespietemplateurl="http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template"
31*a1acfa9bSespie
32*a1acfa9bSespie: ${MAKEINFO="makeinfo"}
33*a1acfa9bSespie: ${TEXI2DVI="texi2dvi -t @finalout"}
34*a1acfa9bSespie: ${DVIPS="dvips"}
35*a1acfa9bSespie: ${DOCBOOK2TXT="docbook2txt"}
36*a1acfa9bSespie: ${DOCBOOK2HTML="docbook2html"}
37*a1acfa9bSespie: ${DOCBOOK2PDF="docbook2pdf"}
38*a1acfa9bSespie: ${DOCBOOK2PS="docbook2ps"}
39*a1acfa9bSespie: ${GENDOCS_TEMPLATE_DIR="."}
40*a1acfa9bSespieunset CDPATH
41*a1acfa9bSespie
42*a1acfa9bSespiercs_revision='$Revision: 1.1.1.1 $'
43*a1acfa9bSespiercs_version=`set - $rcs_revision; echo $2`
44*a1acfa9bSespieprogram=`echo $0 | sed -e 's!.*/!!'`
45*a1acfa9bSespieversion="gendocs.sh $rcs_version
46*a1acfa9bSespie
47*a1acfa9bSespieCopyright (C) 2003 Free Software Foundation, Inc.
48*a1acfa9bSespieThere is NO warranty.  You may redistribute this software
49*a1acfa9bSespieunder the terms of the GNU General Public License.
50*a1acfa9bSespieFor more information about these matters, see the files named COPYING."
51*a1acfa9bSespie
52*a1acfa9bSespieusage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
53*a1acfa9bSespie
54*a1acfa9bSespieGenerate various output formats from PACKAGE.texinfo (or .texi or .txi) source.
55*a1acfa9bSespieSee the GNU Maintainers document for a more extensive discussion:
56*a1acfa9bSespie  http://www.gnu.org/prep/maintain_toc.html
57*a1acfa9bSespie
58*a1acfa9bSespieOptions:
59*a1acfa9bSespie  -o OUTDIR   write files into OUTDIR, instead of manual/.
60*a1acfa9bSespie  --docbook   convert to DocBook too (xml, txt, html, pdf and ps).
61*a1acfa9bSespie  --html ARG  pass indicated ARG to makeinfo for HTML targets.
62*a1acfa9bSespie  --help      display this help and exit successfully.
63*a1acfa9bSespie  --version   display version information and exit successfully.
64*a1acfa9bSespie
65*a1acfa9bSespieSimple example: $prog emacs \"GNU Emacs Manual\"
66*a1acfa9bSespie
67*a1acfa9bSespieTypical sequence:
68*a1acfa9bSespie  cd YOURPACKAGESOURCE/doc
69*a1acfa9bSespie  wget \"$scripturl\"
70*a1acfa9bSespie  wget \"$templateurl\"
71*a1acfa9bSespie  $prog YOURMANUAL \"GNU YOURMANUAL - One-line description\"
72*a1acfa9bSespie
73*a1acfa9bSespieOutput will be in a new subdirectory \"manual\" (by default, use -o OUTDIR
74*a1acfa9bSespieto override).  Move all the new files into your web CVS tree, as
75*a1acfa9bSespieexplained in the Web Pages node of maintain.texi.
76*a1acfa9bSespie
77*a1acfa9bSespieMANUAL-TITLE is included as part of the HTML <title> of the overall
78*a1acfa9bSespiemanual/index.html file.  It should include the name of the package being
79*a1acfa9bSespiedocumented.  manual/index.html is created by substitution from the file
80*a1acfa9bSespie$GENDOCS_TEMPLATE_DIR/gendocs_template.  (Feel free to modify the
81*a1acfa9bSespiegeneric template for your own purposes.)
82*a1acfa9bSespie
83*a1acfa9bSespieIf you have several manuals, you'll need to run this script several
84*a1acfa9bSespietimes with different YOURMANUAL values, specifying a different output
85*a1acfa9bSespiedirectory with -o each time.  Then write (by hand) an overall index.html
86*a1acfa9bSespiewith links to them all.
87*a1acfa9bSespie
88*a1acfa9bSespieYou can set the environment variables MAKEINFO, TEXI2DVI, and DVIPS to
89*a1acfa9bSespiecontrol the programs that get executed, and GENDOCS_TEMPLATE_DIR to
90*a1acfa9bSespiecontrol where the gendocs_template file is looked for.
91*a1acfa9bSespie
92*a1acfa9bSespieEmail bug reports or enhancement requests to bug-texinfo@gnu.org.
93*a1acfa9bSespie"
94*a1acfa9bSespie
95*a1acfa9bSespiecalcsize()
96*a1acfa9bSespie{
97*a1acfa9bSespie  size="`ls -ksl $1 | awk '{print $1}'`"
98*a1acfa9bSespie  echo $size
99*a1acfa9bSespie}
100*a1acfa9bSespie
101*a1acfa9bSespieoutdir=manual
102*a1acfa9bSespiehtml=
103*a1acfa9bSespiePACKAGE=
104*a1acfa9bSespieMANUAL_TITLE=
105*a1acfa9bSespie
106*a1acfa9bSespiewhile test $# -gt 0; do
107*a1acfa9bSespie  case $1 in
108*a1acfa9bSespie    --help) echo "$usage"; exit 0;;
109*a1acfa9bSespie    --version) echo "$version"; exit 0;;
110*a1acfa9bSespie    -o) shift; outdir=$1;;
111*a1acfa9bSespie    --docbook) docbook=yes;;
112*a1acfa9bSespie    --html) shift; html=$1;;
113*a1acfa9bSespie    -*)
114*a1acfa9bSespie      echo "$0: Unknown or ambiguous option \`$1'." >&2
115*a1acfa9bSespie      echo "$0: Try \`--help' for more information." >&2
116*a1acfa9bSespie      exit 1;;
117*a1acfa9bSespie    *)
118*a1acfa9bSespie      if test -z "$PACKAGE"; then
119*a1acfa9bSespie        PACKAGE=$1
120*a1acfa9bSespie      elif test -z "$MANUAL_TITLE"; then
121*a1acfa9bSespie        MANUAL_TITLE=$1
122*a1acfa9bSespie      else
123*a1acfa9bSespie        echo "$0: extra non-option argument \`$1'." >&2
124*a1acfa9bSespie        exit 1
125*a1acfa9bSespie      fi;;
126*a1acfa9bSespie  esac
127*a1acfa9bSespie  shift
128*a1acfa9bSespiedone
129*a1acfa9bSespie
130*a1acfa9bSespieif test -s $srcdir/$PACKAGE.texinfo; then
131*a1acfa9bSespie  srcfile=$srcdir/$PACKAGE.texinfo
132*a1acfa9bSespieelif test -s $srcdir/$PACKAGE.texi; then
133*a1acfa9bSespie  srcfile=$srcdir/$PACKAGE.texi
134*a1acfa9bSespieelif test -s $srcdir/$PACKAGE.txi; then
135*a1acfa9bSespie  srcfile=$srcdir/$PACKAGE.txi
136*a1acfa9bSespieelse
137*a1acfa9bSespie  echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2
138*a1acfa9bSespie  exit 1
139*a1acfa9bSespiefi
140*a1acfa9bSespie
141*a1acfa9bSespieif test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
142*a1acfa9bSespie  echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
143*a1acfa9bSespie  echo "$0: it is available from $templateurl." >&2
144*a1acfa9bSespie  exit 1
145*a1acfa9bSespiefi
146*a1acfa9bSespie
147*a1acfa9bSespieecho Generating output formats for $srcfile
148*a1acfa9bSespie
149*a1acfa9bSespiecmd="${MAKEINFO} -o $PACKAGE.info $srcfile"
150*a1acfa9bSespieecho "Generating info files... ($cmd)"
151*a1acfa9bSespie$cmd
152*a1acfa9bSespiemkdir -p $outdir/
153*a1acfa9bSespietar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info*
154*a1acfa9bSespieinfo_tgz_size="`calcsize $outdir/$PACKAGE.info.tar.gz`"
155*a1acfa9bSespie# do not mv the info files, there's no point in having them available
156*a1acfa9bSespie# separately on the web.
157*a1acfa9bSespie
158*a1acfa9bSespiecmd="${TEXI2DVI} $srcfile"
159*a1acfa9bSespieecho "Generating dvi ... ($cmd)"
160*a1acfa9bSespie$cmd
161*a1acfa9bSespie
162*a1acfa9bSespie# now, before we compress dvi:
163*a1acfa9bSespieecho Generating postscript...
164*a1acfa9bSespie${DVIPS} $PACKAGE -o
165*a1acfa9bSespiegzip -f -9 $PACKAGE.ps
166*a1acfa9bSespieps_gz_size="`calcsize $PACKAGE.ps.gz`"
167*a1acfa9bSespiemv $PACKAGE.ps.gz $outdir/
168*a1acfa9bSespie
169*a1acfa9bSespie# compress/finish dvi:
170*a1acfa9bSespiegzip -f -9 $PACKAGE.dvi
171*a1acfa9bSespiedvi_gz_size="`calcsize $PACKAGE.dvi.gz`"
172*a1acfa9bSespiemv $PACKAGE.dvi.gz $outdir/
173*a1acfa9bSespie
174*a1acfa9bSespiecmd="${TEXI2DVI} --pdf $srcfile"
175*a1acfa9bSespieecho "Generating pdf ... ($cmd)"
176*a1acfa9bSespie$cmd
177*a1acfa9bSespiepdf_size="`calcsize $PACKAGE.pdf`"
178*a1acfa9bSespiemv $PACKAGE.pdf $outdir/
179*a1acfa9bSespie
180*a1acfa9bSespiecmd="${MAKEINFO} -o $PACKAGE.txt --no-split --no-headers $srcfile"
181*a1acfa9bSespieecho "Generating ASCII... ($cmd)"
182*a1acfa9bSespie$cmd
183*a1acfa9bSespieascii_size="`calcsize $PACKAGE.txt`"
184*a1acfa9bSespiegzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz
185*a1acfa9bSespieascii_gz_size="`calcsize $outdir/$PACKAGE.txt.gz`"
186*a1acfa9bSespiemv $PACKAGE.txt $outdir/
187*a1acfa9bSespie
188*a1acfa9bSespiecmd="${MAKEINFO} --no-split --html -o $PACKAGE.html $html $srcfile"
189*a1acfa9bSespieecho "Generating monolithic html... ($cmd)"
190*a1acfa9bSespierm -rf $PACKAGE.html  # in case a directory is left over
191*a1acfa9bSespie$cmd
192*a1acfa9bSespiehtml_mono_size="`calcsize $PACKAGE.html`"
193*a1acfa9bSespiegzip -f -9 -c $PACKAGE.html >$outdir/$PACKAGE.html.gz
194*a1acfa9bSespiehtml_mono_gz_size="`calcsize $outdir/$PACKAGE.html.gz`"
195*a1acfa9bSespiemv $PACKAGE.html $outdir/
196*a1acfa9bSespie
197*a1acfa9bSespiecmd="${MAKEINFO} --html -o $PACKAGE.html $html $srcfile"
198*a1acfa9bSespieecho "Generating html by node... ($cmd)"
199*a1acfa9bSespie$cmd
200*a1acfa9bSespiesplit_html_dir=$PACKAGE.html
201*a1acfa9bSespie(
202*a1acfa9bSespie  cd ${split_html_dir} || exit 1
203*a1acfa9bSespie  tar -czf ../$outdir/${PACKAGE}.html_node.tar.gz -- *.html
204*a1acfa9bSespie)
205*a1acfa9bSespiehtml_node_tgz_size="`calcsize $outdir/${PACKAGE}.html_node.tar.gz`"
206*a1acfa9bSespierm -f $outdir/html_node/*.html
207*a1acfa9bSespiemkdir -p $outdir/html_node/
208*a1acfa9bSespiemv ${split_html_dir}/*.html $outdir/html_node/
209*a1acfa9bSespiermdir ${split_html_dir}
210*a1acfa9bSespie
211*a1acfa9bSespieecho Making .tar.gz for sources...
212*a1acfa9bSespiesrcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null`
213*a1acfa9bSespietar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles
214*a1acfa9bSespietexi_tgz_size="`calcsize $outdir/$PACKAGE.texi.tar.gz`"
215*a1acfa9bSespie
216*a1acfa9bSespieif test -n "$docbook"; then
217*a1acfa9bSespie  cmd="${MAKEINFO} -o - --docbook $srcfile > ${srcdir}/$PACKAGE-db.xml"
218*a1acfa9bSespie  echo "Generating docbook XML... $(cmd)"
219*a1acfa9bSespie  eval $cmd
220*a1acfa9bSespie  docbook_xml_size="`calcsize $PACKAGE-db.xml`"
221*a1acfa9bSespie  gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz
222*a1acfa9bSespie  docbook_xml_gz_size="`calcsize $outdir/$PACKAGE-db.xml.gz`"
223*a1acfa9bSespie  mv $PACKAGE-db.xml $outdir/
224*a1acfa9bSespie
225*a1acfa9bSespie  cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml"
226*a1acfa9bSespie  echo "Generating docbook HTML... ($cmd)"
227*a1acfa9bSespie  $cmd
228*a1acfa9bSespie  split_html_db_dir=html_node_db
229*a1acfa9bSespie  (
230*a1acfa9bSespie    cd ${split_html_db_dir} || exit 1
231*a1acfa9bSespie    tar -czf ../$outdir/${PACKAGE}.html_node_db.tar.gz -- *.html
232*a1acfa9bSespie  )
233*a1acfa9bSespie  html_node_db_tgz_size="`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`"
234*a1acfa9bSespie  rm -f $outdir/html_node_db/*.html
235*a1acfa9bSespie  mkdir -p $outdir/html_node_db
236*a1acfa9bSespie  mv ${split_html_db_dir}/*.html $outdir/html_node_db/
237*a1acfa9bSespie  rmdir ${split_html_db_dir}
238*a1acfa9bSespie
239*a1acfa9bSespie  cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml"
240*a1acfa9bSespie  echo "Generating docbook ASCII... ($cmd)"
241*a1acfa9bSespie  $cmd
242*a1acfa9bSespie  docbook_ascii_size="`calcsize $PACKAGE-db.txt`"
243*a1acfa9bSespie  mv $PACKAGE-db.txt $outdir/
244*a1acfa9bSespie
245*a1acfa9bSespie  cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml"
246*a1acfa9bSespie  echo "Generating docbook PS... $(cmd)"
247*a1acfa9bSespie  $cmd
248*a1acfa9bSespie  gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz
249*a1acfa9bSespie  docbook_ps_gz_size="`calcsize $outdir/$PACKAGE-db.ps.gz`"
250*a1acfa9bSespie  mv $PACKAGE-db.ps $outdir/
251*a1acfa9bSespie
252*a1acfa9bSespie  cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml"
253*a1acfa9bSespie  echo "Generating docbook PDF... ($cmd)"
254*a1acfa9bSespie  $cmd
255*a1acfa9bSespie  docbook_pdf_size="`calcsize $PACKAGE-db.pdf`"
256*a1acfa9bSespie  mv $PACKAGE-db.pdf $outdir/
257*a1acfa9bSespiefi
258*a1acfa9bSespie
259*a1acfa9bSespieecho Writing index file...
260*a1acfa9bSespiecurdate="`date '+%B %d, %Y'`"
261*a1acfa9bSespiesed \
262*a1acfa9bSespie   -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
263*a1acfa9bSespie   -e "s!%%DATE%%!$curdate!g" \
264*a1acfa9bSespie   -e "s!%%PACKAGE%%!$PACKAGE!g" \
265*a1acfa9bSespie   -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
266*a1acfa9bSespie   -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
267*a1acfa9bSespie   -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
268*a1acfa9bSespie   -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
269*a1acfa9bSespie   -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
270*a1acfa9bSespie   -e "s!%%PDF_SIZE%%!$pdf_size!g" \
271*a1acfa9bSespie   -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
272*a1acfa9bSespie   -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
273*a1acfa9bSespie   -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
274*a1acfa9bSespie   -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
275*a1acfa9bSespie   -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
276*a1acfa9bSespie   -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
277*a1acfa9bSespie   -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
278*a1acfa9bSespie   -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
279*a1acfa9bSespie   -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
280*a1acfa9bSespie   -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
281*a1acfa9bSespie   -e "s,%%SCRIPTURL%%,$scripturl,g" \
282*a1acfa9bSespie   -e "s!%%SCRIPTNAME%%!$prog!g" \
283*a1acfa9bSespie$GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html
284*a1acfa9bSespie
285*a1acfa9bSespieecho "Done!  See $outdir/ subdirectory for new files."
286