gendocs.sh 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. scriptversion=2011-04-08.14
  5. # Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
  6. # 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 3 of the License, or
  11. # (at your option) 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, see <http://www.gnu.org/licenses/>.
  20. #
  21. # Original author: Mohit Agarwal.
  22. # Send bug reports and any other correspondence to bug-texinfo@gnu.org.
  23. #
  24. # The latest version of this script, and the companion template, is
  25. # available from Texinfo CVS:
  26. # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs.sh
  27. # http://savannah.gnu.org/cgi-bin/viewcvs/texinfo/texinfo/util/gendocs_template
  28. #
  29. # An up-to-date copy is also maintained in Gnulib (gnu.org/software/gnulib).
  30. prog=`basename "$0"`
  31. srcdir=`pwd`
  32. scripturl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs.sh"
  33. templateurl="http://savannah.gnu.org/cgi-bin/viewcvs/~checkout~/texinfo/texinfo/util/gendocs_template"
  34. : ${SETLANG="env LANG= LC_MESSAGES= LC_ALL= LANGUAGE="}
  35. : ${MAKEINFO="makeinfo"}
  36. : ${TEXI2DVI="texi2dvi -t @finalout"}
  37. : ${DVIPS="dvips"}
  38. : ${DOCBOOK2HTML="docbook2html"}
  39. : ${DOCBOOK2PDF="docbook2pdf"}
  40. : ${DOCBOOK2PS="docbook2ps"}
  41. : ${DOCBOOK2TXT="docbook2txt"}
  42. : ${GENDOCS_TEMPLATE_DIR="."}
  43. : ${TEXI2HTML="texi2html"}
  44. unset CDPATH
  45. unset use_texi2html
  46. version="gendocs.sh $scriptversion
  47. Copyright 2010 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."
  51. usage="Usage: $prog [OPTION]... PACKAGE MANUAL-TITLE
  52. Generate various output formats from PACKAGE.texinfo (or .texi or .txi) source.
  53. See the GNU Maintainers document for a more extensive discussion:
  54. http://www.gnu.org/prep/maintain_toc.html
  55. Options:
  56. -s SRCFILE read Texinfo from SRCFILE, instead of PACKAGE.{texinfo|texi|txi}
  57. -o OUTDIR write files into OUTDIR, instead of manual/.
  58. --email ADR use ADR as contact in generated web pages.
  59. --docbook convert to DocBook too (xml, txt, html, pdf and ps).
  60. --html ARG pass indicated ARG to makeinfo or texi2html for HTML targets.
  61. --texi2html use texi2html to generate HTML targets.
  62. --help display this help and exit successfully.
  63. --version display version information and exit successfully.
  64. Simple example: $prog --email bug-gnu-emacs@gnu.org emacs \"GNU Emacs Manual\"
  65. Typical sequence:
  66. cd PACKAGESOURCE/doc
  67. wget \"$scripturl\"
  68. wget \"$templateurl\"
  69. $prog --email BUGLIST MANUAL \"GNU MANUAL - One-line description\"
  70. Output will be in a new subdirectory \"manual\" (by default, use -o OUTDIR
  71. to override). Move all the new files into your web CVS tree, as
  72. explained in the Web Pages node of maintain.texi.
  73. Please use the --email ADDRESS option to specify your bug-reporting
  74. address in the generated HTML pages.
  75. MANUAL-TITLE is included as part of the HTML <title> of the overall
  76. manual/index.html file. It should include the name of the package being
  77. documented. manual/index.html is created by substitution from the file
  78. $GENDOCS_TEMPLATE_DIR/gendocs_template. (Feel free to modify the
  79. generic template for your own purposes.)
  80. If you have several manuals, you'll need to run this script several
  81. times with different MANUAL values, specifying a different output
  82. directory with -o each time. Then write (by hand) an overall index.html
  83. with links to them all.
  84. If a manual's Texinfo sources are spread across several directories,
  85. first copy or symlink all Texinfo sources into a single directory.
  86. (Part of the script's work is to make a tar.gz of the sources.)
  87. You can set the environment variables MAKEINFO, TEXI2DVI, TEXI2HTML, and
  88. DVIPS to control the programs that get executed, and
  89. GENDOCS_TEMPLATE_DIR to control where the gendocs_template file is
  90. looked for. With --docbook, the environment variables DOCBOOK2HTML,
  91. DOCBOOK2PDF, DOCBOOK2PS, and DOCBOOK2TXT are also respected.
  92. By default, makeinfo and texi2dvi are run in the default (English)
  93. locale, since that's the language of most Texinfo manuals. If you
  94. happen to have a non-English manual and non-English web site, see the
  95. SETLANG setting in the source.
  96. Email bug reports or enhancement requests to bug-texinfo@gnu.org.
  97. "
  98. calcsize()
  99. {
  100. size=`ls -ksl $1 | awk '{print $1}'`
  101. echo $size
  102. }
  103. MANUAL_TITLE=
  104. PACKAGE=
  105. EMAIL=webmasters@gnu.org # please override with --email
  106. htmlarg=
  107. outdir=manual
  108. srcfile=
  109. while test $# -gt 0; do
  110. case $1 in
  111. --email) shift; EMAIL=$1;;
  112. --help) echo "$usage"; exit 0;;
  113. --version) echo "$version"; exit 0;;
  114. -s) shift; srcfile=$1;;
  115. -o) shift; outdir=$1;;
  116. --docbook) docbook=yes;;
  117. --html) shift; htmlarg=$1;;
  118. --texi2html) use_texi2html=1;;
  119. -*)
  120. echo "$0: Unknown option \`$1'." >&2
  121. echo "$0: Try \`--help' for more information." >&2
  122. exit 1;;
  123. *)
  124. if test -z "$PACKAGE"; then
  125. PACKAGE=$1
  126. elif test -z "$MANUAL_TITLE"; then
  127. MANUAL_TITLE=$1
  128. else
  129. echo "$0: extra non-option argument \`$1'." >&2
  130. exit 1
  131. fi;;
  132. esac
  133. shift
  134. done
  135. # For most of the following, the base name is just $PACKAGE
  136. base=$PACKAGE
  137. if test -n "$srcfile"; then
  138. # but here, we use the basename of $srcfile
  139. base=`basename "$srcfile"`
  140. case $base in
  141. *.txi|*.texi|*.texinfo) base=`echo "$base"|sed 's/\.[texinfo]*$//'`;;
  142. esac
  143. PACKAGE=$base
  144. elif 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
  153. fi
  154. if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then
  155. echo "$0: cannot read $GENDOCS_TEMPLATE_DIR/gendocs_template." >&2
  156. echo "$0: it is available from $templateurl." >&2
  157. exit 1
  158. fi
  159. case $outdir in
  160. /*) abs_outdir=$outdir;;
  161. *) abs_outdir=$srcdir/$outdir;;
  162. esac
  163. echo Generating output formats for $srcfile
  164. cmd="$SETLANG $MAKEINFO -o $PACKAGE.info \"$srcfile\""
  165. echo "Generating info files... ($cmd)"
  166. eval "$cmd"
  167. mkdir -p "$outdir/"
  168. tar czf "$outdir/$PACKAGE.info.tar.gz" $PACKAGE.info*
  169. info_tgz_size=`calcsize "$outdir/$PACKAGE.info.tar.gz"`
  170. # do not mv the info files, there's no point in having them available
  171. # separately on the web.
  172. cmd="$SETLANG ${TEXI2DVI} \"$srcfile\""
  173. echo "Generating dvi ... ($cmd)"
  174. eval "$cmd"
  175. # now, before we compress dvi:
  176. echo Generating postscript...
  177. ${DVIPS} $PACKAGE -o
  178. gzip -f -9 $PACKAGE.ps
  179. ps_gz_size=`calcsize $PACKAGE.ps.gz`
  180. mv $PACKAGE.ps.gz "$outdir/"
  181. # compress/finish dvi:
  182. gzip -f -9 $PACKAGE.dvi
  183. dvi_gz_size=`calcsize $PACKAGE.dvi.gz`
  184. mv $PACKAGE.dvi.gz "$outdir/"
  185. cmd="$SETLANG ${TEXI2DVI} --pdf \"$srcfile\""
  186. echo "Generating pdf ... ($cmd)"
  187. eval "$cmd"
  188. pdf_size=`calcsize $PACKAGE.pdf`
  189. mv $PACKAGE.pdf "$outdir/"
  190. cmd="$SETLANG $MAKEINFO -o $PACKAGE.txt --no-split --no-headers \"$srcfile\""
  191. echo "Generating ASCII... ($cmd)"
  192. eval "$cmd"
  193. ascii_size=`calcsize $PACKAGE.txt`
  194. gzip -f -9 -c $PACKAGE.txt >"$outdir/$PACKAGE.txt.gz"
  195. ascii_gz_size=`calcsize "$outdir/$PACKAGE.txt.gz"`
  196. mv $PACKAGE.txt "$outdir/"
  197. html_split()
  198. {
  199. opt="--split=$1 $htmlarg --node-files"
  200. cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $opt \"$srcfile\""
  201. echo "Generating html by $1... ($cmd)"
  202. eval "$cmd"
  203. split_html_dir=$PACKAGE.html
  204. (
  205. cd ${split_html_dir} || exit 1
  206. ln -sf ${PACKAGE}.html index.html
  207. tar -czf "$abs_outdir/${PACKAGE}.html_$1.tar.gz" -- *.html
  208. )
  209. eval html_$1_tgz_size=`calcsize "$outdir/${PACKAGE}.html_$1.tar.gz"`
  210. rm -f "$outdir"/html_$1/*.html
  211. mkdir -p "$outdir/html_$1/"
  212. mv ${split_html_dir}/*.html "$outdir/html_$1/"
  213. rmdir ${split_html_dir}
  214. }
  215. if test -z "$use_texi2html"; then
  216. opt="--no-split --html -o $PACKAGE.html $htmlarg"
  217. cmd="$SETLANG $MAKEINFO $opt \"$srcfile\""
  218. echo "Generating monolithic html... ($cmd)"
  219. rm -rf $PACKAGE.html # in case a directory is left over
  220. eval "$cmd"
  221. html_mono_size=`calcsize $PACKAGE.html`
  222. gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
  223. html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
  224. mv $PACKAGE.html "$outdir/"
  225. cmd="$SETLANG $MAKEINFO --html -o $PACKAGE.html $htmlarg \"$srcfile\""
  226. echo "Generating html by node... ($cmd)"
  227. eval "$cmd"
  228. split_html_dir=$PACKAGE.html
  229. (
  230. cd ${split_html_dir} || exit 1
  231. tar -czf "$abs_outdir/${PACKAGE}.html_node.tar.gz" -- *.html
  232. )
  233. html_node_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node.tar.gz"`
  234. rm -f "$outdir"/html_node/*.html
  235. mkdir -p "$outdir/html_node/"
  236. mv ${split_html_dir}/*.html "$outdir/html_node/"
  237. rmdir ${split_html_dir}
  238. else
  239. cmd="$SETLANG $TEXI2HTML --output $PACKAGE.html $htmlarg \"$srcfile\""
  240. echo "Generating monolithic html... ($cmd)"
  241. rm -rf $PACKAGE.html # in case a directory is left over
  242. eval "$cmd"
  243. html_mono_size=`calcsize $PACKAGE.html`
  244. gzip -f -9 -c $PACKAGE.html >"$outdir/$PACKAGE.html.gz"
  245. html_mono_gz_size=`calcsize "$outdir/$PACKAGE.html.gz"`
  246. mv $PACKAGE.html "$outdir/"
  247. html_split node
  248. html_split chapter
  249. html_split section
  250. fi
  251. echo Making .tar.gz for sources...
  252. d=`dirname $srcfile`
  253. (
  254. cd "$d"
  255. srcfiles=`ls *.texinfo *.texi *.txi *.eps 2>/dev/null` || true
  256. tar cvzfh "$abs_outdir/$PACKAGE.texi.tar.gz" $srcfiles
  257. )
  258. texi_tgz_size=`calcsize "$outdir/$PACKAGE.texi.tar.gz"`
  259. if test -n "$docbook"; then
  260. cmd="$SETLANG $MAKEINFO -o - --docbook \"$srcfile\" > ${srcdir}/$PACKAGE-db.xml"
  261. echo "Generating docbook XML... ($cmd)"
  262. eval "$cmd"
  263. docbook_xml_size=`calcsize $PACKAGE-db.xml`
  264. gzip -f -9 -c $PACKAGE-db.xml >"$outdir/$PACKAGE-db.xml.gz"
  265. docbook_xml_gz_size=`calcsize "$outdir/$PACKAGE-db.xml.gz"`
  266. mv $PACKAGE-db.xml "$outdir/"
  267. split_html_db_dir=html_node_db
  268. cmd="${DOCBOOK2HTML} -o $split_html_db_dir \"${outdir}/$PACKAGE-db.xml\""
  269. echo "Generating docbook HTML... ($cmd)"
  270. eval "$cmd"
  271. (
  272. cd ${split_html_db_dir} || exit 1
  273. tar -czf "$abs_outdir/${PACKAGE}.html_node_db.tar.gz" -- *.html
  274. )
  275. html_node_db_tgz_size=`calcsize "$outdir/${PACKAGE}.html_node_db.tar.gz"`
  276. rm -f "$outdir"/html_node_db/*.html
  277. mkdir -p "$outdir/html_node_db"
  278. mv ${split_html_db_dir}/*.html "$outdir/html_node_db/"
  279. rmdir ${split_html_db_dir}
  280. cmd="${DOCBOOK2TXT} \"${outdir}/$PACKAGE-db.xml\""
  281. echo "Generating docbook ASCII... ($cmd)"
  282. eval "$cmd"
  283. docbook_ascii_size=`calcsize $PACKAGE-db.txt`
  284. mv $PACKAGE-db.txt "$outdir/"
  285. cmd="${DOCBOOK2PS} \"${outdir}/$PACKAGE-db.xml\""
  286. echo "Generating docbook PS... ($cmd)"
  287. eval "$cmd"
  288. gzip -f -9 -c $PACKAGE-db.ps >"$outdir/$PACKAGE-db.ps.gz"
  289. docbook_ps_gz_size=`calcsize "$outdir/$PACKAGE-db.ps.gz"`
  290. mv $PACKAGE-db.ps "$outdir/"
  291. cmd="${DOCBOOK2PDF} \"${outdir}/$PACKAGE-db.xml\""
  292. echo "Generating docbook PDF... ($cmd)"
  293. eval "$cmd"
  294. docbook_pdf_size=`calcsize $PACKAGE-db.pdf`
  295. mv $PACKAGE-db.pdf "$outdir/"
  296. fi
  297. echo "Writing index file..."
  298. if test -z "$use_texi2html"; then
  299. CONDS="/%%IF *HTML_SECTION%%/,/%%ENDIF *HTML_SECTION%%/d;\
  300. /%%IF *HTML_CHAPTER%%/,/%%ENDIF *HTML_CHAPTER%%/d"
  301. else
  302. CONDS="/%%ENDIF.*%%/d;/%%IF *HTML_SECTION%%/d;/%%IF *HTML_CHAPTER%%/d"
  303. fi
  304. curdate=`$SETLANG date '+%B %d, %Y'`
  305. sed \
  306. -e "s!%%TITLE%%!$MANUAL_TITLE!g" \
  307. -e "s!%%EMAIL%%!$EMAIL!g" \
  308. -e "s!%%PACKAGE%%!$PACKAGE!g" \
  309. -e "s!%%DATE%%!$curdate!g" \
  310. -e "s!%%HTML_MONO_SIZE%%!$html_mono_size!g" \
  311. -e "s!%%HTML_MONO_GZ_SIZE%%!$html_mono_gz_size!g" \
  312. -e "s!%%HTML_NODE_TGZ_SIZE%%!$html_node_tgz_size!g" \
  313. -e "s!%%HTML_SECTION_TGZ_SIZE%%!$html_section_tgz_size!g" \
  314. -e "s!%%HTML_CHAPTER_TGZ_SIZE%%!$html_chapter_tgz_size!g" \
  315. -e "s!%%INFO_TGZ_SIZE%%!$info_tgz_size!g" \
  316. -e "s!%%DVI_GZ_SIZE%%!$dvi_gz_size!g" \
  317. -e "s!%%PDF_SIZE%%!$pdf_size!g" \
  318. -e "s!%%PS_GZ_SIZE%%!$ps_gz_size!g" \
  319. -e "s!%%ASCII_SIZE%%!$ascii_size!g" \
  320. -e "s!%%ASCII_GZ_SIZE%%!$ascii_gz_size!g" \
  321. -e "s!%%TEXI_TGZ_SIZE%%!$texi_tgz_size!g" \
  322. -e "s!%%DOCBOOK_HTML_NODE_TGZ_SIZE%%!$html_node_db_tgz_size!g" \
  323. -e "s!%%DOCBOOK_ASCII_SIZE%%!$docbook_ascii_size!g" \
  324. -e "s!%%DOCBOOK_PS_GZ_SIZE%%!$docbook_ps_gz_size!g" \
  325. -e "s!%%DOCBOOK_PDF_SIZE%%!$docbook_pdf_size!g" \
  326. -e "s!%%DOCBOOK_XML_SIZE%%!$docbook_xml_size!g" \
  327. -e "s!%%DOCBOOK_XML_GZ_SIZE%%!$docbook_xml_gz_size!g" \
  328. -e "s,%%SCRIPTURL%%,$scripturl,g" \
  329. -e "s!%%SCRIPTNAME%%!$prog!g" \
  330. -e "$CONDS" \
  331. $GENDOCS_TEMPLATE_DIR/gendocs_template >"$outdir/index.html"
  332. echo "Done, see $outdir/ subdirectory for new files."
  333. # Local variables:
  334. # eval: (add-hook 'write-file-hooks 'time-stamp)
  335. # time-stamp-start: "scriptversion="
  336. # time-stamp-format: "%:y-%02m-%02d.%02H"
  337. # time-stamp-end: "$"
  338. # End: