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. 4# $Id: gendocs.sh,v 1.16 2005/05/15 00:00:08 karl Exp $ 5# 6# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. 7# 8# This program is free software; you can redistribute it and/or modify 9# it under the terms of the GNU General Public License as published by 10# the Free Software Foundation; either version 2, or (at your option) 11# any later version. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16# GNU General Public License for more details. 17# 18# You should have received a copy of the GNU General Public License 19# along with this program; if not, you can either send email to this 20# program's maintainer or write to: The Free Software Foundation, 21# Inc.; 51 Franklin Street, Fifth Floor; Boston, MA 02110-1301, USA. 22# 23# Original author: Mohit Agarwal. 24# Send bug reports and any other correspondence to bug-texinfo@gnu.org. 25 26#set -e 27 28prog="`basename \"$0\"`" 29srcdir=`pwd` 30 31scripturl="https://github.com/cffi/cffi/blob/master/doc/gendocs.sh" 32templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template" 33 34: ${MAKEINFO="makeinfo"} 35: ${TEXI2DVI="texi2dvi -t @finalout"} 36: ${DVIPS="dvips"} 37: ${DOCBOOK2TXT="docbook2txt"} 38: ${DOCBOOK2HTML="docbook2html"} 39: ${DOCBOOK2PDF="docbook2pdf"} 40: ${DOCBOOK2PS="docbook2ps"} 41: ${GENDOCS_TEMPLATE_DIR="."} 42unset CDPATH 43 44rcs_revision='$Revision: 1.16 $' 45rcs_version=`set - $rcs_revision; echo $2` 46program=`echo $0 | sed -e 's!.*/!!'` 47version="gendocs.sh $rcs_version 48 49Copyright (C) 2005 Free Software Foundation, Inc. 50There is NO warranty. You may redistribute this software 51under the terms of the GNU General Public License. 52For more information about these matters, see the files named COPYING." 53 54usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE 55 56Generate various output formats from PACKAGE.texinfo (or .texi or .txi) source. 57See the GNU Maintainers document for a more extensive discussion: 58 http://www.gnu.org/prep/maintain_toc.html 59 60Options: 61 -o OUTDIR write files into OUTDIR, instead of manual/. 62 --docbook convert to DocBook too (xml, txt, html, pdf and ps). 63 --html ARG pass indicated ARG to makeinfo for HTML targets. 64 --help display this help and exit successfully. 65 --version display version information and exit successfully. 66 67Simple example: $prog emacs \"GNU Emacs Manual\" 68 69Typical sequence: 70 cd YOURPACKAGESOURCE/doc 71 wget \"$scripturl\" 72 wget \"$templateurl\" 73 $prog YOURMANUAL \"GNU YOURMANUAL - One-line description\" 74 75Output will be in a new subdirectory \"manual\" (by default, use -o OUTDIR 76to override). Move all the new files into your web CVS tree, as 77explained in the Web Pages node of maintain.texi. 78 79MANUAL-TITLE is included as part of the HTML <title> of the overall 80manual/index.html file. It should include the name of the package being 81documented. manual/index.html is created by substitution from the file 82$GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the 83generic template for your own purposes.) 84 85If you have several manuals, you'll need to run this script several 86times with different YOURMANUAL values, specifying a different output 87directory with -o each time. Then write (by hand) an overall index.html 88with links to them all. 89 90You can set the environment variables MAKEINFO, TEXI2DVI, and DVIPS to 91control the programs that get executed, and GENDOCS_TEMPLATE_DIR to 92control where the gendocs_template file is looked for. 93 94Email bug reports or enhancement requests to bug-texinfo@gnu.org. 95" 96 97calcsize() 98{ 99 size="`ls -ksl $1 | awk '{print $1}'`" 100 echo $size 101} 102 103outdir=manual 104html= 105PACKAGE= 106MANUAL_TITLE= 107 108while test $# -gt 0; do 109 case $1 in 110 --help) echo "$usage"; exit 0;; 111 --version) echo "$version"; exit 0;; 112 -o) shift; outdir=$1;; 113 --docbook) docbook=yes;; 114 --html) shift; html=$1;; 115 -*) 116 echo "$0: Unknown or ambiguous option \`$1'." >&2 117 echo "$0: Try \`--help' for more information." >&2 118 exit 1;; 119 *) 120 if test -z "$PACKAGE"; then 121 PACKAGE=$1 122 elif test -z "$MANUAL_TITLE"; then 123 MANUAL_TITLE=$1 124 else 125 echo "$0: extra non-option argument \`$1'." >&2 126 exit 1 127 fi;; 128 esac 129 shift 130done 131 132if test -s $srcdir/$PACKAGE.texinfo; then 133 srcfile=$srcdir/$PACKAGE.texinfo 134elif test -s $srcdir/$PACKAGE.texi; then 135 srcfile=$srcdir/$PACKAGE.texi 136elif test -s $srcdir/$PACKAGE.txi; then 137 srcfile=$srcdir/$PACKAGE.txi 138else 139 echo "$0: cannot find .texinfo or .texi or .txi for $PACKAGE in $srcdir." >&2 140 exit 1 141fi 142 143if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then 144 echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2 145 echo "$0: it is available from $templateurl." >&2 146 exit 1 147fi 148 149echo Generating output formats for $srcfile 150 151cmd="${MAKEINFO} -o $PACKAGE.info $srcfile" 152echo "Generating info files... ($cmd)" 153eval $cmd 154install-info $PACKAGE.info dir 155mkdir -p $outdir/ 156tar czf $outdir/$PACKAGE.info.tar.gz $PACKAGE.info* 157info_tgz_size="`calcsize $outdir/$PACKAGE.info.tar.gz`" 158# do not mv the info files, there's no point in having them available 159# separately on the web. 160 161cmd="${TEXI2DVI} $srcfile" 162echo "Generating dvi ... ($cmd)" 163eval $cmd 164 165# now, before we compress dvi: 166echo Generating postscript... 167${DVIPS} $PACKAGE -o 168gzip -f -9 $PACKAGE.ps 169ps_gz_size="`calcsize $PACKAGE.ps.gz`" 170mv $PACKAGE.ps.gz $outdir/ 171 172# compress/finish dvi: 173gzip -f -9 $PACKAGE.dvi 174dvi_gz_size="`calcsize $PACKAGE.dvi.gz`" 175mv $PACKAGE.dvi.gz $outdir/ 176 177cmd="${TEXI2DVI} --pdf $srcfile" 178echo "Generating pdf ... ($cmd)" 179eval $cmd 180pdf_size="`calcsize $PACKAGE.pdf`" 181mv $PACKAGE.pdf $outdir/ 182 183cmd="${MAKEINFO} -o $PACKAGE.txt --no-split --no-headers $srcfile" 184echo "Generating ASCII... ($cmd)" 185eval $cmd 186ascii_size="`calcsize $PACKAGE.txt`" 187gzip -f -9 -c $PACKAGE.txt >$outdir/$PACKAGE.txt.gz 188ascii_gz_size="`calcsize $outdir/$PACKAGE.txt.gz`" 189mv $PACKAGE.txt $outdir/ 190 191# Print a SED expression that will translate references to MANUAL to 192# the proper page on gnu.org. This is a horrible shell hack done 193# because \| in sed regexps is a GNU extension. 194monognuorg () { 195 case "$1" in 196 libtool) echo "s!$1.html!http://www.gnu.org/software/$1/manual.html!" ;; 197 *) echo "s!$1.html!http://www.gnu.org/software/$1/manual/html_mono/$1.html!" ;; 198 esac 199} 200polygnuorg () { 201 case "$1" in 202 libtool) echo 's!\.\./'"$1/.*\.html!http://www.gnu.org/software/$1/manual.html!" ;; 203 *) echo 's!\.\./'"$1!http://www.gnu.org/software/$1/manual/html_node!" ;; 204 esac 205} 206 207cmd="${MAKEINFO} --no-split --html -o $PACKAGE.html $html $srcfile" 208echo "Generating monolithic html... ($cmd)" 209rm -rf $PACKAGE.html # in case a directory is left over 210eval $cmd 211sbcl --no-sysinit --no-userinit --load colorize-lisp-examples.lisp $PACKAGE.html 212#fix libc/libtool xrefs 213sed -e `monognuorg libc` -e `monognuorg libtool` $PACKAGE.html >$outdir/$PACKAGE.html 214rm $PACKAGE.html 215html_mono_size="`calcsize $outdir/$PACKAGE.html`" 216gzip -f -9 -c $outdir/$PACKAGE.html >$outdir/$PACKAGE.html.gz 217html_mono_gz_size="`calcsize $outdir/$PACKAGE.html.gz`" 218 219cmd="${MAKEINFO} --html -o $PACKAGE.html $html $srcfile" 220echo "Generating html by node... ($cmd)" 221eval $cmd 222split_html_dir=$PACKAGE.html 223sbcl --no-userinit --no-sysinit --load colorize-lisp-examples.lisp "${split_html_dir}"/\*.html 224( 225 cd ${split_html_dir} || exit 1 226 #fix libc xrefs 227 for broken_file in *.html; do 228 sed -e `polygnuorg libc` -e `polygnuorg libtool` "$broken_file" > "$broken_file".temp 229 mv -f "$broken_file".temp "$broken_file" 230 done 231 tar -czf ../$outdir/${PACKAGE}.html_node.tar.gz -- *.html 232) 233html_node_tgz_size="`calcsize $outdir/${PACKAGE}.html_node.tar.gz`" 234rm -f $outdir/html_node/*.html 235mkdir -p $outdir/html_node/ 236mv ${split_html_dir}/*.html $outdir/html_node/ 237rmdir ${split_html_dir} 238 239echo Making .tar.gz for sources... 240srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null` 241tar cvzfh $outdir/$PACKAGE.texi.tar.gz $srcfiles 242texi_tgz_size="`calcsize $outdir/$PACKAGE.texi.tar.gz`" 243 244if test -n "$docbook"; then 245 cmd="${MAKEINFO} -o - --docbook $srcfile > ${srcdir}/$PACKAGE-db.xml" 246 echo "Generating docbook XML... $(cmd)" 247 eval $cmd 248 docbook_xml_size="`calcsize $PACKAGE-db.xml`" 249 gzip -f -9 -c $PACKAGE-db.xml >$outdir/$PACKAGE-db.xml.gz 250 docbook_xml_gz_size="`calcsize $outdir/$PACKAGE-db.xml.gz`" 251 mv $PACKAGE-db.xml $outdir/ 252 253 cmd="${DOCBOOK2HTML} -o $split_html_db_dir ${outdir}/$PACKAGE-db.xml" 254 echo "Generating docbook HTML... ($cmd)" 255 eval $cmd 256 split_html_db_dir=html_node_db 257 ( 258 cd ${split_html_db_dir} || exit 1 259 tar -czf ../$outdir/${PACKAGE}.html_node_db.tar.gz -- *.html 260 ) 261 html_node_db_tgz_size="`calcsize $outdir/${PACKAGE}.html_node_db.tar.gz`" 262 rm -f $outdir/html_node_db/*.html 263 mkdir -p $outdir/html_node_db 264 mv ${split_html_db_dir}/*.html $outdir/html_node_db/ 265 rmdir ${split_html_db_dir} 266 267 cmd="${DOCBOOK2TXT} ${outdir}/$PACKAGE-db.xml" 268 echo "Generating docbook ASCII... ($cmd)" 269 eval $cmd 270 docbook_ascii_size="`calcsize $PACKAGE-db.txt`" 271 mv $PACKAGE-db.txt $outdir/ 272 273 cmd="${DOCBOOK2PS} ${outdir}/$PACKAGE-db.xml" 274 echo "Generating docbook PS... $(cmd)" 275 eval $cmd 276 gzip -f -9 -c $PACKAGE-db.ps >$outdir/$PACKAGE-db.ps.gz 277 docbook_ps_gz_size="`calcsize $outdir/$PACKAGE-db.ps.gz`" 278 mv $PACKAGE-db.ps $outdir/ 279 280 cmd="${DOCBOOK2PDF} ${outdir}/$PACKAGE-db.xml" 281 echo "Generating docbook PDF... ($cmd)" 282 eval $cmd 283 docbook_pdf_size="`calcsize $PACKAGE-db.pdf`" 284 mv $PACKAGE-db.pdf $outdir/ 285fi 286 287echo Writing index file... 288curdate="`date '+%B %d, %Y'`" 289sed \ 290 -e "s!%%TITLE%%!$MANUAL_TITLE!g" \ 291 -e "s!%%DATE%%!$curdate!g" \ 292 -e "s!%%PACKAGE%%!$PACKAGE!g" \ 293 -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \ 294 -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \ 295 -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \ 296 -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \ 297 -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \ 298 -e "s!%%PDF_SIZE%%!$pdf_size!g" \ 299 -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \ 300 -e "s!%%ASCII_SIZE%%!$ascii_size!g" \ 301 -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \ 302 -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \ 303 -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \ 304 -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \ 305 -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \ 306 -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \ 307 -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \ 308 -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \ 309 -e "s,%%SCRIPTURL%%,$scripturl,g" \ 310 -e "s!%%SCRIPTNAME%%!$prog!g" \ 311$GENDOCS_TEMPLATE_DIR/gendocs_template >$outdir/index.html 312 313echo "Done! See $outdir/ subdirectory for new files." 314