gendocs.sh 12 KB

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